Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: MooseX::Types::TypeDecorator error

by KSURi (Monk)
on Jul 16, 2009 at 13:49 UTC ( [id://780710]=note: print w/replies, xml ) Need Help??


in reply to Re: MooseX::Types::TypeDecorator error
in thread MooseX::Types::TypeDecorator error

I can't replicate that too! Though below code is just simplified version of my code, it works fine:
use MooseX::Declare; class Foo { use feature qw(say); use Data::Dumper; use MooseX::MultiMethods; use MooseX::Types -declare => [qw(Bar MyStr MyNum)]; use MooseX::Types::Moose qw(Str Num); use MooseX::Types::Structured qw(Dict); BEGIN { subtype MyStr, as Str; subtype MyNum, as Num; subtype Bar, as Dict[ string => MyStr, number => MyNum, ], message { 'Invalid Foo struct' }; }; multi method baz(Bar $barrr) { say'Bar'; say Dumper $barrr } multi method baz(Str $string) { say 'Str'; say Dumper $string; } } no Moose; no MooseX::Declare; 1; package main; my $foo = Foo->new; $foo->baz( { string => 'hello', number => 1.00, } ); $foo->baz( 'hello world' )

Replies are listed 'Best First'.
Re^3: MooseX::Types::TypeDecorator error
by Anonymous Monk on Jul 16, 2009 at 14:34 UTC
    Thanks. My problem is i'm missing MooseX::Declare because Devel-Declare-0.005007 won't compile on windows, sorry :)
Re^3: MooseX::Types::TypeDecorator error
by phaylon (Curate) on Jul 16, 2009 at 22:05 UTC

    You should put your MooseX-Types library into a separate file. The method signatures are parsed at compile time, and if they are defined in the same package, they are not declared yet.


    Ordinary morality is for ordinary people. -- Aleister Crowley
      Yes, as some anonymous monk said above, that's why I put types declaration into BEGIN block (inlined for brevity). In real code these declarations are in a separate file.
      That is why BEGIN{} blocks were invented :)
      BEGIN { use MooseX::Declare; class Foo { use feature qw(say); use Data::Dumper; use MooseX::MultiMethods; use MooseX::Types -declare => [qw(Bar MyStr MyNum)]; use MooseX::Types::Moose qw(Str Num); use MooseX::Types::Structured qw(Dict); BEGIN { subtype MyStr, as Str; subtype MyNum, as Num; subtype Bar, as Dict[ string => MyStr, number => MyNum, ], message { 'Invalid Foo struct' }; }; multi method baz(Bar $barrr) { say'Bar'; say Dumper $barrr } multi method baz(Str $string) { say 'Str'; say Dumper $string; } } } no Moose; no MooseX::Declare; 1; package main; my $foo = Foo->new; $foo->baz( { string => 'hello', number => 1.00, } ); $foo->baz( 'hello world' )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://780710]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 04:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found