From: Dave Rolsky Date: Mon, 6 Jun 2011 05:54:08 +0000 (-0500) Subject: fix attr ->default method to work like it does for regular attributes. only call... X-Git-Tag: v0.26~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e5fa95baab2413d6eea127014ba8fa291ce3ab3e;p=gitmo%2FMooseX-ClassAttribute.git fix attr ->default method to work like it does for regular attributes. only call the default subref if we receive a parameter. --- diff --git a/lib/MooseX/ClassAttribute/Trait/Attribute.pm b/lib/MooseX/ClassAttribute/Trait/Attribute.pm index 1432331..5519c54 100644 --- a/lib/MooseX/ClassAttribute/Trait/Attribute.pm +++ b/lib/MooseX/ClassAttribute/Trait/Attribute.pm @@ -42,7 +42,8 @@ sub _initialize { my $metaclass = shift; if ( $self->has_default() ) { - $self->set_value( undef, $self->default() ); + $self->set_value( undef, + $self->default( $self->associated_class() ) ); } elsif ( $self->has_builder() ) { $self->set_value( undef, $self->_call_builder( $metaclass->name() ) ); @@ -55,8 +56,8 @@ around default => sub { my $default = $self->$orig(); - if ( $self->is_default_a_coderef() ) { - return $default->( $self->associated_class() ); + if ( $self->is_default_a_coderef() && @_ ) { + return $default->(@_); } return $default;