--- Adriano Ferreira <a.r.ferreira gmail.com> wrote:
> On 1/17/07, ti lemonia.org <ti lemonia.org> wrote:
> > UNIVERSAL::can tells you what methods are *in the
hash*. It doesn't
> tell
> > you what AUTOLOAD would do, because, as you say,
it can't.
>
> ->can is a method. Its base implementation (the one
provided by
> UNIVERSAL package) "tells you what methods are *in
the hash*" (as you
> said).
To be fair, it doesn't quite do that (depending upon how you
look at
it). If you merely have a forward declaration and no
method,
UNIVERSAL->can($method) succeeds, but then invoking the
method fails.
package Foo;
sub bar;
package main;
use Test::More 'no_plan';
can_ok 'Foo', 'bar';
ok my $method = Foo->can('bar'), '...
can("bar") should succeed';
diag +Foo->$method;
Results in the rather confusing:
ok 1 - Foo->can('bar')
ok 2 - ... can("bar") should succeed
Undefined subroutine &Foo::bar called at universal.pl
line 13.
1..2
# Looks like your test died just after 2.
ok
All tests successful.
Files=1, Tests=2, 0 wallclock secs ( 0.04 cusr + 0.00
csys = 0.04
CPU)
Basically, a forward declaration appears to fill the
*Foo::bar
slot. I personally think this is bug in 'can', but I'm sure
opinions
will differ on this.
Cheers,
Ovid
--
Buy the book -- http://www.or
eilly.com/catalog/perlhks/
Perl and CGI -- http://u
sers.easystreet.com/ovid/cgi_course/
|