Re: Perl module that simplifies creation of packages?



In article <44eb1feb$0$10154$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Christian Winter <thepoet_nospam@xxxxxxxx> wrote:

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{Class::Accessor::Chained};
__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
.



Relevant Pages

  • Re: Slot accessors and syntax
    ... > I've heard it recommended that one use accessors preferably to slots, ... > globally visible functions in the package. ... The problem you describe is a namespace issue, ... This is not possible by making method syntax ...
    (comp.lang.lisp)
  • Re: Scope - do I need two identical classes, each with different scope?
    ... >Triangle attributes) and one is default package scope(and would be ... >returned from the calculation method)? ... the accessors in a package version then seal them off in a derived ... second derived version with accessors and a private constructor. ...
    (comp.lang.java.programmer)
  • Re: Looping through Class::Accessor accessors
    ... object and also get the name of the accessor as I loop through. ... # loop through the objects accessors ... my $class = shift; ... package You; ...
    (comp.lang.perl.misc)
  • Re: First draft of chapter 17 of Practical Common Lisp on web
    ... On Tue, 13 Jul 2004, Raistlin Magere wrote: ... > accessable outside the package can you just export the class name or do you ... > need to export all the accessors you want to make available? ... > Similarly when dealing with generic functions is there a way to export only ...
    (comp.lang.lisp)
  • RE: Duplicate name error after copying task/ VS_ISCORRUPT
    ... What you have to do is copy the assemblies that you want to reference ... Dim oApp As New Application, ... Dim oExec As Executable ... ' Get package path ...
    (microsoft.public.sqlserver.dts)