X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=moose-class%2Fslides%2Findex.html;h=6c0e0b0cdf7d566016517118d200fe90af3307e5;hb=f28e0a12c2f3f8d2380386202bd2d35fee215086;hp=ea20e486eae08452ebe2f580efbbcf9b052caf49;hpb=bd857054d0772af174d9ca4c76ac138dde5eb976;p=gitmo%2Fmoose-presentations.git diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html index ea20e48..6c0e0b0 100644 --- a/moose-class/slides/index.html +++ b/moose-class/slides/index.html @@ -40,7 +40,7 @@ img#me05 {top: 43px;left: 36px;} @@ -208,7 +219,7 @@ use Moose; @@ -235,7 +246,10 @@ after 'foo' my @return = $self->$real_foo( @_, bar => 42 ); - return ( @return, 'modify return values' ); + return ( + @return, + 'modify return values' + ); }; @@ -262,7 +276,7 @@ has weight => ( ); # kaboom -Person->new( weight => 'fat' ); +Person->new( weight => 'heavy' );
@@ -284,11 +298,11 @@ use Moose; has blog_uri => ( is => 'rw', isa => 'URI', - handles => { 'blog_hostname' => 'host' }, + handles => { 'blog_host' => 'host' }, ); -$person->blog_hostname; -# really calls $person->blog_uri->host +$person->blog_host; +# really calls $person->blog_uri->host
@@ -829,6 +843,16 @@ has last_name => ( );
+
+

More Why Moose?

+ + +
+

Part 1: Moose Classes

@@ -869,8 +893,8 @@ use Moose;

BUILDARGS

@@ -885,10 +909,9 @@ use Moose; sub BUILDARGS { my $class = shift; - if ( @_ == 1 && ! ref $_[0] ) { + if ( @_ == 1 && ! ref $_[0] ) { return { ssn => $_[0] }; } - return $class->SUPER::BUILDARGS(@_); } @@ -925,11 +948,37 @@ sub BUILD {
+

Object Construction a la Moose

+ +
Person->new(@_)
+ +
    +
  1. Calls Person->BUILDARGS(@_) to turn @_ into a hashref
  2. +
  3. Blesses a reference
  4. +
  5. Populates attributes based on the hashref from #1
  6. +
  7. Calls $new_object->BUILDALL($constructor_args) +
    ... which calls all BUILD methods
  8. +
  9. Returns the object
  10. +
+
+ +
+

The Object is Opaque

+ + +
+ +

DEMOLISH

@@ -938,6 +987,8 @@ sub BUILD {
package Employee;
@@ -991,6 +1042,7 @@ extends 'LWP';
@@ -1002,12 +1054,13 @@ use Moose; extends 'Person'; -override work => sub { +override work => sub { my $self = shift; - die "Pay me first" unless $self->got_paid; - super(); -}; + die "Pay me first" + unless $self->got_paid; + super(); +};
@@ -1016,7 +1069,8 @@ use Moose;
@@ -1057,8 +1111,7 @@ has first_name => ( is => 'ro' ); my $person = Person->new( first_name => 'Dave' ); -$person->first_name('Stevan'); -print $person->first_name; # Dave +$person->first_name('Stevan'); # dies @@ -1077,7 +1130,7 @@ print $person->first_name; # Dave use Moose; # true -Person->can('extends'); +Person->can('extends');