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; |
6d7f2c07 | 8 | our $VERSION = "0.22"; |
9448c224 | 9 | use Moose; |
c20dc98b | 10 | |
16ddefbf | 11 | use Carp::Clan qw( ^MooseX::Types ); |
9448c224 | 12 | use Class::MOP; |
13 | ||
14 | use namespace::clean -except => [qw( meta )]; | |
c20dc98b | 15 | |
52d358e2 | 16 | extends 'MooseX::Types'; |
3df5416a | 17 | |
9448c224 | 18 | =head1 DESCRIPTION |
19 | ||
20 | See L<MooseX::Types/SYNOPSIS> for detailed usage. | |
21 | ||
22 | =head1 METHODS | |
23 | ||
24 | =head2 import | |
25 | ||
26 | =cut | |
27 | ||
c20dc98b | 28 | sub import { |
29 | my ($class, @args) = @_; | |
30 | my %libraries = @args == 1 ? (Moose => $args[0]) : @args; | |
31 | ||
32 | for my $l (keys %libraries) { | |
33 | ||
34 | croak qq($class expects an array reference as import spec) | |
35 | unless ref $libraries{ $l } eq 'ARRAY'; | |
36 | ||
37 | my $library_class | |
52d358e2 | 38 | = ($l eq 'Moose' ? 'MooseX::Types::Moose' : $l ); |
9448c224 | 39 | Class::MOP::load_class($library_class); |
c20dc98b | 40 | |
16ddefbf | 41 | $library_class->import({ |
57dad71e | 42 | -into => scalar(caller), |
43 | -wrapper => $class, | |
16ddefbf | 44 | }, @{ $libraries{ $l } }); |
c20dc98b | 45 | } |
46 | return 1; | |
47 | } | |
48 | ||
49 | 1; | |
9448c224 | 50 | |
51 | =head1 SEE ALSO | |
52 | ||
53 | L<MooseX::Types> | |
54 | ||
b55332a8 | 55 | =head1 AUTHOR |
9448c224 | 56 | |
b55332a8 | 57 | See L<MooseX::Types/AUTHOR>. |
9448c224 | 58 | |
59 | =head1 LICENSE | |
60 | ||
61 | This program is free software; you can redistribute it and/or modify | |
62 | it under the same terms as perl itself. | |
63 | ||
64 | =cut |