MooseX::Types::CheckedUtilExports - Wrap L<Moose::Util::TypeConstraints> to be safer for L<MooseX::Types>


MooseX-Types documentation Contained in the MooseX-Types distribution.

Index


Code Index:

NAME

Top

MooseX::Types::CheckedUtilExports - Wrap Moose::Util::TypeConstraints to be safer for MooseX::Types

VERSION

Top

version 0.27

DESCRIPTION

Top

Prevents errors like:

    subtype Foo =>
    ...

Which should be written as:

    subtype Foo,
    ...

When using MooseX::Types. Exported by that module.

Exports checked versions of the following subs:

type subtype maybe_type duck_type enum coerce from as

While class_type and role_type will also register the type in the library.

From Moose::Util::TypeConstraints. See that module for syntax.

SEE ALSO

Top

MooseX::Types

LICENSE

Top

This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.

AUTHOR

Top

Robert "phaylon" Sedlacek <rs@474.at>

COPYRIGHT AND LICENSE

Top


MooseX-Types documentation Contained in the MooseX-Types distribution.

package MooseX::Types::CheckedUtilExports;
BEGIN {
  $MooseX::Types::CheckedUtilExports::VERSION = '0.27';
}

#ABSTRACT: Wrap L<Moose::Util::TypeConstraints> to be safer for L<MooseX::Types>

use strict;
use warnings;
use Moose::Util::TypeConstraints ();
use Moose::Exporter;
use Sub::Name;
use Carp;

use namespace::clean -except => 'meta';

my $StringFoundMsg =
q{WARNING: String found where Type expected (did you use a => instead of a , ?)};

my @exports = qw/type subtype maybe_type duck_type enum coerce from as/;


for my $export (@exports) {
    no strict 'refs';

    *{$export} = sub {
        my $caller = shift;

        local $Carp::CarpLevel = $Carp::CarpLevel + 1;

        carp $StringFoundMsg
            unless ref($_[0]) ||
                $_[0] =~ /\b::\b/ || # qualified type
                $caller->get_registered_class_type($_[0]) ||
                $caller->get_registered_role_type($_[0]);

        goto &{"Moose::Util::TypeConstraints::$export"};
    }
}

Moose::Exporter->setup_import_methods(
    with_caller => [ @exports, 'class_type', 'role_type' ]
);

sub class_type {
    my $caller = shift;

    $caller->register_class_type(
        Moose::Util::TypeConstraints::class_type(@_)
    );
}

sub role_type ($;$) {
    my ($caller, $name, $opts) = @_;

    $caller->register_role_type(
        Moose::Util::TypeConstraints::role_type($name, $opts)
    );
}


1;

__END__