Subdomain Posts
None | 22 days ago
Perl | 35 days ago
Perl | 35 days ago
None | 36 days ago
Perl | 41 days ago
Perl | 41 days ago
Perl | 41 days ago
None | 99 days ago
None | 243 days ago
None | 364 days ago
Recent Posts
None | 0 sec ago
None | 0 sec ago
None | 2 sec ago
None | 2 sec ago
Python | 3 sec ago
None | 7 sec ago
Java | 22 sec ago
None | 23 sec ago
PHP | 24 sec ago
None | 31 sec ago
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By mhg on the 3rd of Feb 2010 04:16:31 PM
Download |
Raw |
Embed |
Report
use Moose;
sub track_master {
my ( $orig, $self, $value ) = @_;
return $self->$orig( $value ) if $value;
my $out = $self->$orig();
return $out->( $self ) if ref $out eq 'CODE';
}
has color => (
is => 'rw',
default => 'red',
);
has line_color => (
is => 'rw',
lazy => 1,
default => sub { sub { $_[0]->color } },
);
around line_color => \&track_master;
has font_color => (
is => 'rw',
lazy => 1,
default => sub { sub { $_[0]->color } },
);
around font_color => \&track_master;
my $t = TestMoose->new;
# Should be red red red
print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
$t->color( 'green' );
# Should be green green green
print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
$t->line_color( 'pink' );
# Should be green pink green
print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
$t->color( 'blue' );
# Should be blue pink blue
print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post