Skip to content

Commit

Permalink
Merge pull request #1 from tadzik/master
Browse files Browse the repository at this point in the history
Implemented a stupid BUILD handling
  • Loading branch information
dams committed Sep 8, 2011
2 parents 91e0939 + 3a9dd9b commit 5f97f6b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Mo.pm
Expand Up @@ -12,6 +12,6 @@ sub import {
push @{$p.'::ISA'}, $_[0];
}

sub new { bless { @_[1..$#_] }, $_[0] }
sub new { $_ = bless { @_[1..$#_] }, $_[0]; $_->can('BUILD') && $_->BUILD; $_ }

1;
31 changes: 30 additions & 1 deletion t/test.t
@@ -1,4 +1,4 @@
use Test::More tests => 5;
use Test::More tests => 8;

package Foo;
use Mo;
Expand All @@ -11,6 +11,28 @@ extends 'Foo';

has 'that';

package Baz;
use Mo;

has 'foo';

sub BUILD {
my $self = shift;
$self->foo(5);
}

package Maz;
use Mo;
extends 'Baz';

has 'bar';

sub BUILD {
my $self = shift;
$self->SUPER::BUILD();
$self->bar(7);
}

package main;

my $bar = Bar->new(
Expand All @@ -28,3 +50,10 @@ is $bar->that, 'thong', 'Read works in parent class';
$bar->this('thang');

is $bar->this, 'thang', 'Write works';

my $baz = Baz->new;
is $baz->foo, 5, 'BUILD works';

my $maz = Maz->new;
is $maz->foo, 5, 'BUILD works again';
is $maz->bar, 7, 'BUILD works in parent class';

0 comments on commit 5f97f6b

Please sign in to comment.