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):

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');
My output is this:
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.p

Why 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.