Subject: | T::MO::Extends fails to mock inline package that has no "new" |
Test::MockObject::Extends dies when trying to mock packages defined
inline (ie not in an external .pm file) if the package has no new
method. This does not happen with packages defined in an external .pm
file, but there is a warning produced from UNIVERSAL::can.
mark:~/work/justice/migration$ cat mockobject.t
use strict;
use warnings;
use Test::MockObject;
use Test::MockObject::Extends;
print "Test::MockObject version $Test::MockObject::VERSION\n";
print "Test::MockObject::Extends version
$Test::MockObject::Extends::VERSION\n";
print "UNIVERSAL::can version $UNIVERSAL::can::VERSION\n";
{
package InlinePackageNoNew;
}
{
package InlinePackageHasNew;
sub new {
}
}
my @testPackages = qw( InlinePackageNoNew InlinePackageHasNew
ExternalPackageHasNew ExternalPackageNoNew );
foreach my $testPackage(@testPackages){
print ">>>>>>>>>>>>>>>>>>>>>> ";
print "attempt to mock $testPackage....";
eval {
my $mocker = Test::MockObject::Extends->new($testPackage);
print "success\n";
};
if($@){
print "failed\n";
print $@ if $@;
}
print "\n";
}
mark:~/work/justice/migration$ cat ExternalPackage
ExternalPackageHasNew.pm ExternalPackageNoNew.pm
mark:~/work/justice/migration$ cat ExternalPackageHasNew.pm
package ExternalPackageHasNew;
sub new{
}
1;
mark:~/work/justice/migration$ cat ExternalPackageNoNew.pm
package ExternalPackageNoNew;
1;
mark:~/work/justice/migration$ perl mockobject.t
Test::MockObject version 1.02
Test::MockObject::Extends version 1.01
UNIVERSAL::can version 1.11
Show quoted text
>>>>>>>>>>>>>>>>>>>>>> attempt to mock InlinePackageNoNew....failed
Can't locate InlinePackageNoNew.pm in @INC (@INC contains:
/home/perl/lib//i486-linux-gnu-thread-multi /home/perl/lib/
/home/perl/share/perl//5.8.7 /home/perl/share/perl/
/home/perl/share/perl/5.8.7/ . /etc/perl /usr/local/lib/perl/5.8.7
/usr/local/share/perl/5.8.7 /usr/lib/perl5 /usr/share/perl5
/usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl
/usr/local/lib/perl/5.8.4 .) at
/home/perl/lib//Test/MockObject/Extends.pm line 22.
Show quoted text>>>>>>>>>>>>>>>>>>>>>> attempt to mock InlinePackageHasNew....success
Show quoted text>>>>>>>>>>>>>>>>>>>>>> attempt to mock
ExternalPackageHasNew....Called UNIVERSAL::can() as a function, not a
method at /home/perl/lib//Test/MockObject/Extends.pm line 19
success
Show quoted text>>>>>>>>>>>>>>>>>>>>>> attempt to mock
ExternalPackageNoNew....Called UNIVERSAL::can() as a function, not a
method at /home/perl/lib//Test/MockObject/Extends.pm line 19
success
perl is v5.8.7 built for i486-linux-gnu-thread-multi.
regards,
Mark