blahblah has asked for the wisdom of the Perl Monks concerning the following question:
Ack!package Help; use strict; use warnings; sub new { my ($class, %args) = @_; my $self = {}; bless $self, $class; # populate $self->{attributes} = [qw(foo boo)]; $self->$_($args{$_}) for @{$self->{attributes}}; return $self; } sub foo { my ($self, $value) = @_; if (defined $value) { $self->{foo} = $value; return 1; } else { return $self->{foo}; # shouldn't this autoviv? } } sub boo { my ($self, $value) = @_; if (defined $value) { $self->{boo} = $value; return 1; } else { return $self->{boo}; } } package main; use Data::Dumper; # no autoviv? what? my $obj_01 = Help->new(); print Dumper($obj_01); # we set values - that works my $obj_02 = Help->new(foo => '', boo => "value"); print Dumper($obj_02); # again, no autoviv (I expect it to be the same as 01 # but am still surprised there is no autoviv happening) my $obj_03 = Help->new(foo => undef, boo => undef); print Dumper($obj_03); 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why is this not autovivifying?
by Fletch (Bishop) on Apr 02, 2007 at 15:33 UTC | |
by blahblah (Friar) on Apr 02, 2007 at 15:47 UTC | |
by ikegami (Patriarch) on Apr 03, 2007 at 01:06 UTC | |
by Fletch (Bishop) on Apr 03, 2007 at 13:21 UTC | |
|
Re: Why is this not autovivifying?
by saintly (Scribe) on Apr 02, 2007 at 16:05 UTC |