in reply to Re: coding a subroutine as both method and regular function
in thread coding a subroutine as both method and regular function
In CGI.pm, that is a little bit wild. A lot of these sub call self_or_default()..
Uhm.. I was gonna dissect how self_or_default() works.. but... ouch. It hurts. CGI.pm v 3.15 line 442:
sub self_or_default { return @_ if defined($_[0]) && (!ref($_[0])) &&($_[0] eq 'CGI'); unless (defined($_[0]) && (ref($_[0]) eq 'CGI' || UNIVERSAL::isa($_[0],'CGI')) # slightl +y optimized for common case ) { $Q = $CGI::DefaultClass->new unless defined($Q); unshift(@_,$Q); } return wantarray ? @_ : $Q; }
I mean, I get it.. it sees if the first list element is a ref or not, if it is a ref to 'CGI', it returns the list unchanged. If it is not.. then.. uhm... hmm.
|
|---|