Share Pastebin
Guest
Public paste!

mhg

By: a guest | Jan 28th, 2010 | Syntax: Perl | Size: 0.78 KB | Hits: 122 | Expires: Never
Copy text to clipboard
  1. #==================== code ===============================
  2.  
  3. use MooseX::Declare;
  4.  
  5. class TestMoose {
  6.     has p1  => (
  7.         is      => 'rw',
  8.         default => '111',
  9.     );
  10.     has p3  => (
  11.         is          => 'rw',
  12.         lazy        => 1,
  13.         default     => sub { '333' . $_[0]->p2 },
  14.     );
  15.     has p2  => (
  16.         is          => 'rw',
  17.         lazy        => 1,
  18.         default     => sub { '222' . $_[0]->p1 },
  19.     );
  20. }
  21.  
  22. my $t = TestMoose->new;
  23.  
  24. print join ' ', $t->p1, $t->p2, $t->p3, "\n";
  25.  
  26. $t->p2( 'xxx' );
  27.  
  28. print join ' ', $t->p1, $t->p2, $t->p3, "\n";
  29.  
  30.  
  31. #============================== result ===========================
  32.  
  33. $ perl testMoose.pl
  34. 111 222111 333222111
  35. 111 xxx 333222111
  36.  
  37. # but what i want is:
  38.  
  39. 111 222111 333222111
  40. 111 xxx 333xxx