package MooseX::Types;
+use Moose;
=head1 NAME
#use warnings;
#use strict;
-use Sub::Uplevel;
use Moose::Util::TypeConstraints;
+use MooseX::Types::TypeDecorator;
use MooseX::Types::Base ();
use MooseX::Types::Util qw( filter_tags );
use MooseX::Types::UndefinedType;
-use Sub::Install qw( install_sub );
-use Carp qw( croak );
-use Moose;
+use Carp::Clan qw( ^MooseX::Types );
use namespace::clean -except => [qw( meta )];
-our $VERSION = 0.04;
+our $VERSION = 0.05;
my $UndefMsg = q{Action for type '%s' not yet defined in library '%s'};
MooseX::Types comes with a library of Moose' built-in types called
L<MooseX::Types::Moose>.
+The exporting mechanism is, since version 0.5, implemented via a wrapper
+around L<Sub::Exporter>. This means you can do something like this:
+
+ use MyLibrary TypeA => { -as => 'MyTypeA' },
+ TypeB => { -as => 'MyTypeB' };
+
=head1 WRAPPING A LIBRARY
You can define your own wrapper subclasses to manipulate the behaviour
# generate predeclared type helpers
if (my @orig_declare = @{ $args{ -declare } || [] }) {
my ($tags, $declare) = filter_tags @orig_declare;
+ my @to_export;
for my $type (@$declare) {
croak "Cannot create a type containing '::' ($type) at the moment"
if $type =~ /::/;
+ # add type to library and remember to export
$callee->add_type($type);
- $callee->export_type_into(
- $callee, $type,
- sprintf($UndefMsg, $type, $callee),
- -full => 1,
- );
+ push @to_export, $type;
}
+
+ $callee->import({ -full => 1, -into => $callee }, @to_export);
}
# run type constraints import
sub type_export_generator {
my ($class, $type, $full) = @_;
- return sub {
- return find_type_constraint($full)
- || MooseX::Types::UndefinedType->new($full);
+ return sub {
+ my @args = @_;
+ #use Data::Dump qw/dump/; warn dump @args if @args;
+ my $type_constraint = find_type_constraint($full)
+ || MooseX::Types::UndefinedType->new($full);
+
+ if(@args) {
+ my $tc = $args[0]->[0];
+ # warn dump $tc;
+ # $type_constraint->type_constraint($tc);
+ }
+ return MooseX::Types::TypeDecorator->new(type_constraint=>$type_constraint);
};
}
=head1 SEE ALSO
-L<Moose>, L<Moose::Util::TypeConstraints>, L<MooseX::Types::Moose>
+L<Moose>,
+L<Moose::Util::TypeConstraints>,
+L<MooseX::Types::Moose>,
+L<Sub::Exporter>
=head1 AUTHOR AND COPYRIGHT