From: Tomas Doran (t0m Date: Thu, 28 May 2009 16:36:51 +0000 (+0100) Subject: Fix such that BUILD method is advised with a modifier, rather than being present... X-Git-Tag: 0.00900~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Emulate-Class-Accessor-Fast.git;a=commitdiff_plain;h=db88e89a4b39274199eadc81789b199b07af339e Fix such that BUILD method is advised with a modifier, rather than being present in the role. This fixes issues with client classes having their own BUILD method (as in that case, our BUILD method is ignored) --- diff --git a/lib/MooseX/Emulate/Class/Accessor/Fast.pm b/lib/MooseX/Emulate/Class/Accessor/Fast.pm index 450c409..6700a6b 100644 --- a/lib/MooseX/Emulate/Class/Accessor/Fast.pm +++ b/lib/MooseX/Emulate/Class/Accessor/Fast.pm @@ -77,17 +77,18 @@ my $locate_metaclass = sub { }; sub BUILD { + shift; +} + +around 'BUILD' => sub { + my $orig = shift; my $self = shift; - my %args; - if (scalar @_ == 1 && defined $_[0] && ref($_[0]) eq 'HASH') { - %args = %{$_[0]}; - } elsif( scalar(@_) ) { - %args = @_; - } + my %args = %{ $_[0] }; + $self = $self->$orig(\%args); my @extra = grep { !exists($self->{$_}) } keys %args; @{$self}{@extra} = @args{@extra}; return $self; -} +}; =head2 mk_accessors @field_names