Created
January 27, 2009 04:08
-
-
Save yappo/53172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More tests => 4; | |
do { | |
package Class1; | |
use Mouse; | |
has l => ( | |
is => 'ro', | |
default => 'A', | |
); | |
has s => ( | |
is => 'ro', | |
default => sub { ($_[0]->l || '') . ':B' }, | |
); | |
package Class2; | |
use Mouse; | |
has s => ( | |
is => 'ro', | |
default => 'B', | |
); | |
has l => ( | |
is => 'ro', | |
default => sub { 'A:' . ($_[0]->s || '') }, | |
); | |
}; | |
my $obj1 = Class1->new; | |
is $obj1->s, ':B'; | |
my $obj2 = Class2->new; | |
is $obj2->l, 'A:B'; | |
do { | |
package Class3; | |
use Moose; | |
has l => ( | |
is => 'ro', | |
default => 'A', | |
); | |
has s => ( | |
is => 'ro', | |
default => sub { ($_[0]->l || '') . ':B' }, | |
); | |
package Class4; | |
use Moose; | |
has s => ( | |
is => 'ro', | |
default => 'B', | |
); | |
has l => ( | |
is => 'ro', | |
default => sub { 'A:' . ($_[0]->s || '') }, | |
); | |
}; | |
my $obj3 = Class3->new; | |
is $obj3->s, ':B'; | |
my $obj4 = Class4->new; | |
is $obj4->l, 'A:B'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment