J
J Krugman
I've just come across this sort of code (from the CPAN module
SOAP::Lite):
sub BEGIN {
no strict 'refs';
for my $method (qw(ids hrefs parts parser base xmlschemas xmlschema)) {
my $field = '_' . $method;
*$method = sub {
my $self = shift->new;
@_ ? ($self->{$field} = shift, return $self) : return $self->{$field};
}
}
}
(SOAP::Lite comprises many packages; practically every one of them
has a BEGIN block in which methods are defined using this technique.)
This seems to me like an alternative to AUTOLOAD for defining
generic accessor methods. Any ideas about why this technique would
be preferable to using AUTOLOAD?
Thanks!
jill
SOAP::Lite):
sub BEGIN {
no strict 'refs';
for my $method (qw(ids hrefs parts parser base xmlschemas xmlschema)) {
my $field = '_' . $method;
*$method = sub {
my $self = shift->new;
@_ ? ($self->{$field} = shift, return $self) : return $self->{$field};
}
}
}
(SOAP::Lite comprises many packages; practically every one of them
has a BEGIN block in which methods are defined using this technique.)
This seems to me like an alternative to AUTOLOAD for defining
generic accessor methods. Any ideas about why this technique would
be preferable to using AUTOLOAD?
Thanks!
jill