Question

I'm currently refactoring a test suite built up by a colleague and would like to use Test::Class[::Most] while doing so. As I started I figured out I could really use a couple of Moose roles to decouple code a little bit. However, it seems it's not quite possible -- I'm getting error messages like this one:

Prototype mismatch: sub My::Test::Class::Base::blessed: none vs ($) at
/usr/lib/perl5/vendor_perl/5.8.8/Sub/Exporter.pm line 896

So the question is: can I use Moose together with Test::Class and if so, how?

PS: The code goes like this:

package My::Test::Class::Base;
use Moose;
use Test::Class::Most;

with 'My::Cool::Role';

has attr => ( ... );
Était-ce utile?

La solution

Test::Deep (loaded via Test::Most via Test::Class::Most) is exporting its own blessed along with a lot of other stuff it probably shouldn't be. Its not documented. Moose is also exporting the more common Scalar::Util::blessed. Since Scalar::Util::blessed is fairly common, Test::Deep should not be exporting its own different blessed.

Unfortunately, there's no good way to stop it. I'd suggest in My::Test::Class::Base doing the following hack:

package My::Test::Class::Base;

# Test::Class::Most exports Test::Most exports Test::Deep which exports
# an undocumented blessed() which clashes with Moose's blessed().
BEGIN {
    require Test::Deep;
    @Test::Deep::EXPORT = grep { $_ ne 'blessed' } @Test::Deep::EXPORT;
}

use Moose;
use Test::Class::Most;

and reporting the problem to Test::Deep and Test::Most.

Autres conseils

You can squelch particular exports via (for example):

use Test::Deep '!blessed';

I've just released an updated version of Test::Most. If you install 0.30, this issue goes away.

Folks finding this page might also be interested to know about the various Test::Class-Moose mashup modules:

With any of these some amount of refactoring would required-- the syntax varies. HOwever, with some amount of find-and-replace you may be able to make a fairly quick transition.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top