MX::Method with Maybe[] not working?

[email protected] ("Noel Maddy")
Newsgroups perl.moose
Message-ID <[email protected]>
I'm not getting what I expect when I use Maybe[] with MX::Method. Am I
misunderstanding this, or doing something wrong?

I have a method that needs to accept either a scalar value or undefined.
With 'Value', it accepts any defined scalar. But with 'Maybe[Value]', it
rejects all scalars.

Method is defined as:

  method 'validate' => positional( { isa => 'Maybe[Value]', required =>
1 } ) => sub { 1; };

No matter whether I pass in a scalar or undefined value, I get:

  Parameter 0: Argument isn't (Maybe[Value])

Poking in the debugger, it seems to show that 'Maybe[Value]' requires an
Object:

  DB<2> x $self->{'@!parameter_map'}
0  ARRAY(0x130b0d0)
   0  MooseX::Meta::Parameter=HASH(0x1305240)
      'isa' => 'Maybe[Value]'
      'required' => 1
      'type_constraint' => Moose::Meta::TypeConstraint=HASH(0x13137b0)
         'compiled_type_constraint' => CODE(0x1313770)
            -> &CODE(0x1313770) in ???
         'constraint' => CODE(0x1305280)
            ->
&MooseX::Meta::Parameter::__ANON__[/usr/share/perl5/MooseX/Meta/Parameter.pm:34]
in /usr/share/perl5/MooseX/Meta/Parameter.pm:34-34
         'name' => '__ANON__'
         'package_defined_in' => 'MooseX::Meta::Parameter'
         'parent' => Moose::Meta::TypeConstraint=HASH(0x10c3c20)
            'compiled_type_constraint' => CODE(0x10a3250)
               ->
&Moose::Util::TypeConstraints::OptimizedConstraints::Object in
/usr/share/perl5/Moose/Util/TypeConstraints/OptimizedConstraints.pm:33-33
            'constraint' => CODE(0x10eddc0)
               ->
&Moose::Util::TypeConstraints::__ANON__[/usr/share/perl5/Moose/Util/TypeConstraints.pm:453]
in /usr/share/perl5/Moose/Util/TypeConstraints.pm:453-453
            'hand_optimized_type_constraint' => CODE(0x10a3250)
               -> REUSED_ADDRESS
            'name' => 'Object'
            'package_defined_in' => 'Moose::Util::TypeConstraints'
            'parent' => Moose::Meta::TypeConstraint=HASH(0x10c3540)
               'compiled_type_constraint' => CODE(0x1091ee0)
                  ->
&Moose::Util::TypeConstraints::OptimizedConstraints::Ref in
/usr/share/perl5/Moose/Util/TypeConstraints/OptimizedConstraints.pm:13-13
               'constraint' => CODE(0x10df150)
                  ->
&Moose::Util::TypeConstraints::__ANON__[/usr/share/perl5/Moose/Util/TypeConstraints.pm:418]
in /usr/share/perl5/Moose/Util/TypeConstraints.pm:418-418
               'hand_optimized_type_constraint' => CODE(0x1091ee0)
                  -> REUSED_ADDRESS
               'name' => 'Ref'
               'package_defined_in' => 'Moose::Util::TypeConstraints'
               'parent' => Moose::Meta::TypeConstraint=HASH(0x10c39a0)
                  'compiled_type_constraint' => CODE(0x10c3570)
                     -> &Moose::Meta::TypeConstraint::Defined in 0
                  'constraint' => CODE(0x10ded00)
                     ->
&Moose::Util::TypeConstraints::__ANON__[/usr/share/perl5/Moose/Util/TypeConstraints.pm:405]
in /usr/share/perl5/Moose/Util/TypeConstraints.pm:405-405
                  'name' => 'Defined'
                  'package_defined_in' => 'Moose::Util::TypeConstraints'
                  'parent' =>
Moose::Meta::TypeConstraint=HASH(0x10c35c0)
                     'compiled_type_constraint' => CODE(0x10c3910)
                        -> &Moose::Meta::TypeConstraint::Item in 0
                     'constraint' => CODE(0x10deac0)
                        ->
&Moose::Util::TypeConstraints::__ANON__[/usr/share/perl5/Moose/Util/TypeConstraints.pm:402]
in /usr/share/perl5/Moose/Util/TypeConstraints.pm:402-402
                     'name' => 'Item'
                     'package_defined_in' =>
'Moose::Util::TypeConstraints'
  DB<3> T
. = eval {...} called from file
`/usr/share/perl5/MooseX/Meta/Signature/Positional.pm' line 43
@ =
MooseX::Meta::Signature::Positional::validate(ref(MooseX::Meta::Signature::Positional),
0) called from file `/usr/share/perl5/MooseX/Method.pm' line 85
. = eval {...} called from file `/usr/share/perl5/MooseX/Method.pm' line
84
. = DataSmithy::Role::DataType::validate(ref(Testme), 0) called from
file `t/030-datasmithy-role-datatype.t' line 46
. = main::__ANON__[t/030-datasmithy-role-datatype.t:46]() called from
file `/usr/share/perl5/Sub/Uplevel.pm' line 102
. = Sub::Uplevel::uplevel(3, ref(CODE)) called from file
`/usr/share/perl5/Test/Exception.pm' line 89
. = eval {...} called from file `/usr/share/perl5/Test/Exception.pm'
line 89
$ = Test::Exception::_try_as_caller(ref(CODE)) called from file
`/usr/share/perl5/Test/Exception.pm' line 243
. = Test::Exception::lives_ok(ref(CODE), '->validate succeeds with
undef') called from file `t/030-datasmithy-role-datatype.t' line 46


==============================================================================
CONFIDENTIALITY NOTICE: This email contains information from the sender that may be CONFIDENTIAL, LEGALLY PRIVILEGED, PROPRIETARY or otherwise protected from disclosure. This email is intended for use only by the person or entity to whom it is addressed. If you are not the intended recipient, any use, disclosure, copying, distribution, printing, or any action taken in reliance on the contents of this email, is strictly prohibited. If you received this email in error, please contact the sending party by reply email, delete the email from your computer system and shred any paper copies.
 
Note to Patients: There are a number of risks you should consider before using e-mail to communicate with us. See our Privacy Policy and Henry Ford My Health at www.henryford.com for more detailed information. If you do not believe that our policy gives you the privacy and security protection you need, do not send e-mail or Internet communications to us.

==============================================================================
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.