rinceWind has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
Is there a way of avoiding the use of no strict 'refs' in the following code fragment. I know symbolic references are ugly, but the alternatives are probably worse. Is this one of those cases where no strict 'refs' is best?
sub AUTOLOAD { use vars qw($AUTOLOAD); my ($pkg,$method) = ($AUTOLOAD =~ /(.*)::(\w+)$/); my ($self,@args) = @_; my $pkgTmplt; my $pkgv = $pkg.'::_template'; { no strict 'refs'; $pkgTmplt = $$pkgv{$method}; } if ($pkgTmplt) { my $acc = $self->accessor($method,$pkgTmplt); my $chunk = <<END package $pkg; sub $method { $acc } END ; eval $chunk; die "Error making accessor: $@\nCode follows:\n$chunk" if $@; wantarray ? ($self->$method(@args)) : $self->$method(@args); } else { croak "Unknown sub $method in $pkg "; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: strict refs and package namespaces
by merlyn (Sage) on Feb 19, 2002 at 13:30 UTC | |
|
Re: strict refs and package namespaces
by broquaint (Abbot) on Feb 19, 2002 at 11:37 UTC |