Calling UNIVERSAL::can() as a function is allowed. (was: [OT] best way to determine existence of a function in a package)
Ovid
publiustemp-londonpm at yahoo.com
Fri Nov 23 09:55:13 GMT 2007
----- Original Message ----
> From: Matt S Trout <dbix-class at trout.me.uk>
> I also massively dislike having UNIVERSAL::can and ::isa in
> my dependency chain; they have a tendency to scare people
> off for some reason and
since I get exactly zero value out of
> having them around I'd rather just not
bother.
Agreed. Extending the behavior of UNIVERSAL:: is dodgy enough. Altering the behavior is just wrong. The *correct* way to handle something like this, if you truly want to globally alter behavior:
package My::UNIVERSAL;
# do whatever you want
1;
Then have your classes explicitly inherit from My::UNIVERSAL rather than implicitly inherit from UNIVERSAL. For a touch of extra work, you get the safety you want and you don't break other people's code. I did this on one project to to make "->can" return false for "private" methods unless you were a subclass or a trusted class. Altering "->can" proved to be more trouble than it was worth, but at least while I made a mess for me, I didn't make a mess for anyone else.
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/
More information about the london.pm
mailing list