Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl 6 OOP

lichtkind
September 05, 2015

Perl 6 OOP

features and syntax of OO in Perl 6, whcih might be much more than you expect

lichtkind

September 05, 2015
Tweet

More Decks by lichtkind

Other Decks in Programming

Transcript

  1. Damian Says: Object-oriented programming ... many opinions, theories, and even

    ideologies have been formulated on the subject. ... Most are mutually inconsistent.
  2. O O P Classes / Prototypes (Multiple) Inheritance / Roles

    MMD + Delegation Types + Subtypes Introspection / Metaobj.
  3. In Perl 5 package Spaceship; use Moose; has 'speed' =>

    ( is => 'ro'; isa => 'Int'; ); sub stop { $self = shift; $self->speed = 0; }
  4. In Perl 5 package Spaceship; use Moo; has 'speed' =>

    ( is => 'ro'; isa => sub { die "…" unless looks_like_number($_[0]); }); sub stop { $self = shift; $self->speed = 0; }
  5. In Perl 5 use MooseX::Declare; class Spaceship { has 'speed'

    => ( is => 'ro'; isa => 'Int'; ); method stop { $self->speed = 0; } }
  6. trusts class Cat { method steal { my $carlo =

    Dog.new(); $carlo!Bone = 0; ...
  7. Twigils . punlic access. ! private access. ^ pos. auto

    para. : named auto p. * global var ? compiler info = POD ~ sublang
  8. In Perl 5 use MooseX::Declare; class Spaceship { has 'speed'

    => ( is => 'ro'; isa => 'Int'; ); method stop { $self->speed = 0; } }
  9. In Perl 5 use MooseX::Declare; class Spaceship { has 'speed'

    => ( is => 'rw'; isa => 'Int'; ); method stop { $self->speed = 0; } }
  10. Class class Spaceship { has Int $.speed is rw =

    0; method stop { $.speed = 0; } }
  11. In Perl 5 use MooseX::Declare; class Spaceship { has 'speed'

    => ( is => 'rw'; isa => 'Int'; default => 0; ); method stop { $self->speed = 0; } }
  12. Perl 6 Attribute no: isa default (just Syntax) predicate required

    coerce reader writer init_arg clearer builder lazy_build
  13. Methods WHAT short name WHICH object ID (type) WHO package,

    long name in str context WHERE memory address HOW object of meta class WHEN (reserved for events?) WHY (reserved for documentation) WHENCE autovivification of closures
  14. Methods WHAT short name WHICH object ID (type) WHO package,

    long name in str context WHERE memory address HOW object of meta class WHEN (reserved for events?) WHY (reserved for documentation) WHENCE autovivification of closures
  15. Methods WHAT short name WHICH object ID (type) WHO package,

    long name in str context WHERE memory address HOW object of meta class WHEN (reserved for events?) WHY (reserved for documentation) WHENCE autovivification of closures