Make formatting more like the rest of the code
[gitmo/MooseX-Types.git] / lib / MooseX / Types / Combine.pm
index f41fd6e..43aa79f 100644 (file)
@@ -1,11 +1,6 @@
-=head1 NAME
-
-MooseX::Types::Combine - Combine type libraries for exporting
-
-=cut
-
 package MooseX::Types::Combine;
-our $VERSION = "0.24";
+
+# ABSTRACT: Combine type libraries for exporting
 
 use strict;
 use warnings;
@@ -36,20 +31,23 @@ sub import {
     my ($class, @types) = @_;
     my $caller = caller;
 
-    my @type_libs = $class->provide_types_from;
-    Class::MOP::load_class($_) for @type_libs;
+    my %types = $class->_provided_types;
 
-    my %types = map {
-        my $lib = $_;
-        map +($_ => $lib), $lib->type_names
-    } @type_libs;
+    if ( grep { $_ eq ':all' } @types ) {
+        $_->import( { -into => $caller }, q{:all} )
+            for $class->provide_types_from;
+        return;
+    }
 
     my %from;
     for my $type (@types) {
-        die
-            "$caller asked for a type ($type) which is not found in any of the"
-            . " type libraries (@type_libs) combined by $class\n"
-            unless $types{$type};
+        unless ($types{$type}) {
+            my @type_libs = $class->provide_types_from;
+
+            die
+                "$caller asked for a type ($type) which is not found in any of the"
+                . " type libraries (@type_libs) combined by $class\n";
+        }
 
         push @{ $from{ $types{$type} } }, $type;
     }
@@ -72,18 +70,45 @@ sub provide_types_from {
     my $store =
      do { no strict 'refs'; \@{ "${class}::__MOOSEX_TYPELIBRARY_LIBRARIES" } };
 
-    @$store = @libs if @libs;
+    if (@libs) {
+        $class->_check_type_lib($_) for @libs;
+        @$store = @libs;
+
+        my %types = map {
+            my $lib = $_;
+            map +( $_ => $lib ), $lib->type_names
+        } @libs;
+
+        $class->_provided_types(%types);
+    }
 
     @$store;
 }
 
-=head1 SEE ALSO
+sub _check_type_lib {
+    my ($class, $lib) = @_;
 
-L<MooseX::Types>
+    Class::MOP::load_class($lib);
+
+    die "Cannot use $lib in a combined type library, it does not provide any types"
+        unless $lib->can('type_names');
+}
+
+sub _provided_types {
+    my ($class, %types) = @_;
+
+    my $types =
+     do { no strict 'refs'; \%{ "${class}::__MOOSEX_TYPELIBRARY_TYPES" } };
 
-=head1 AUTHOR
+    %$types = %types
+        if keys %types;
 
-See L<MooseX::Types/AUTHOR>.
+    %$types;
+}
+
+=head1 SEE ALSO
+
+L<MooseX::Types>
 
 =head1 LICENSE