This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libpackage-variant-perl.

commit 6779ecfd9c1a2a51cc5c26596ced7a36e27cf9dd
Author: Matt S Trout <m...@shadowcat.co.uk>
Date:   Fri Jul 3 19:04:48 2015 +0000

    add make_variant_package_name optional method
---
 Changes                |  2 ++
 lib/Package/Variant.pm | 23 ++++++++++++++++++++++-
 t/01simple.t           | 19 +++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/Changes b/Changes
index ce9d1db..24dc98d 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Package-Variant
 
+  - add make_variant_package_name optional method
+
 1.002002 - 2014-08-21
   - fix license in metadata
 
diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm
index a242d93..06cf0bf 100644
--- a/lib/Package/Variant.pm
+++ b/lib/Package/Variant.pm
@@ -94,9 +94,17 @@ sub import {
   };
 }
 
+sub build_variant_package_name {
+  my ($me, $variable, @args) = @_;
+  if ($variable->can('make_variant_package_name')) {
+    return $variable->make_variant_package_name(@args);
+  }
+  return "${variable}::_Variant_".++$Variable{$variable}{anon};
+}
+
 sub build_variant_of {
   my ($me, $variable, @args) = @_;
-  my $variant_name = "${variable}::_Variant_".++$Variable{$variable}{anon};
+  my $variant_name = $me->build_variant_package_name($variable, @args);
   foreach my $to_import (@{$Variable{$variable}{args}{importing}}) {
     my ($pkg, $args) = @$to_import;
     require_module $pkg;
@@ -316,6 +324,19 @@ declared in L</subs> to customize the new variant package.
 This is a class method receiving the C<$target> package and the
 C<@arguments> defining the requested variant.
 
+=head2 make_variant_package_name
+
+  Some::Variant::Package->make_variant_package_name( @arguments );
+
+B<You may optionally provide this method.> If present, this method will be
+used to determine the package name for a particular variant being constructed.
+
+If you do not implement it, a unique package name something like
+
+  Some::Variant::Package::_Variant_A003
+
+will be created for you.
+
 =head2 import
 
   use Some::Variant::Package;
diff --git a/t/01simple.t b/t/01simple.t
index 3d3813d..6e8348c 100644
--- a/t/01simple.t
+++ b/t/01simple.t
@@ -131,4 +131,23 @@ like exception {
   );
 }, qr/value.+2.+foo.+importing.+array/i, 'importing array invalid list';
 
+BEGIN {
+  package TestOverrideName;
+
+  use Package::Variant;
+
+  sub make_variant_package_name {
+    my (undef, @args) = @_;
+    return $args[0];
+  }
+
+  sub make_variant {
+    install hey => sub { 'hey' };
+  }
+}
+
+is(TestOverrideName::->build_variant('hey'), 'hey');
+
+is(hey->hey, 'hey', 'hey');
+
 done_testing;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libpackage-variant-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to