--- David Cantrell <[EMAIL PROTECTED]> wrote: > > >>I wonder how you'd tag a subroutine that can be called as a > method or > > >>a regular subroutine. > > >:horrible_evil_delete_this_entire_file_to_be_safe > > /me makes notes. > > I'm with chromatic on this one. Doing that will make your brain > hurt. > Especially if you do it to subroutines/methods that you create on the > fly with AUTOLOAD. I wish I'd never dunnit.
Yeah, digging through the CGI.pm code base was *real* fun because of this. Since all functions are, under the hood, methods, then the beginning of many functions looks like this: sub param { my($self,@p) = self_or_default(@_); ... And what does &self_or_default look like? sub self_or_default { return @_ if defined($_[0]) && (!ref($_[0])) &&($_[0] eq 'CGI'); unless (defined($_[0]) && (ref($_[0]) eq 'CGI' || UNIVERSAL::isa($_[0],'CGI')) # slightly optimized for common case ) { $Q = $CGI::DefaultClass->new unless defined($Q); unshift(@_,$Q); } return wantarray ? @_ : $Q; } Lincoln Stein admits that he wouldn't write it this way any more, but there are plenty of programmers who wouldn't see anything wrong with this :( Just for fun, how many potential bugs can you count in the self_or_default subroutine? Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/