billy,
AUTOLOAD looks to be the perfect solution.
let's say your object has these slots:
{rect => 'whatever',
circle => undef,
name => 'whatever'};
let's say you want an accessor method to return the value of a particular
slot by saying 'get_rect', 'get_circle', or 'get_name', and you don't want
to define all these accessor methods. you can do this:
use vars '$AUTOLOAD'; # needed if you do 'use strict'
sub AUTOLOAD {
my ($self) = @_;
$AUTOLOAD =~ /get_(\w+)/ or die "no such method: $AUTOLOAD";
exists $self->{$1} or die "no such attribute: $1";
return $self->{$1};
}
-=-=-=-
then in your code a call to the function:
get_rect()
will return 'whatever' (value of the slot in your object hash)
regards,
john
Billy Patton wrote:
>
> I have an OO module that has some 100+ slots in the hash.
> most are all for holding command line input. Any command
> line switch get entered into the hash without the -
> ex: command_line -abc -def
> is abc and def in the hash.
>
> Keeping with good OO methodology I need a method to access each element
> without building a method for each.
> EX:
> sub abc {
> my ($c,$set) = @_;
> my $name = (caller(0))[3];
> $c->{$name} = $set if defined $set;
> return $c->{$name};
> }
>
> in an XS file I have :
> OnlyArb(np,stop=0)
> Laff::Node np
> Laff::Node stop
> ALIAS:
> OnlyArb = lARB
> OnlyAttr = lATTR
> OnlyCircle = lCIRCLE
> OnlyClf = lCLF
> OnlyConnect = lCONNECT
> OnlyCpd = lCPD
> OnlyCpr = lCPR
> OnlyDtext = lDTEXT
> OnlyName = lNAME
> OnlyPath = lPATH
> OnlyPort = lPORT
> OnlyPrel = lPREL
> OnlyRect = lRECT
> OnlySnam = lSNAM
> OnlySxcall = lSXCALL
> OnlyText = lTEXT
> OnlyXcall = lXCALL
> CODE:
> {
> do
> {
> np = (stop) ? LaffNodeNext(np,stop)
> : LaffNodeNext(np,NULL);
> } while (np && np->type != ix);
> RETVAL = np;
> }
> OUTPUT:
> RETVAL
>
> This gives me one routine that I can access all data. ix is the l*
>
> How can I do this in my OO package?
>
> I've looked out on CPAN and searched for Alias. There is an alias
> module
> but they deal with data, not subroutines.
>
> So how do I duplicate teh ALIAS and ix in perl for what has been done
> in XS?
>
> --
> =========+=========+=========+=========+=========+=========+=========+
> ___ _ ____ ___ __ __
> / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
> / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
> /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
> /___/
> Texas Instruments ASIC Circuit Design Methology Group
> Dallas, Texas
> 214-480-4455
> [EMAIL PROTECTED]
> =========+=========+=========+=========+=========+=========+=========+