Subject: | methods doens't work for AUTOLOADed methods |
The methods comparison doesn't work on AUTOLOADed methods. Here's a test case, module first and then script.
----------
package TestDeepAutoloadBug;
sub new {return bless {},'TestDeepAutoloadBug'}
sub works {return 1}
use vars qw($AUTOLOAD);
sub AUTOLOAD {
my $self=shift;
my $method=$AUTOLOAD;
$method=~s/^.*:://; # strip class qualification
return if $method eq 'DESTROY'; # the books say you should do this
return 1;
}
1;
----------
use Test::More qw/no_plan/;
use Test::Deep;
use TestDeepAutoloadBug;
$obj=new TestDeepAutoloadBug;
cmp_deeply($obj,methods(works=>1),'this one works, of course');
cmp_deeply($obj,methods(bug=>1),'this one does not work');
----------
The obvious fix is to invoke the method inside an eval rather than relying on UNIVERSAL::can in Test::Deep::Methods::descend. (This suggestion presupposes that my weak understanding of the code is even marginally accurate :) I don't know what the performance impact might be.
Thanks,
Nat Goodman