Commit | Line | Data |
---|---|---|
9448c224 | 1 | =head1 NAME |
2 | ||
3 | MooseX::Types::Wrapper - Wrap exports from a library | |
4 | ||
5 | =cut | |
6 | ||
52d358e2 | 7 | package MooseX::Types::Wrapper; |
9448c224 | 8 | use Moose; |
c20dc98b | 9 | |
16ddefbf | 10 | use Carp::Clan qw( ^MooseX::Types ); |
9448c224 | 11 | use Class::MOP; |
12 | ||
13 | use namespace::clean -except => [qw( meta )]; | |
c20dc98b | 14 | |
52d358e2 | 15 | extends 'MooseX::Types'; |
3df5416a | 16 | |
9448c224 | 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 | ||
c20dc98b | 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 | |
52d358e2 | 37 | = ($l eq 'Moose' ? 'MooseX::Types::Moose' : $l ); |
9448c224 | 38 | Class::MOP::load_class($library_class); |
c20dc98b | 39 | |
16ddefbf | 40 | $library_class->import({ |
57dad71e | 41 | -into => scalar(caller), |
42 | -wrapper => $class, | |
16ddefbf | 43 | }, @{ $libraries{ $l } }); |
c20dc98b | 44 | } |
45 | return 1; | |
46 | } | |
47 | ||
48 | 1; | |
9448c224 | 49 | |
50 | =head1 SEE ALSO | |
51 | ||
52 | L<MooseX::Types> | |
53 | ||
b55332a8 | 54 | =head1 AUTHOR |
9448c224 | 55 | |
b55332a8 | 56 | See L<MooseX::Types/AUTHOR>. |
9448c224 | 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 |