Subject: | Prints confusing warning on unloaded classes |
Looks like there's been no resolution on the discussion in
http://use.perl.org/~jk2addict/journal/34808
so let me file this as a bug. And it is a bug in UNIVERSAL::can IMO.
Without this module, the following code works as expected:
if(DateTime::Locale::en->can('new')) {
print "I can\n";
}
DateTime::Locale::en hasn't been loaded at that point, but perl's can()
doesn't freak out on this and returns false, because there's no new()
method available in a class that's not been loaded.
On the other hand, if you use UNIVERSAL::can as in
use UNIVERSAL::can;
if(DateTime::Locale::en->can('new')) {
print "I can\n";
}
then you get this confusing error message:
Called UNIVERSAL::can() as a function, not a method at script line 6
Note that if you preload DateTime::Locale::en, as in
use DateTime::Locale::en;
use UNIVERSAL::can;
if(DateTime::Locale::en->can('new')) {
print "I can\n";
}
then UNIVERSAL::can works as expected and returns true.
This problem surfaces with the use of Test::MockObject 1.08, which
requires UNIVERSAL::can and prints the warning on perfectly valid code like
BEGIN {
use Test::MockObject;
my $mock = Test::MockObject->new;
$mock->fake_module("Foo::Bar");
}
use DateTime;
because DateTime uses can() to check for available modules.
Looks like the patch proposed in the discussion mentioned above would
fix the problem -- any chance you could release it any time soon?
Thanks!
-- Mike