Skip Menu |

This queue is for tickets about the UNIVERSAL-can CPAN distribution.

Report information
The Basics
Id: 31350
Status: resolved
Priority: 0/
Queue: UNIVERSAL-can

People
Owner: Nobody in particular
Requestors: MSCHILLI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.12
Fixed in: (no value)



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
From: chromatic [...] wgz.org
On Mon Dec 10 13:41:58 2007, MSCHILLI wrote: Show quoted text
> 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 Show quoted text
> > 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?
I believe 1.13_001 should correct this problem. Can you confirm?
Fixed in 1.14.