Skip to content

Commit

Permalink
handle uninitialized attributes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Mar 11, 2012
1 parent 2c758b6 commit 8c94d8f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mop/class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ sub new {
if ( my $attrs = $class->get_all_attributes ) {
foreach my $attr ( keys %$attrs ) {
my ($plain_attr) = ($attr =~ /^\$(.*)/);
$instance->{ $attr } = \(exists $args{ $plain_attr } ? $args{ $plain_attr } : $attrs->{ $attr }->());
if ( exists $args{ $plain_attr } ) {
$instance->{ $attr } = \($args{ $plain_attr });
}
else {
$instance->{ $attr } = \(ref $attrs->{ $attr } ? $attrs->{ $attr }->() : $attrs->{ $attr });
}
}
}
$class->bless( $instance );
Expand Down

0 comments on commit 8c94d8f

Please sign in to comment.