|
Posted by boyd on August 25, 2006, 7:11 pm
Please log in for more thread options
> Ignoramus20689 wrote:
> > I recall that there is a perl module that simplifies creation of
> > packages with nice accessors. Like, I could use that module and do
> > just a few things so that my class would have great get and set
> > functions, etc, without doing much. I have no recollection of its
> > name, maybe something::Object or some such.
>
> There are quite a number of those on CPAN, did you try searching
> for them yet?
> http://search.cpan.org/search?query=Accessor&mode=all
> brings quite a list of modules that ease the creation of
> accessors.
>
> -Chris
One other module in this series, which I got from the Perl Advent
calendar, is
Class::Accessor::Chained
which I like a lot. It allows one to set the accessor values with one
reference to the object instead of multiple times:
For example:
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
$|++;
package Test;
use base q;
__PACKAGE__->mk_accessors( qw( x y str ) );
sub do_something {
my $self = shift;
print "The values of x and y are: ", $self->x, $self->y, "\n";
print "And the string is: \' " . $self->str . "\' \n";
}
package main_program;
my $obj = Test->new;
# Here is the chained feature:
$obj->x(123.4)
->y(-20.9)
->str("this is an example program")
->do_something;
Boyd
--
boyd
|