rvosa has asked for the wisdom of the Perl Monks concerning the following question:
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)?
I'm trying to understand how attributes work. I still don't get it. Why does the following not work (and is it fixable)?
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?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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to use attributes?
by blokhead (Monsignor) on Mar 22, 2007 at 18:48 UTC | |
by rvosa (Curate) on Mar 22, 2007 at 19:05 UTC | |
Re: how to use attributes?
by Limbic~Region (Chancellor) on Mar 22, 2007 at 23:29 UTC | |
Re: how to use attributes?
by Anno (Deacon) on Mar 22, 2007 at 18:57 UTC | |
Re: how to use attributes?
by Moron (Curate) on Mar 22, 2007 at 18:41 UTC | |
Re: how to use attributes?
by varian (Chaplain) on Mar 22, 2007 at 18:34 UTC | |
by rvosa (Curate) on Mar 22, 2007 at 19:01 UTC | |
Re: how to use attributes?
by xdg (Monsignor) on Mar 23, 2007 at 13:47 UTC | |
Re: how to use attributes?
by Zaxo (Archbishop) on Mar 23, 2007 at 21:53 UTC |
Back to
Seekers of Perl Wisdom