in reply to Importing CGI methods into a subclass as a class method
If the methods really were being imported into the namespace, they would be automatically usable as methods on your objects, as they are not bound by the lexical scope of your function call. However, I doubt it would work right, as the method calls would eventually translate to CGI::param($obj, 'foo') instead what you probably want: CGI::param($obj->{query}, 'foo'), (i.e., $obj->{query}->param('foo')).use CGI; my $q = new CGI qw(param); print "\$q->param($_) = " . $q->param($_) . "\n" for $q->param; print param('asdf'); # not imported, error __END__ prints: $ perl test.pl $q->param(keywords) = param Undefined subroutine &main::param called at - line 4.
I don't see the problem with using AUTOLOAD to dispatch to the CGI object, even if you want to use it with more than just the param method:
sub AUTOLOAD { my $func = $AUTOLOAD; $func =~ s/^.*:://; $self->{query}->$func(@_); }
blokhead
|
|---|