Hello, monks!

I'm writing a tool using a bunch of modern perl modules (MooseX::Declare, MooseX::Types, MooseX::MultiMethods). But it doesn't work:

Subroutine My::Tool::method redefined at /usr/local/share/perl/5.10.0/ +MooseX/Method/Signatures.pm line 38. Argument cannot be 'type' at /usr/local/share/perl/5.10.0/MooseX/Types +/TypeDecorator.pm line 81 MooseX::Types::TypeDecorator::new('MooseX::Types::TypeDecorator=HA +SH(0xa3f6fe8)', 'type', 'mass', 'from', 'kg', 'to', 'g') called at /h +ome/surikov/lib/My/Tool.pm line 12 My::Tool::__ANON__('My::Tool=HASH(0x93cf9e0)', 'HASH(0x93cf760)') +called at t.pl line 56
I'm definitely missing something, just don't understand what. Any suggestions?

PS: debugging with MooseX::Declare becomes quite difficult and takes a lot of time =(

I have defined my own data types in a separate package, like this:
package My::Types; use strict; use warnings; use MooseX::Types -declare => [qw(Measure MeasureType MeasureUnit some + other types)]; use MooseX::Types::Moose qw(Num Int Str); use MooseX::Types::Structured qw(Dict); use List::MoreUtils qw(any); my @measure_types = qw(some data here); my @measure_units = qw(and here); subtype MeasureType, as Str, where { my $measure_type = $_; any { $measure_type eq lc } @meas +ure_types }, message { 'Unknown measure type' }; subtype MeasureUnit, as Str, where { my $measure_unit = $_; any { $measure_unit eq lc } @meas +ure_units }, message { 'Unknown measure unit' }; subtype Measure, as Dict[ type => MeasureType, from => MeasureUnit, to => MeasureUnit, amount => Num, ], message { 'Invalid Measure struct' }; # more subtypes goes here
And here is the usage:
class My::Tool { # ... multi method convert(Measure $measure) { my $converter = My::Tool->new( type => $measure->{type}, from => $measure->{from}, to => $measure->{to}, ); $converter->calculate($measure->{amount}) } # more 'convert' methods omitted }

In reply to MooseX::Types::TypeDecorator error by KSURi

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.