in reply to Whats wrong with symbol refs here?
Personally I don't think there is anything wrong with this under controlled circumstances - I have plenty of code that does the same thing within an AUTOLOAD to create the autoloaded subroutines in the symbol table and of course it has to use "no strict 'refs'"
An alternative might be to create coderefs for the subroutines within the object itself (or if an object has not been created at that point in a package variable) and then use AUTOLOAD to run that code.
This might look look something like:
$self->{$method} = sub { my $self = shift; # etc }; ... sub AUTOLOAD { my ( $self, @args ) = @_; (my $method = $AUTOLOAD) =~ s/.*:://; if ( exists $self->{$method} ) { return $self->{$method}->(@args); } else { die "Not a method"; }
Of course this doesn't actually ever create the method in the symbol table so that UNIVERSAL::can won't work and inheritance won't work as expected :( - If you really need those things then don't worry about using no strict 'refs' it is really only an indication to perl that you recognize you are doing something a little out of the ordinaru but you promise not to do it all over the program :)
/J\
|
|---|