--- "Mumia W." <[EMAIL PROTECTED]>
wrote:
> On 09/22/2006 07:50 AM, chen li wrote:
> >
> > --- "Mumia W."
> <[EMAIL PROTECTED]>
> > wrote:
> >> That "redundancy" allows you to use inheritance.
> If
> >> you have a class
> >> Employee, with an expanded set of fields, this
> >> method makes it possible
> >> to add the fields without having to modify each
> >> method that uses them.
> >>
> >
> > Where can I find more about this kind of syntax?
> > [...]
>
> Read the "Class Data" section in perltoot.
>
Hi Mumia,
I don't think I get the point. If my purpose of using
AUTOLOAD is to handle 1) many attributes in construct
2) create an un-predined method on the fly, what will
happen if I make the following changes:
in sub new change
my $self = {_permitted => \%fields,%fields,};
to my $self =\%fields;
in sub AUTOLOAD comment out the unless statement.
Do you think these change will affect inheritance?
Thanks in advacne,
Li
########### copy from perltoot
package Person;
use Carp;
our $AUTOLOAD; # it's a package global
my %fields = (
name => undef,
age => undef,
peers => undef,
);
sub new {
my $class = shift;
my $self = {
_permitted => \%fields,
%fields,
};
bless $self, $class;
return $self;
}
sub AUTOLOAD {
my $self = shift;
my $type = ref($self)
or croak "$self is not an
object";
my $name = $AUTOLOAD;
$name =~ s/.*://; # strip
fully-qualified portion
unless (exists
$self->{_permitted}->{$name} ) {
croak "Can't access `$name' field in
class $type";
}
if (@_) {
return $self->{$name} = shift;
} else {
return $self->{$name};
}
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>