+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
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';
use Moose::Role;
-our $VERSION = '0.00100';
+our $VERSION = '0.00200';
=head1 NAME
=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.
#!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");
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');