[Templates] Called UNIVERSAL::can() as a function, not a method at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/Template/Provider.pm

Andy Wardley abw@wardley.org
Sat, 09 Jun 2007 09:41:40 +0100

Kake L Pugh wrote:
> We're also seeing this warning when running the OpenGuides tests
> (Template Toolkit 2.19).  Is there anything that can be done about it?

Perrin's answered this elsewhere:


   "This is because you have installed chromatic's UNIVERSAL::can module.
    Maybe you installed Test::MockObject and it grabbed this too? The
    normal UNIVERSAL.pm that ships with perl doesn't do this."

My take on the problem is that calling UNIVERSAL::can() as a function is
entirely valid.  From the UNIVERSAL docs:

   "can" can be called as a class (static) method, an object method,
    or a function.

Now I accept that calling UNIVERSAL::can() as a function may not be the
best practice if you're building a strict OO system.  And in the particular
case of that Provider code, there may be a better way to crack that nut.

But in other parts of TT, like the Stash for example, we have to bend over
backwards to make the dotop work across a wide range of different objects,
some of which are strictly OO, and others which aren't.  And that's when
calling UNIVERSAL::can as a function is your friend (or mine as the case
may be).

So in short, if you want to get rid of the warnings, then you need to stop
using the UNIVERSAL::can module.  It deliberately sets out to "break" other
modules in an attempt to impose and enforce one particular programming 
paradigm.  I think that's wrong, especially when the Perl docs for U::can()
explicitly say that it's OK to call it as a function.

I'll try and work around it in TT3 if I can.  But right now, I'm maintaining
my SEP Field[*] around it.


[*] http://en.wikipedia.org/wiki/Somebody_Else's_Problem_field