changed Class::Inspector to load_class; finished 0.03
[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    qw( croak );
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( @{ $libraries{ $l } }, { 
41             -into    => scalar(caller),
42             -wrapper => $class,
43         });
44     }
45     return 1;
46 }
47
48 1;
49
50 =head1 SEE ALSO
51
52 L<MooseX::Types>
53
54 =head1 AUTHOR AND COPYRIGHT
55
56 Robert 'phaylon' Sedlacek C<E<lt>rs@474.atE<gt>>, with many thanks to
57 the C<#moose> cabal on C<irc.perl.org>.
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