# Assume I have foo, bar, and baz as my attributes my $x = $self->foo; # This retrieves the value in foo $self->foo(123); # This sets foo to 123 (and returns $self, to all +ow for: $self->foo(123) # chaining of mutator calls ->bar(456);
Now, I have used generic set/get routines. We had a set() and a get(), that took attribute names. So, you would have:
my %values; @values{qw(foo bar baz)} = $self->get(qw(foo bar baz)); $self->set( foo => 123, bar => 456, );
Except, there are a few issues. How do you handle misnamed attributes? What about attributes whose values are arrayrefs? It gets messy. And, it's even worse if you have a single method for doing all accessor/mutator functionality. Personally, I'd recommend against this. Maintainability will suffer.
------
We are the carpenters and bricklayers of the Information Age.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In reply to Re: OO Getters/Setters
by dragonchild
in thread OO Getters/Setters
by theAcolyte
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |