1 package MooseX::Types::Combine;
3 # ABSTRACT: Combine type libraries for exporting
11 package CombinedTypeLib;
13 use base 'MooseX::Types::Combine';
15 __PACKAGE__->provide_types_from(qw/TypeLib1 TypeLib2/);
19 use CombinedTypeLib qw/Type1 Type2 ... /;
23 Allows you to export types from multiple type libraries.
25 Libraries on the right side of the type libs passed to L</provide_types_from>
26 take precedence over those on the left in case of conflicts.
31 my ($class, @types) = @_;
34 my %types = $class->_provided_types;
36 if ( grep { $_ eq ':all' } @types ) {
37 $_->import( { -into => $caller }, q{:all} )
38 for $class->provide_types_from;
43 for my $type (@types) {
44 unless ($types{$type}) {
45 my @type_libs = $class->provide_types_from;
48 "$caller asked for a type ($type) which is not found in any of the"
49 . " type libraries (@type_libs) combined by $class\n";
52 push @{ $from{ $types{$type} } }, $type;
55 $_->import({ -into => $caller }, @{ $from{ $_ } })
61 =head2 provide_types_from
63 Sets or returns a list of type libraries to re-export from.
67 sub provide_types_from {
68 my ($class, @libs) = @_;
71 do { no strict 'refs'; \@{ "${class}::__MOOSEX_TYPELIBRARY_LIBRARIES" } };
74 $class->_check_type_lib($_) for @libs;
79 map +( $_ => $lib ), $lib->type_names
82 $class->_provided_types(%types);
89 my ($class, $lib) = @_;
91 Class::MOP::load_class($lib);
93 die "Cannot use $lib in a combined type library, it does not provide any types"
94 unless $lib->can('type_names');
98 my ($class, %types) = @_;
101 do { no strict 'refs'; \%{ "${class}::__MOOSEX_TYPELIBRARY_TYPES" } };
115 This program is free software; you can redistribute it and/or modify
116 it under the same terms as perl itself.