First, thank you guys very much for answering questions. It's very appreciated.
I've been playing around with MooseX and I'm confused as to a problem with the following code (perl 5.12.2 on a linux box, btw):
My output is this:use strict; use warnings; use MooseX::Declare; class Foo { use MooseX::Types::Moose qw(Num); method print_number (Num $num) { print "Yep. ($num) is a number.\n\n"; } method regex_number_then_print (Num $num) { $num =~ /(\d*\.\d+)/; print " ** I found ($1) during regex.\n"; $self->print_number($1); } method regex_number_then_print_with_quotes (Num $num) { $num =~ /(\d*\.\d+)/; print " ** I found ($1) during regex.\n"; $self->print_number("$1"); } method regex_number_then_print_with_intermediate_var (Num $num) { $num =~ /(\d*\.\d+)/; print " ** I found ($1) during regex.\n"; my $tmp = $1; $self->print_number($tmp); } } package main; my $obj = Foo->new; print "###### Directly printing number #####\n"; $obj->print_number('1.7'); print "###### Directly printing quoted number #####\n"; $obj->regex_number_then_print_with_quotes('1.7'); print "###### Directly printing number after intermediate variable lau +ndering #####\n"; $obj->regex_number_then_print_with_intermediate_var('1.7'); print "###### Directly printing number from capture variable \$1 ##### +\n"; $obj->regex_number_then_print('1.7');
plxc16479> tmp12.pl ###### Directly printing number ##### Yep. (1.7) is a number. ###### Directly printing quoted number ##### ** I found (1.7) during regex. Yep. (1.7) is a number. ###### Directly printing number after intermediate variable laundering + ##### ** I found (1.7) during regex. Yep. (1.7) is a number. ###### Directly printing number from capture variable $1 ##### ** I found (1.7) during regex. Validation failed for 'Tuple[Tuple[Object,Num],Dict[]]' with value [ [ + Foo=HASH(0x63d490), "coerce" ], { } ], Internal Validation Error is +: [+] Validation failed for 'Tuple[Object,Num]' with value [ Foo{ }, " +coerce" ] [+] Validation failed for 'Num' with value coerce at /nfs/pdx/disks/ +nehalem.pde.077/perl/lib64/site_perl/MooseX/Method/Signatures/Meta/Me +thod.pm line 435 MooseX::Method::Signatures::Meta::Method::validate('MooseX::Me +thod::Signatures::Meta::Method=HASH(0x1cbefd0)', 'ARRAY(0x1cbf330)') +called at /nfs/pdx/disks/nehalem.pde.077/perl/lib64/site_perl/MooseX/ +Method/Signatures/Meta/Method.pm line 151 Foo::print_number('Foo=HASH(0x63d490)', 1.7) called at tmp12.p +l line 15 Foo::regex_number_then_print('Foo=HASH(0x63d490)', 1.7) called + at tmp12.pl line 41
It seems to indicate the call is being made with the correct values, judging from this line:
Foo::print_number('Foo=HASH(0x63d490)', 1.7) called at tmp12.pWhy the error when printing directly from the $1 capture variable? Why does it work when the capture variable is quoted or intermediated? Am I doing something wrong?
In reply to a MooseX Q that's driving me up the wall :) by tj_thompson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |