Dear monks,
I'm trying to understand how
attributes work. I still don't get it. Why does the following not work (and is it fixable)?
package Attr;
sub new :Constructor { return bless {}, shift }
sub set_blah :Mutator {
my ( $self, $blah ) = @_;
$self->{blah} = $blah;
return $self;
}
sub get_blah :Accessor {
my $self = shift;
return $self->{blah};
}
1;
package main;
my $obj = Attr->new;
$obj->set_blah('I just set something!');
print $obj->get_blah;
All I get is
Invalid CODE attribute: Constructor at /Users/rvosa/Desktop/Attr.pl line 3. So is it possible to set (arbitrary) attributes on methods, and how is that done?