From: Robert Sedlacek Date: Mon, 28 Nov 2011 21:23:42 +0000 (+0100) Subject: allow optional renaming of exported generator X-Git-Tag: v1.000000~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FPackage-Variant.git;a=commitdiff_plain;h=0a7db8d2582be4949a5c321ac449ff6c2e1c1e03 allow optional renaming of exported generator --- diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm index 7e0cbe0..b0c2698 100644 --- a/lib/Package/Variant.pm +++ b/lib/Package/Variant.pm @@ -21,8 +21,10 @@ sub import { }; *{"${target}::import"} = sub { my $target = caller; + my (undef, %arg) = @_; + my $as = defined($arg{as}) ? $arg{as} : $last; no strict 'refs'; - *{"${target}::${last}"} = sub { + *{"${target}::${as}"} = sub { $me->build_variant_of($variable, @_); }; }; @@ -176,7 +178,8 @@ your package. use My::Variant; my $new_variant_package = Variant( @variant_arguments ); -The package is now fully initialized and used. +The package is now fully initialized and used. You can import the +subroutine under a different name by specifying an C argument. =head2 Dynamic creation of variant packages @@ -239,6 +242,19 @@ This method is provided for you. It will allow a user to C your package and receive a subroutine taking C<@arguments> defining the variant and returning the name of the newly created variant package. +The following options can be specified when importing: + +=over + +=item * B + + use Some::Variant::Package as => 'Foo'; + my $variant_package = Foo( @arguments ); + +Exports the generator subroutine under a different name than the default. + +=back + =head1 C METHODS These methods are available on C itself.