Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of chorny (7137)

Sunday August 08, 2010
03:08 PM

subtypes + type strictness in Perl

[ #40483 ]

package IPType;
use Regexp::Common 2.105;
use MooseX::Types::Moose qw( Str );
use MooseX::Types -declare => [ qw(IP) ];

subtype IP, as Str, where {
       $_ =~ /\A $RE{net}{IPv4} \z/msx
}, message {
       "'$_' is not a valid IP";


use IPType qw/IP/;
use MooseX::Lexical::Types qw/IP/;

my IP $foo;   # declare typed variable
$foo = '';     # works
$foo = 'bar';  # fails
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.