switching over to dzil
[gitmo/MooseX-Types.git] / lib / MooseX / Types / Wrapper.pm
1 package MooseX::Types::Wrapper;
2
3 #ABSTRACT: Wrap exports from a library
4
5 use Moose;
6
7 use Carp::Clan      qw( ^MooseX::Types );
8 use Class::MOP;
9
10 use namespace::clean -except => [qw( meta )];
11
12 extends 'MooseX::Types';
13
14 =head1 DESCRIPTION
15
16 See L<MooseX::Types/SYNOPSIS> for detailed usage.
17
18 =head1 METHODS
19
20 =head2 import
21
22 =cut
23
24 sub import {
25     my ($class, @args) = @_;
26     my %libraries = @args == 1 ? (Moose => $args[0]) : @args;
27
28     for my $l (keys %libraries) {
29
30         croak qq($class expects an array reference as import spec)
31             unless ref $libraries{ $l } eq 'ARRAY';
32
33         my $library_class 
34           = ($l eq 'Moose' ? 'MooseX::Types::Moose' : $l );
35         Class::MOP::load_class($library_class);
36
37         $library_class->import({ 
38             -into    => scalar(caller),
39             -wrapper => $class,
40         }, @{ $libraries{ $l } });
41     }
42     return 1;
43 }
44
45 1;
46
47 =head1 SEE ALSO
48
49 L<MooseX::Types>
50
51 =head1 LICENSE
52
53 This program is free software; you can redistribute it and/or modify
54 it under the same terms as perl itself.
55
56 =cut