From: Graham Knop Date: Fri, 27 Sep 2013 17:09:22 +0000 (-0400) Subject: add build_variant method on variable packages X-Git-Tag: v1.002000~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5a0662d9857ea1ee0717fa919d134115fd3441a8;p=p5sagit%2FPackage-Variant.git add build_variant method on variable packages --- diff --git a/Changes b/Changes index e25d5bf..8f96bd4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Package-Variant + - add build_variant method on variable packages, to allow avoiding + importing a generator sub - fix pragmas applied by modules listed in "importing" from leaking out into unexpected scopes diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm index 4aeda2a..2f19c47 100644 --- a/lib/Package/Variant.pm +++ b/lib/Package/Variant.pm @@ -87,7 +87,11 @@ sub import { } *{"${variable}::install"} = sub { goto &{$Variable{$variable}{install}}; - } + }; + *{"${variable}::build_variant"} = sub { + shift; + $me->build_variant_of($variable, @_); + }; } sub build_variant_of { @@ -328,6 +332,16 @@ Exports the generator subroutine under a different name than the default. =back +=head2 build_variant + + use Some::Variant::Package (); + my $variant_package = Some::Variant::Package->build_variant( @arguments ); + +This method is provided for you. It will generate a variant package +and return its name, just like the generator sub provided by +L. This allows you to avoid importing anything into the +consuming package. + =head1 C METHODS These methods are available on C itself. diff --git a/t/01simple.t b/t/01simple.t index 2a060cb..3d3813d 100644 --- a/t/01simple.t +++ b/t/01simple.t @@ -100,6 +100,13 @@ TestSingleImport(23); is_deeply [@imported], [qw( TestImportableA )], 'scalar import works'; +@imported = (); + +TestSingleImport::->build_variant; + +is_deeply [@imported], [qw( TestImportableA )], + 'build_variant works'; + like exception { Package::Variant->import( importing => \'foo', subs => [qw( foo )],