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 "; } }
In reply to strict refs and package namespaces by rinceWind
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |