From: Dave Rolsky Date: Sun, 21 Jun 2009 15:05:45 +0000 (-0500) Subject: Add slides on BUILDARGS, BUILD, and DEMOLISH X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6c8786deaf97484afa544488d5e0340d131c274;p=gitmo%2Fmoose-presentations.git Add slides on BUILDARGS, BUILD, and DEMOLISH --- diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html index 4f2fcd3..cbbf3a1 100644 --- a/moose-class/slides/index.html +++ b/moose-class/slides/index.html @@ -866,6 +866,74 @@ use Moose;
+

BUILDARGS

+ + +
+ +
+

BUILDARGS Example

+ +
package Person;
+use Moose;
+
+sub BUILDARGS {
+    my $class = shift;
+
+    if ( @_ == 1 && ! ref $_[0] ) {
+        return { ssn => $_[0] };
+    }
+
+    return $class->SUPER::BUILDARGS(@_);
+}
+
+Person->new('123-45-6789')
+
+ +
+

BUILD

+ + +
+ +
+

BUILD Example

+ +
package Person;
+use Moose;
+
+sub BUILD {
+    my $self = shift;
+
+    if ( $self->country_of_residence
+         eq 'USA' ) {
+        die 'All US residents'
+            . ' must have an SSN'
+            unless $self->has_ssn;
+    }
+}
+
+ +
+

DEMOLISH

+ + +
+ +

extends