Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

problem with using subtype from MooseX::Types::NetAddr::IP

by lune (Pilgrim)
on Oct 24, 2011 at 13:17 UTC ( #933396=perlquestion: print w/replies, xml ) Need Help??

lune has asked for the wisdom of the Perl Monks concerning the following question:

Hello everybody,

I want to use NetAddrIP as subtype and expected this to be quite straightforward:

package myip; use Moose; use MooseX::Types::NetAddr::IP qw( NetAddrIP NetAddrIPv4 NetAddrIPv6 ) +; has ip => ( is => 'rw', isa => 'NetAddrIP', ); my $ip = myip->new(ip => '127.0.0.1' ); print $ip->ip() . "\n";
However, this gives me a typechecking error, saying "Validation failed for 'NetAddrIP' with value 127.0.0.1". Any ideas what I'm missing?

Replies are listed 'Best First'.
Re: problem with using subtype from MooseX::Types::NetAddr::IP
by zwon (Abbot) on Oct 24, 2011 at 14:45 UTC

    As you declared ip attribute as 'NetAddrIP' Moose want it to be reference to NetAddrIP, you're passing the string. The points you're missing is that NetAddrIP should be without quotes (look into MooseX::Types documentation for the explanation, shortly -- NetAddrIP is a function call), and also you should allow coercion of attribute:

    has ip => ( is => 'rw', isa => NetAddrIP, coerce => 1, );

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-05-26 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?