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 => '' ); print $ip->ip() . "\n";
However, this gives me a typechecking error, saying "Validation failed for 'NetAddrIP' with value". 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, );