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
Fri Nov 23 09:55:13 GMT 2007

----- Original Message ----
> From: Matt S Trout <dbix-class at>

> 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 

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


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.

Buy the book  -
Perl and CGI  -
Personal blog -
Tech blog     -

More information about the mailing list