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