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...
Learn a little bit about the new Pastebin.com on our help page. hide message
By mhg on the 3rd of Feb 2010 04:16:31 PM Download | Raw | Embed | Report
  1. package TestMoose;
  2. use Moose;
  3.  
  4. sub track_master {
  5.     my ( $orig, $self, $value ) = @_;
  6.  
  7.     return $self->$orig( $value ) if $value;
  8.  
  9.     my $out = $self->$orig();
  10.     return $out->( $self ) if ref $out eq 'CODE';
  11.  
  12.     return $self->$orig();
  13. }
  14.  
  15.     has color  => (
  16.         is      => 'rw',
  17.         default => 'red',
  18.     );
  19.  
  20.     has line_color     => (
  21.         is          => 'rw',
  22.         lazy        => 1,
  23.         default     => sub { sub { $_[0]->color } },
  24.     );
  25.     around line_color   => \&track_master;
  26.  
  27.     has font_color  => (
  28.         is          => 'rw',
  29.         lazy        => 1,
  30.         default     => sub { sub { $_[0]->color } },
  31.     );
  32.     around font_color   => \&track_master;
  33.  
  34. package main;
  35.  
  36. my $t = TestMoose->new;
  37.  
  38. # Should be red red red
  39. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
  40.  
  41. $t->color( 'green' );
  42.  
  43. # Should be green green green
  44. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
  45.  
  46. $t->line_color( 'pink' );
  47.  
  48. # Should be green pink green
  49. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
  50.  
  51. $t->color( 'blue' );
  52.  
  53. # Should be blue pink blue
  54. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: