Share Pastebin
Guest
Public paste!

mhg

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