reorganize author/copyright sections at the request of Debian packagers
[gitmo/MooseX-Types.git] / lib / MooseX / Types / Combine.pm
CommitLineData
ca9d7442 1=head1 NAME
2
3MooseX::Types::Combine - Combine type libraries for exporting
4
5=cut
6
7package MooseX::Types::Combine;
8
9use strict;
10use warnings;
11use Class::MOP ();
12
13=head1 SYNOPSIS
14
15 package CombinedTypeLib;
16
17 use base 'MooseX::Types::Combined';
18
19 __PACKAGE__->provide_types_from(qw/TypeLib1 TypeLib2/);
20
21 package UserClass;
22
23 use CombinedTypeLib qw/Type1 Type2 ... /;
24
25=head1 DESCRIPTION
26
27Allows you to export types from multiple type libraries.
28
29Libraries on the right side of the type libs passed to L</provide_types_from>
30take precedence over those on the left in case of conflicts.
31
32=cut
33
34sub import {
35 my ($class, @types) = @_;
36 my $caller = caller;
37
38 my @type_libs = $class->provide_types_from;
39 Class::MOP::load_class($_) for @type_libs;
40
41 my %types = map {
42 my $lib = $_;
43 map +($_ => $lib), $lib->type_names
44 } @type_libs;
45
46 my %from;
47 push @{ $from{ $types{ $_ } } }, $_ for @types;
48
49 $_->import({ -into => $caller }, @{ $from{ $_ } })
50 for keys %from;
51}
52
53=head1 CLASS METHODS
54
55=head2 provide_types_from
56
57Sets or returns a list of type libraries to re-export from.
58
59=cut
60
61sub provide_types_from {
62 my ($class, @libs) = @_;
63
64 my $store =
65 do { no strict 'refs'; \@{ "${class}::__MOOSEX_TYPELIBRARY_LIBRARIES" } };
66
67 @$store = @libs if @libs;
68
69 @$store;
70}
71
72=head1 SEE ALSO
73
74L<MooseX::Types>
75
b55332a8 76=head1 AUTHOR
77
78See L<MooseX::Types/AUTHOR>.
79
ca9d7442 80=head1 LICENSE
81
82This program is free software; you can redistribute it and/or modify
83it under the same terms as perl itself.
84
85=cut
86
871;