RSS Git Download  Clone
Raw Blame History
package Local::MooX::Types;

use MooX::Types::MooseLike;
use Scalar::Util qw(blessed);

use base qw(Exporter);
our @EXPORT_OK = ();

# define some types
my @defs = (
	{
        name 	=> 'HashReference',
        test	=> sub { ref $_[0] eq 'HASH' },
        message => sub { "$_[0] is not a hashref" }
	},
	{
        name 	=> 'ArrayReference',
        test	=> sub { ref $_[0] eq 'ARRAY' },
        message => sub { "$_[0] is not an arrayref" }
	},
    { # from the docs: isa => VarChar[25]:
        name => 'VarChar',
        test => sub {
            my ($value, $param) = @_;
            length($value) <= $param;
        },
        message => sub { "$_[0] is too large! It should be <= $_[1]" }
    },
    {
        name    => 'String', # test taken from MooX/Types/MooseLike/Base.pm source-code:
        test    => sub { defined $_[0] and (ref(\$_[0]) eq 'SCALAR') },
        message => sub { "$_[0] is not a string" },
    },
    {
        name    => 'Integer',
        test    => sub { defined $_[0] and $_[0] =~ /\A\d+\Z/ },
        message => sub { "$_[0] is not an integer" },
    },
    {
        name => 'Object', # test taken from MooX/Types/MooseLike/Base.pm source-code:
        test => sub {
            defined $_[0] and blessed($_[0]) and blessed($_[0]) ne 'Regexp'
        },
        message => sub { "$_[0] is not an Object" },
    },
);
MooX::Types::MooseLike::register_types(\@defs, __PACKAGE__);

1;