tests/accessor
raw| 1 | package cm3; |
| 2 | sub new { bless $_[1], $_[0] } |
| 3 | |
| 4 | use lib "tests"; |
| 5 | |
| 6 | # comment/uncomment one or the other: |
| 7 | use Accessor_maker; |
| 8 | # sub foo { $_[0]->{ 'foo' } } |
| 9 | |
| 10 | package main; |
| 11 | |
| 12 | sub test { |
| 13 | my $self = shift; |
| 14 | |
| 15 | print 'un' unless defined $self->foo; |
| 16 | print "defined\n"; |
| 17 | |
| 18 | my $foo = $self->foo; |
| 19 | print 'un' unless defined $foo; |
| 20 | print "defined\n"; |
| 21 | } |
| 22 | |
| 23 | test( cm3->new({}) ); |
| 24 | test( cm3->new({foo => 1}) ); |