From: Robert Buels Date: Thu, 9 Jul 2009 19:01:19 +0000 (-0700) Subject: carried BUILDARGS in Person.pm from exercise 1 forward through the later answer class... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d405ed6c12b930e5ed2e31fb438e23603376464;p=gitmo%2Fmoose-presentations.git carried BUILDARGS in Person.pm from exercise 1 forward through the later answer classes. t/02*.t was failing when run with answers/02*/* objects --- diff --git a/moose-class/exercises/answers/02-roles/Person.pm b/moose-class/exercises/answers/02-roles/Person.pm index e3b718a..ca3104a 100644 --- a/moose-class/exercises/answers/02-roles/Person.pm +++ b/moose-class/exercises/answers/02-roles/Person.pm @@ -7,6 +7,20 @@ with 'Printable', 'HasAccount'; has first_name => ( is => 'rw' ); has last_name => ( is => 'rw' ); +sub BUILDARGS { + my $class = shift; + + if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) { + return { + first_name => $_[0]->[0], + last_name => $_[0]->[1], + }; + } + else { + return $class->SUPER::BUILDARGS(@_); + } +} + sub full_name { my $self = shift; diff --git a/moose-class/exercises/answers/03-basic-attributes/Person.pm b/moose-class/exercises/answers/03-basic-attributes/Person.pm index db69019..3a42949 100644 --- a/moose-class/exercises/answers/03-basic-attributes/Person.pm +++ b/moose-class/exercises/answers/03-basic-attributes/Person.pm @@ -14,6 +14,20 @@ has first_name => ( is => 'rw' ); has last_name => ( is => 'rw' ); +sub BUILDARGS { + my $class = shift; + + if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) { + return { + first_name => $_[0]->[0], + last_name => $_[0]->[1], + }; + } + else { + return $class->SUPER::BUILDARGS(@_); + } +} + sub full_name { my $self = shift; diff --git a/moose-class/exercises/answers/05-types/Person.pm b/moose-class/exercises/answers/05-types/Person.pm index c402db3..b906206 100644 --- a/moose-class/exercises/answers/05-types/Person.pm +++ b/moose-class/exercises/answers/05-types/Person.pm @@ -21,6 +21,20 @@ has last_name => ( isa => 'Str', ); +sub BUILDARGS { + my $class = shift; + + if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) { + return { + first_name => $_[0]->[0], + last_name => $_[0]->[1], + }; + } + else { + return $class->SUPER::BUILDARGS(@_); + } +} + sub full_name { my $self = shift; diff --git a/moose-class/exercises/answers/06-advanced-attributes/Person.pm b/moose-class/exercises/answers/06-advanced-attributes/Person.pm index f9bb240..dd2914a 100644 --- a/moose-class/exercises/answers/06-advanced-attributes/Person.pm +++ b/moose-class/exercises/answers/06-advanced-attributes/Person.pm @@ -28,6 +28,20 @@ sub BUILD { $self->account->owner($self); } +sub BUILDARGS { + my $class = shift; + + if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) { + return { + first_name => $_[0]->[0], + last_name => $_[0]->[1], + }; + } + else { + return $class->SUPER::BUILDARGS(@_); + } +} + sub full_name { my $self = shift;