0.002 added the constructor functionality and removed auto_install
[gitmo/MooseX-Emulate-Class-Accessor-Fast.git] / lib / MooseX / Emulate / Class / Accessor / Fast.pm
index 154aabf..c75cf30 100644 (file)
@@ -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<Class::MOP::Attribute>. 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.