From: Guillermo Roditi Date: Fri, 28 Mar 2008 18:27:23 +0000 (+0000) Subject: 0.002 added the constructor functionality and removed auto_install X-Git-Tag: 0.00200^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b8ba79f1c7975eccdcc17212646d85b8f842dc2;p=gitmo%2FMooseX-Emulate-Class-Accessor-Fast.git 0.002 added the constructor functionality and removed auto_install --- diff --git a/Changes b/Changes index 220a896..090ebc6 100644 --- a/Changes +++ b/Changes @@ -1,2 +1,6 @@ +0.00200 Mar 28, 2008 + - Extend BUILDALL to store constructor keys in the obj. hashref + - Minor fix to make sure Adopt doesn't trip PAUSE perms + - Bye bye auto_install. 0.00100 Mar 15, 2008 - Initial Release! \ No newline at end of file diff --git a/MANIFEST b/MANIFEST index 5019cd6..83ea6b1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,3 +1,4 @@ +Changes inc/Module/AutoInstall.pm inc/Module/Install.pm inc/Module/Install/AutoInstall.pm diff --git a/Makefile.PL b/Makefile.PL index d6132c9..c37a1f3 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,5 +13,4 @@ requires 'Moose'; build_requires 'Test::More' => 0; -auto_install; WriteAll; diff --git a/lib/MooseX/Adopt/Class/Accessor/Fast.pm b/lib/MooseX/Adopt/Class/Accessor/Fast.pm index ed95486..066f424 100644 --- a/lib/MooseX/Adopt/Class/Accessor/Fast.pm +++ b/lib/MooseX/Adopt/Class/Accessor/Fast.pm @@ -1,10 +1,11 @@ package MooseX::Adopt::Class::Accessor::Fast; -our $VERSION = '0.00100'; +our $VERSION = '0.00200'; $INC{'Class/Accessor/Fast.pm'} = __FILE__; -package Class::Accessor::Fast; +package #don't index + Class::Accessor::Fast; use Moose; with 'MooseX::Emulate::Class::Accessor::Fast'; diff --git a/lib/MooseX/Emulate/Class/Accessor/Fast.pm b/lib/MooseX/Emulate/Class/Accessor/Fast.pm index 154aabf..c75cf30 100644 --- a/lib/MooseX/Emulate/Class/Accessor/Fast.pm +++ b/lib/MooseX/Emulate/Class/Accessor/Fast.pm @@ -2,7 +2,7 @@ package MooseX::Emulate::Class::Accessor::Fast; use Moose::Role; -our $VERSION = '0.00100'; +our $VERSION = '0.00200'; =head1 NAME @@ -60,6 +60,28 @@ methods in L. Example =head1 METHODS +=head2 new %args + +Extend the default Moose constructor to emulate the behavior of C::A::F and +store arguments in the instance hashref. + +=cut + +around new => sub{ + my $orig = shift; + my $class = shift; + my %args; + if (scalar @_ == 1 && defined $_[0] && ref($_[0]) eq 'HASH') { + %args = %{$_[0]}; + } else { + %args = @_; + } + my $self = $class->$orig(@_); + my @extra = grep { !exists($self->{$_}) } keys %args; + @{$self}{@extra} = @args{@extra}; + return $self; +}; + =head2 mk_accessors @field_names Create read-write accessors. An attribute named C<$field_name> will be created. diff --git a/t/adopt.t b/t/adopt.t index 6cd2831..c7900a9 100644 --- a/t/adopt.t +++ b/t/adopt.t @@ -1,7 +1,7 @@ #!perl use strict; use lib 't/lib'; -use Test::More tests => 6; +use Test::More tests => 12; #1,2 require_ok("MooseX::Adopt::Class::Accessor::Fast"); @@ -11,3 +11,15 @@ use_ok('TestAdoptCAF'); ok(TestAdoptCAF->can('meta'), 'Adopt seems to work'); ok(TestAdoptCAF->meta->find_attribute_by_name($_), "attribute $_ created") for qw(foo bar baz); + +#7-9 +my $t = TestAdoptCAF->new(foo => 100, bar => 200, groditi => 300); +is($t->{foo}, 100, '$self->{foo} set'); +is($t->{bar}, 200, '$self->{bar} set'); +is($t->{groditi}, 300, '$self->{groditi} set'); + +#10-12 +my $u = TestAdoptCAF->new({foo => 100, bar => 200, groditi => 300}); +is($t->{foo}, 100, '$self->{foo} set'); +is($t->{bar}, 200, '$self->{bar} set'); +is($t->{groditi}, 300, '$self->{groditi} set');