Guest
Public paste!

mhg

By: a guest | Jan 28th, 2010 | Syntax: Perl | Size: 0.88 KB | Hits: 145 | Expires: Never
Copy text to clipboard
  1. package TestMoose;
  2. use Moose;
  3.     has color  => (
  4.         is      => 'rw',
  5.         default => 'red',
  6.     );
  7.     has line_color     => (
  8.         is          => 'rw',
  9.         lazy        => 1,
  10.         default     => sub { $_[0]->color },
  11.     );
  12.     has font_color  => (
  13.         is          => 'rw',
  14.         lazy        => 1,
  15.         default     => sub { $_[0]->color },
  16.     );
  17.  
  18. package main;
  19.  
  20. my $t = TestMoose->new;
  21.  
  22. # Should be red red red
  23. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
  24.  
  25. $t->color( 'green' );
  26.  
  27. # Should be green green green
  28. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
  29.  
  30. $t->line_color( 'pink' );
  31.  
  32. # Should be green pink green
  33. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";
  34.  
  35. $t->color( 'blue' );
  36.  
  37. # Should be blue pink blue
  38. print join ' ', $t->color, $t->line_color, $t->font_color, "\n";