[SCM] libpackage-variant-perl Debian packaging branch, master, updated. debian/1.001003-1-16-g363631d

Robert Sedlacek rs at 474.at
Thu May 9 17:13:57 UTC 2013


The following commit has been merged in the master branch:
commit 203d81fc3c1966d9a28a96987ccf49c2b7bfde97
Author: Robert Sedlacek <rs at 474.at>
Date:   Wed Dec 21 00:03:23 2011 +0100

    more complete error handling and error testing

diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm
index bd39d4f..977f76c 100644
--- a/lib/Package/Variant.pm
+++ b/lib/Package/Variant.pm
@@ -9,26 +9,36 @@ my $sanitize_importing = sub {
   my ($me, $spec) = @_;
   return []
     unless defined $spec;
-  return [map {
-    my $import_args = $spec->{$_};
-    croak sprintf q{Import argument list for '%s' is not an array ref},
-      $_,
-      unless ref($import_args) and ref($import_args) eq 'ARRAY';
-    [$_ => $import_args];
-  } keys %$spec]
-    if ref $spec eq 'HASH';
-  croak q{The 'importing' option has to be either a hash or array ref}
-    unless ref $spec eq 'ARRAY';
-  my @specced = @$spec;
+  my @specced =
+    not(ref $spec)
+      ? ($spec)
+    : (ref($spec) eq 'ARRAY')
+      ? (@$spec)
+    : (ref($spec) eq 'HASH')
+      ? (map {
+          croak qq{The import argument list for '$_' is not an array ref}
+            unless ref($spec->{$_}) eq 'ARRAY';
+          ($_ => $spec->{$_});
+        } sort keys %$spec)
+    : croak q{The 'importing' option has to be either a hash or array ref};
   my @imports;
+  my $arg_count = 1;
   while (@specced) {
     my $key = shift @specced;
-    push @imports, [
-      $key,
-      (ref($specced[0]) and ref($specced[0]) eq 'ARRAY')
-        ? shift(@specced)
-        : [],
-    ];
+    croak qq{Value $arg_count in 'importing' is not a package string},
+      $arg_count
+      unless defined($key) and not(ref $key);
+    $arg_count++;
+    my $import_args =
+      (not(@specced) or (defined($specced[0]) and not ref($specced[0])))
+        ? []
+      : (ref($specced[0]) eq 'ARRAY')
+        ? do { $arg_count++; shift @specced }
+      : croak(
+            qq{Value $arg_count for package '$key' in 'importing' is not}
+          . qq{ a package string or array ref}
+        );
+    push @imports, [$key, $import_args];
   }
   return \@imports;
 };
diff --git a/t/01simple.t b/t/01simple.t
index e41d27f..2a060cb 100644
--- a/t/01simple.t
+++ b/t/01simple.t
@@ -85,6 +85,21 @@ TestArrayImports(23);
 is_deeply [@imported], [qw( TestImportableA TestImportableB )],
   'multiple imports in the right order';
 
+BEGIN {
+  package TestSingleImport;
+  use Package::Variant importing => 'TestImportableA';
+  sub make_variant { }
+  $INC{'TestSingleImport.pm'} = __FILE__;
+}
+
+ at imported = ();
+
+use TestSingleImport;
+TestSingleImport(23);
+
+is_deeply [@imported], [qw( TestImportableA )],
+  'scalar import works';
+
 like exception {
   Package::Variant->import(
     importing => \'foo', subs => [qw( foo )],
@@ -95,6 +110,18 @@ like exception {
   Package::Variant->import(
     importing => { foo => \'bar' }, subs => [qw( bar )],
   );
-}, qr/import.+argument.+not.+array/i, 'invalid import argument list';
+}, qr/import.+argument.+foo.+not.+array/i, 'invalid import argument list';
+
+like exception {
+  Package::Variant->import(
+    importing => [ foo => ['bar'], ['bam'], subs => [qw( bar )] ],
+  );
+}, qr/value.+3.+importing.+not.+string/i, 'importing array invalid key';
+
+like exception {
+  Package::Variant->import(
+    importing => [ foo => \'bam', subs => [qw( bar )] ],
+  );
+}, qr/value.+2.+foo.+importing.+array/i, 'importing array invalid list';
 
 done_testing;

-- 
libpackage-variant-perl Debian packaging



More information about the Pkg-perl-cvs-commits mailing list