I simply hate how CGI::Application's accessor for the CGI
object is called query
.
I would like my instance classes to be able to use an accessor named cgi
to get the CGI
object associated with the current instance of my CGI::Application
subclass.
Here is a self-contained example of what I am doing:
package My::Hello;
sub hello {
my $self =shift;
print "Hello @_\n";
}
package My::Merhaba;
use base 'My::Hello';
sub merhaba {
goto sub { shift->hello(@_) };
}
package main;
My::Merhaba->merhaba('StackOverflow');
This is working as I think it should and I cannot see any problems (say, if I wanted to inherit from My::Merhaba
: Subclasses need not know anything about merhaba
).
Would it have been better/more correct to write
sub merhaba {
my $self = shift;
return $self->hello(@_);
}
What are the advantages/disadvantages of using goto &NAME
for the purpose of aliasing a method name? Is there a better way?
Note: If you have an urge to respond with goto
is evil don't do it because this use of Perl's goto
is different than what you have in mind.