Subject: | MooseX::Getopt doesn't play good with MooseX::StrictConstructor (sometimes) |
Hi,
I've caught quite an edge case:
MooseX::Getopt, when used in conjunction with MooseX::StrictConstructor can blow up if you use new_with_options(argv => [...]). The problem comes to be that new_with_options tries to call new, passing the argv parameter too. Since the class being instanced most likely won't have an argv attribute, MooseX::StrictConstructor will make it blow up.
This is a small example of how to reproduce:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Printer;
package X {
use Moose;
with 'MooseX::Getopt';
use MooseX::StrictConstructor;
has a => (is => 'ro', isa => 'Str');
has b => (is => 'ro', isa => 'Str');
}
my $o = X->new_with_options(argv => [ '--b', 'b' ]);
# Never get here ("argv" isn't an attribute of X) :(
p $o;
I've gone ahead, forked and tried to fix the issue and made a pull request on GitHub. Hope it helps!
Jose Luis Martinez
JLMARTIN