r10040 - in /branches/upstream/libsub-exporter-perl/current: ./ inc/Module/ inc/Module/Install/ lib/Sub/ lib/Sub/Exporter/ t/ t/lib/Test/SubExporter/
gregoa-guest at users.alioth.debian.org
gregoa-guest at users.alioth.debian.org
Fri Nov 30 15:47:23 UTC 2007
Author: gregoa-guest
Date: Fri Nov 30 15:47:23 2007
New Revision: 10040
URL: http://svn.debian.org/wsvn/?sc=1&rev=10040
Log:
[svn-upgrade] Integrating new upstream version, libsub-exporter-perl (0.978)
Modified:
branches/upstream/libsub-exporter-perl/current/Changes
branches/upstream/libsub-exporter-perl/current/META.yml
branches/upstream/libsub-exporter-perl/current/inc/Module/Install.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Base.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Can.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Fetch.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Makefile.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Metadata.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Win32.pm
branches/upstream/libsub-exporter-perl/current/inc/Module/Install/WriteAll.pm
branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter.pm
branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Cookbook.pod
branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Util.pm
branches/upstream/libsub-exporter-perl/current/t/faux-export.t
branches/upstream/libsub-exporter-perl/current/t/lib/Test/SubExporter/Faux.pm
branches/upstream/libsub-exporter-perl/current/t/pod-coverage.t
branches/upstream/libsub-exporter-perl/current/t/util-like.t
branches/upstream/libsub-exporter-perl/current/t/util-mixin.t
Modified: branches/upstream/libsub-exporter-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/Changes?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/Changes (original)
+++ branches/upstream/libsub-exporter-perl/current/Changes Fri Nov 30 15:47:23 2007
@@ -1,98 +1,106 @@
Revision history for Sub-Exporter
-0.976 2007-08-30
- fixed merge_col, which was not updated to work with \name generators
- collector hooks can now alter @_ to replace the value to be collected
- clarify args passed to generator in Tutorial; thanks MARKSTOS
+0.978 2007-11-19
+ improve documentation of new installer/generator options
+ deprecate calling "installer" the "exporter"
+ WARNING: "exporter" OPTION WILL BE REMOVED AFTER 2008-06-01
+ major refactoring of the core generation/installation code
+ tentative interface documentation for replacing it!
- added commented-out name_map to Sub::Exporter::Util; future feature?
+0.976 2007-08-30
+ fixed merge_col, which was not updated to work with \name generators
+ collector hooks can now alter @_ to replace the value to be collected
+ clarify args passed to generator in Tutorial; thanks MARKSTOS
-0.975 2007-07-04
- update Tutorial to show (preferred) \'name' style for generators
- changed "standard" name of curry_class to curry_method
- added curry_chain
- added Sub::Exporter::Cookbook
+ added commented-out name_map to Sub::Exporter::Util; future feature?
-0.974 2007-04-22
- fix a bug that didn't mind trying to export a routine that didn't exist
- in the exporting package; this caused Sub::Install to give the
- unhelpful message "argument 'code' is not optional"
+0.975 2007-07-04
+ update Tutorial to show (preferred) \'name' style for generators
+ changed "standard" name of curry_class to curry_method
+ added curry_chain
+ added Sub::Exporter::Cookbook
-0.973 2007-02-02
- document changes made in 0.972
- minor code changes for readability
+0.974 2007-04-22
+ fix a bug: would try to export routines that didn't exist
+ in the exporting package; this caused Sub::Install to give the
+ unhelpful message "argument 'code' is not optional"
-0.972 2006-12-05
- allow exporter config to provide name (via string ref) of generator for
- groups and exports
- similarly allow a string ref for a method name for a collector hook
- remove some pointless conditions
+0.973 2007-02-02
+ document changes made in 0.972
+ minor code changes for readability
-0.971 2006-11-06
- minor documentation clarification
- add Perl::Critic tests (disabled by default)
+0.972 2006-12-05
+ allow exporter config to provide name (via string ref) of generator
+ for groups and exports
+ similarly allow a string ref for a method name for a collector hook
+ remove some pointless conditions
-0.970 2006-06-27
- defaults populate before collectors collect, now
- default group's value is undef by default, not 1
- mixin_exporter can now export into objects, creating virtual classes
-
-0.966 2006-06-17
- correct documentation of collector hook args
- simplify internal use of setup_exporter
- clean up documentation in ::Util
+0.971 2006-11-06
+ minor documentation clarification
+ add Perl::Critic tests (disabled by default)
-0.965 2006-06-05
- curry_class now allows the export to curry a differently-named method
+0.970 2006-06-27
+ defaults populate before collectors collect, now
+ default group's value is undef by default, not 1
+ mixin_exporter can now export into objects, creating virtual classes
+
+0.966 2006-06-17
+ correct documentation of collector hook args
+ simplify internal use of setup_exporter
+ clean up documentation in ::Util
-0.961 2006-06-05
- Data::OptList is now in its own dist; updated to use it
+0.965 2006-06-05
+ curry_class now allows the export to curry a differently-named method
-0.960 2006-05-31
- added into and into_config to config
- 100% test coverage... almost!
- fix bug that prevented validation of opt lists with must_be=class
+0.961 2006-06-05
+ Data::OptList is now in its own dist; updated to use it
-0.954 2006-05-11
- tweaks to Data::OptList, moving toward its own dist: now it exports
- expand_opt_list is now opt_list_as_hash
+0.960 2006-05-31
+ added into and into_config to config
+ 100% test coverage... almost!
+ fix bug that prevented validation of opt lists with must_be=class
-0.953 2006-05-10
- require Params::Util for craftier opt list validation
- use reinstall, rather than install, to avoid warnings on redef
+0.954 2006-05-11
+ tweaks to Data::OptList, moving toward its own dist: now it exports
+ expand_opt_list is now opt_list_as_hash
-0.952 2006-04-30
- add missing file to manifest
+0.953 2006-05-10
+ require Params::Util for craftier opt list validation
+ use reinstall, rather than install, to avoid warnings on redef
-0.951 2006-04-30
- fix util-mixin.t to skip if prereqs are missing
- various changes to improve blessed/weird generators
- (thanks to Yuval Kogman for pointing problems out)
+0.952 2006-04-30
+ add missing file to manifest
-0.95 2006-04-26
- break out Data::OptList for future disting
- remove an "optimization" that broke expand_opt_list
- improve detection of group generators
- improve data passed to hooks (if you relied on the guts, you'll break)
- the ::Util module
+0.951 2006-04-30
+ fix util-mixin.t to skip if prereqs are missing
+ various changes to improve blessed/weird generators
+ (thanks to Yuval Kogman for pointing problems out)
-0.93 2006-03-26
- internal refactoring
- add more arguments to collector hook calls
+0.95 2006-04-26
+ break out Data::OptList for future disting
+ remove an "optimization" that broke expand_opt_list
+ improve detection of group generators
+ improve data passed to hooks (if you relied on the guts, you'll break)
+ the ::Util module
-0.92 2006-03-16
- FIX BUG in nested imports: when importing groups A and B, and group B
- includes group A, the nested group would be ignored, even though it was
- not recursing
+0.93 2006-03-26
+ internal refactoring
+ add more arguments to collector hook calls
- allow 'into_level' parameter to setup_exporter
- rewrite collection collector to be more efficient
- rewrite opt list handlers to be more efficient
- restate some code to improve clarity and coverage (now 100%)
- better diagnostic messages
+0.92 2006-03-16
+ FIX BUG in nested imports: when importing groups A and B, and group B
+ includes group A, the nested group would be ignored, even though it
+ was not recursing
-0.91 2006-03-16
- added "import elsewhere" option to generated exporter (thanks chansen!)
+ allow 'into_level' parameter to setup_exporter
+ rewrite collection collector to be more efficient
+ rewrite opt list handlers to be more efficient
+ restate some code to improve clarity and coverage (now 100%)
+ better diagnostic messages
-0.90 2006-03-11
- first public release
+0.91 2006-03-16
+ added "import elsewhere" option to generated exporter (thanks
+ chansen!)
+
+0.90 2006-03-11
+ first public release
Modified: branches/upstream/libsub-exporter-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/META.yml?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/META.yml (original)
+++ branches/upstream/libsub-exporter-perl/current/META.yml Fri Nov 30 15:47:23 2007
@@ -1,7 +1,8 @@
---
-author: Ricardo SIGNES <rjbs at cpan.org>
+author:
+ - Ricardo SIGNES <rjbs at cpan.org>
distribution_type: module
-generated_by: Module::Install version 0.67
+generated_by: Module::Install version 0.68
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html
@@ -15,4 +16,4 @@
Data::OptList: 0.1
Params::Util: 0.14
Sub::Install: 0.92
-version: 0.976
+version: 0.978
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install.pm Fri Nov 30 15:47:23 2007
@@ -28,7 +28,7 @@
# This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
- $VERSION = '0.67';
+ $VERSION = '0.68';
}
# Whether or not inc::Module::Install is actually loaded, the
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Base.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Base.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Base.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Base.pm Fri Nov 30 15:47:23 2007
@@ -1,7 +1,7 @@
#line 1
package Module::Install::Base;
-$VERSION = '0.67';
+$VERSION = '0.68';
# Suspend handler for "redefined" warnings
BEGIN {
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Can.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Can.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Can.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Can.pm Fri Nov 30 15:47:23 2007
@@ -11,7 +11,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Fetch.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Fetch.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Fetch.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Fetch.pm Fri Nov 30 15:47:23 2007
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Makefile.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Makefile.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Makefile.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Makefile.pm Fri Nov 30 15:47:23 2007
@@ -7,7 +7,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Metadata.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Metadata.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Metadata.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Metadata.pm Fri Nov 30 15:47:23 2007
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Win32.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Win32.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Win32.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/Win32.pm Fri Nov 30 15:47:23 2007
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libsub-exporter-perl/current/inc/Module/Install/WriteAll.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/inc/Module/Install/WriteAll.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/inc/Module/Install/WriteAll.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/inc/Module/Install/WriteAll.pm Fri Nov 30 15:47:23 2007
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.67';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter.pm Fri Nov 30 15:47:23 2007
@@ -14,11 +14,11 @@
=head1 VERSION
-version 0.976
+version 0.978
=cut
-our $VERSION = '0.976';
+our $VERSION = '0.978';
=head1 SYNOPSIS
@@ -176,8 +176,28 @@
groups - a list of groups to provide for exporting; each must be followed by
either (a) a list of exports, possibly with arguments for each
export, or (b) a generator
+
collectors - a list of names into which values are collected for use in
routine generation; each name may be followed by a validator
+
+In addition to the basic options above, a few more advanced options may be
+passed:
+
+ into_level - how far up the caller stack to look for a target (default 0)
+ into - an explicit target (package) into which to export routines
+
+In other words: Sub::Exporter installs a C<import> routine which, when called,
+exports routines to the calling namespace. The C<into> and C<into_level>
+options change where those exported routines are installed.
+
+ generator - a callback used to produce the code that will be installed
+ default: Sub::Exporter::default_generator
+
+ installer - a callback used to install the code produced by the generator
+ default: Sub::Exporter::default_installer
+
+For information on how these callbacks are used, see the documentation for
+C<L</default_generator>> and C<L</default_installer>>.
=head2 Export Configuration
@@ -363,11 +383,13 @@
These options are:
- into_level - how far up the caller stack to look for a target (default 0)
- into - an explicit target (package) into which to export routines
-
-Providing both C<into_level> and C<into> will cause an exception to be
-thrown.
+ into_level
+ into
+ generator
+ installer
+
+These override the same-named configuration options described in L</EXPORTER
+CONFIGURATION>.
=cut
@@ -550,9 +572,6 @@
=cut
-# \%special is for experimental options that may or may not be kept around and,
-# probably, moved to \%config. These are also passed along to build_exporter.
-
sub setup_exporter {
my ($config) = @_;
@@ -599,7 +618,8 @@
BEGIN {
%valid_config_key =
map { $_ => 1 }
- qw(collectors exporter exports groups into into_level)
+ qw(collectors installer generator exports groups into into_level),
+ qw(exporter), # deprecated
}
sub _rewrite_build_config {
@@ -607,6 +627,15 @@
if (my @keys = grep { not exists $valid_config_key{$_} } keys %$config) {
Carp::croak "unknown options (@keys) passed to Sub::Exporter";
+ }
+
+ Carp::croak q(into and into_level may not both be supplied to exporter)
+ if exists $config->{into} and exists $config->{into_level};
+
+ # XXX: Remove after deprecation period.
+ if ($config->{exporter}) {
+ Carp::cluck "'exporter' argument to build_exporter is deprecated. Use 'installer' instead; the semantics are identical.";
+ $config->{installer} = delete $config->{exporter};
}
Carp::croak q(into and into_level may not both be supplied to exporter)
@@ -640,6 +669,9 @@
# by default, build an all-inclusive 'all' group
$config->{groups}{all} ||= [ keys %{ $config->{exports} } ];
+
+ $config->{generator} ||= \&default_generator;
+ $config->{installer} ||= \&default_installer;
}
sub build_exporter {
@@ -654,6 +686,11 @@
my $special = (ref $_[0]) ? shift(@_) : {};
Carp::croak q(into and into_level may not both be supplied to exporter)
if exists $special->{into} and exists $special->{into_level};
+
+ if ($special->{exporter}) {
+ Carp::cluck "'exporter' special import argument is deprecated. Use 'installer' instead; the semantics are identical.";
+ $special->{installer} = delete $special->{exporter};
+ }
my $into
= defined $special->{into} ? delete $special->{into}
@@ -662,9 +699,8 @@
: defined $config->{into_level} ? caller($config->{into_level})
: caller(0);
- my $export = delete $special->{exporter}
- || $config->{exporter}
- || \&default_exporter;
+ my $generator = delete $special->{generator} || $config->{generator};
+ my $installer = delete $special->{installer} || $config->{installer};
# this builds a AOA, where the inner arrays are [ name => value_ref ]
my $import_args = Data::OptList::mkopt([ @_ ]);
@@ -677,61 +713,67 @@
my $to_import = _expand_groups($class, $config, $import_args, $collection);
# now, finally $import_arg is really the "to do" list
- for (@$to_import) {
- _do_import($class, @$_, $collection, $config, $into, $export);
+ _do_import(
+ {
+ class => $class,
+ col => $collection,
+ config => $config,
+ into => $into,
+ generator => $generator,
+ installer => $installer,
+ },
+ $to_import,
+ );
+ };
+
+ return $import;
+}
+
+sub _do_import {
+ my ($arg, $to_import) = @_;
+
+ my @todo;
+
+ for my $pair (@$to_import) {
+ my ($name, $import_arg) = @$pair;
+
+ my ($generator, $as);
+
+ if ($import_arg and Params::Util::_CODELIKE($import_arg)) { ## no critic
+ # This is the case when a group generator has inserted name/code pairs.
+ $generator = sub { $import_arg };
+ $as = $name;
+ } else {
+ $import_arg = { $import_arg ? %$import_arg : () };
+
+ Carp::croak qq("$name" is not exported by the $arg->{class} module)
+ unless exists $arg->{config}{exports}{$name};
+
+ $generator = $arg->{config}{exports}{$name};
+
+ $as = exists $import_arg->{-as} ? (delete $import_arg->{-as}) : $name;
}
- };
-
- return $import;
-}
-
-sub _do_import {
- my ($class, $name, $arg, $collection, $config, $into, $export) = @_;
-
- my ($generator, $as);
-
- if ($arg and Params::Util::_CODELIKE($arg)) { ## no critic
- # This is the case when a group generator has inserted name/code pairs.
- $generator = sub { $arg };
- $as = $name;
- } else {
- $arg = { $arg ? %$arg : () };
-
- Carp::croak qq("$name" is not exported by the $class module)
- unless (exists $config->{exports}{$name});
-
- $generator = $config->{exports}{$name};
-
- $as = exists $arg->{-as} ? (delete $arg->{-as}) : $name;
- }
-
- $export->($class, $generator, $name, $arg, $collection, $as, $into);
-}
-
-# XXX: Consider implementing a _export_args routine that takes the arguments to
-# _export and returns a hash of named params. This lets other people write
-# exporters without tying me down to one set of @_ contents. Maybe that's
-# premature guarantee, though, unless I guarantee that @_ will never get
-# /smaller/.
-
-=head2 default_exporter
-
-This is Sub::Exporter's default exporter. It does what Sub::Exporter promises:
-it calls generators with the three normal arguments, then installs the code
-into the target package.
-
-B<Warning!> Its interface isn't really stable yet, so don't rely on it. It's
-only named here so that you can pass it in to the exporter builder. It will
-have a stable interface in the future so that it may be more easily replaced.
-
-=cut
-
-sub default_exporter {
- my ($class, $generator, $name, $arg, $collection, $as, $into) = @_;
- _install(
- _generate($class, $generator, $name, $arg, $collection),
- $into,
- $as,
+
+ my $code = $arg->{generator}->(
+ {
+ class => $arg->{class},
+ name => $name,
+ arg => $import_arg,
+ col => $arg->{col},
+ generator => $generator,
+ }
+ );
+
+ push @todo, $as, $code;
+ }
+
+ $arg->{installer}->(
+ {
+ class => $arg->{class},
+ into => $arg->{into},
+ col => $arg->{col},
+ },
+ \@todo,
);
}
@@ -750,8 +792,28 @@
# }
# }
-sub _generate {
- my ($class, $generator, $name, $arg, $collection) = @_;
+=head2 default_generator
+
+This is Sub::Exporter's default generator. It takes bits of configuration that
+have been gathered during the import and turns them into a coderef that can be
+installed.
+
+ my $code = default_generator(\%arg);
+
+Passed arguments are:
+
+ class - the class on which the import method was called
+ name - the name of the export being generated
+ arg - the arguments to the generator
+ col - the collections
+
+ generator - the generator to be used to build the export (code or scalar ref)
+
+=cut
+
+sub default_generator {
+ my ($arg) = @_;
+ my ($class, $name, $generator) = @$arg{qw(class name generator)};
if (not defined $generator) {
my $code = $class->can($name)
@@ -762,26 +824,58 @@
# I considered making this "$class->$generator(" but it seems that
# overloading precedence would turn an overloaded-as-code generator object
# into a string before code. -- rjbs, 2006-06-11
- return $generator->($class, $name, $arg, $collection)
+ return $generator->($class, $name, $arg->{arg}, $arg->{col})
if Params::Util::_CODELIKE($generator); ## no critic Private
# This "must" be a scalar reference, to a generator method name.
# -- rjbs, 2006-12-05
- return $class->$$generator($name, $arg, $collection);
-}
-
-sub _install {
- my ($code, $into, $as) = @_;
- # Allow as isa ARRAY to push onto an array?
- # Allow into isa HASH to install name=>code into hash?
-
- if (ref $as eq 'SCALAR') {
- $$as = $code;
- } elsif (ref $as) {
- Carp::croak "invalid reference type for $as: " . ref $as;
- } else {
- Sub::Install::reinstall_sub({ code => $code, into => $into, as => $as });
- }
+ return $class->$$generator($name, $arg->{arg}, $arg->{col});
+}
+
+=head2 default_installer
+
+This is Sub::Exporter's default installer. It does what Sub::Exporter
+promises: it installs code into the target package.
+
+ default_installer(\%arg, \@to_export);
+
+Passed arguments are:
+
+ into - the package into which exports should be delivered
+
+C<@to_export> is a list of name/value pairs. The default exporter assigns code
+(the values) to named slots (the names) in the given package. If the name is a
+scalar reference, the scalar reference is made to point to the code reference
+instead.
+
+=cut
+
+sub default_installer {
+ my ($arg, $to_export) = @_;
+
+ for (my $i = 0; $i < @$to_export; $i += 2) {
+ my ($as, $code) = @$to_export[ $i, $i+1 ];
+
+ # Allow as isa ARRAY to push onto an array?
+ # Allow into isa HASH to install name=>code into hash?
+
+ if (ref $as eq 'SCALAR') {
+ $$as = $code;
+ } elsif (ref $as) {
+ Carp::croak "invalid reference type for $as: " . ref $as;
+ } else {
+ Sub::Install::reinstall_sub({
+ code => $code,
+ into => $arg->{into},
+ as => $as
+ });
+ }
+ }
+}
+
+sub default_exporter {
+ Carp::cluck "default_exporter is deprecated; call default_installer instead; the semantics are identical";
+ goto &default_installer;
}
=head1 EXPORTS
Modified: branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Cookbook.pod
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Cookbook.pod?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Cookbook.pod (original)
+++ branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Cookbook.pod Fri Nov 30 15:47:23 2007
@@ -12,7 +12,7 @@
applications that may not be immediately obvious, or that can demonstrate how
certain features can be put to use (for good or evil).
-=head1 THE RECIPIES
+=head1 THE RECIPES
=head2 Exporting Methods as Routines
Modified: branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Util.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Util.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Util.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/lib/Sub/Exporter/Util.pm Fri Nov 30 15:47:23 2007
@@ -12,13 +12,11 @@
=head1 VERSION
-version 0.976
-
- $Id$
-
-=cut
-
-our $VERSION = '0.976';
+version 0.978
+
+=cut
+
+our $VERSION = '0.978';
=head1 DESCRIPTION
@@ -226,15 +224,15 @@
return %merged;
}
-=head2 mixin_exporter
+=head2 mixin_installer
use Sub::Exporter -setup => {
- exporter => Sub::Exporter::Util::mixin_exporter,
- exports => [ qw(foo bar baz) ],
+ installer => Sub::Exporter::Util::mixin_installer,
+ exports => [ qw(foo bar baz) ],
};
-This utility returns an exporter that will export into a superclass and adjust
-the ISA importing class to include the newly generated superclass.
+This utility returns an installer that will install into a superclass and
+adjust the ISA importing class to include the newly generated superclass.
If the target of importing is an object, the hierarchy is reversed: the new
class will be ISA the object's class, and the object will be reblessed.
@@ -260,24 +258,23 @@
return $mixin_class;
}
-sub mixin_exporter {
- # These are NOT arguments to mixin_exporter, that's why there is no = @_.
- # They are variables created to enclose in each generated exporter coderef.
- my ($mixin_class, $col_ref);
-
+sub mixin_installer {
sub {
- my ($class, $generator, $name, $arg, $collection, $as, $into) = @_;
-
- unless ($mixin_class and ($collection == $col_ref)) {
- $mixin_class = __mixin_class_for($class, $into);
- bless $into => $mixin_class if ref $into;
- $col_ref = 0 + $collection;
- }
-
- Sub::Exporter::default_exporter(
- $class, $generator, $name, $arg, $collection, $as, $mixin_class
+ my ($arg, $to_export) = @_;
+
+ my $mixin_class = __mixin_class_for($arg->{class}, $arg->{into});
+ bless $arg->{into} => $mixin_class if ref $arg->{into};
+
+ Sub::Exporter::default_installer(
+ { %$arg, into => $mixin_class },
+ $to_export,
);
};
+}
+
+sub mixin_exporter {
+ Carp::cluck "mixin_exporter is deprecated; use mixin_installer instead; it behaves identically";
+ return mixin_installer;
}
=head2 like
@@ -339,7 +336,7 @@
merge_col
curry_method curry_class
curry_chain
- mixin_exporter
+ mixin_installer mixin_exporter
) ]
};
Modified: branches/upstream/libsub-exporter-perl/current/t/faux-export.t
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/t/faux-export.t?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/t/faux-export.t (original)
+++ branches/upstream/libsub-exporter-perl/current/t/faux-export.t Fri Nov 30 15:47:23 2007
@@ -4,8 +4,8 @@
=head1 TEST PURPOSE
-These tests check the output of build_exporter when handed an alternate
-exporter that returns its plan.
+These tests check the output of build_installer when handed an alternate
+installer that returns its plan.
=cut
@@ -35,10 +35,10 @@
};
{
- my ($reset, $export, $exports) = faux_exporter;
+ my ($generator, $installer, $reset, $exports) = faux_installer;
my $code = sub {
$reset->();
- splice @_, 1, 0, { exporter => $export };
+ splice @_, 1, 0, { generator => $generator, installer => $installer };
Sub::Exporter::build_exporter($config)->(@_);
};
@@ -86,10 +86,10 @@
}
{
- my ($reset, $export, $exports) = faux_exporter;
+ my ($generator, $installer, $reset, $exports) = faux_installer;
my $code = sub {
$reset->();
- splice @_, 1, 0, { exporter => $export };
+ splice @_, 1, 0, { generator => $generator, installer => $installer };
Sub::Exporter::build_exporter({ exports => [ 'foo' ] })->(@_);
};
@@ -110,9 +110,13 @@
{
package Test::SubExport::FAUX;
- my ($reset, $export, $exports) = main::faux_exporter;
+ my ($generator, $installer, $reset, $exports) = main::faux_installer;
- Sub::Exporter::setup_exporter({ exports => [ 'X' ], exporter => $export });
+ Sub::Exporter::setup_exporter({
+ exports => [ 'X' ],
+ installer => $installer,
+ generator => $generator,
+ });
__PACKAGE__->import(':all');
main::exports_ok($exports, [ [ X => {} ] ], "setup (not built) exporter");
Modified: branches/upstream/libsub-exporter-perl/current/t/lib/Test/SubExporter/Faux.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/t/lib/Test/SubExporter/Faux.pm?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/t/lib/Test/SubExporter/Faux.pm (original)
+++ branches/upstream/libsub-exporter-perl/current/t/lib/Test/SubExporter/Faux.pm Fri Nov 30 15:47:23 2007
@@ -5,9 +5,9 @@
use base qw(Exporter);
-our @EXPORT = qw(faux_exporter exports_ok everything_ok);
+our @EXPORT = qw(faux_installer exports_ok everything_ok);
-sub faux_exporter {
+sub faux_installer {
my ($verbose) = @_;
$verbose = 1;
@@ -15,21 +15,38 @@
my $reset = sub { @exported = () };
- my $export = sub {
- my ($class, $generator, $name, $arg, $collection, $as, $into) = @_;
- my $everything = {
- class => $class,
- generator => $generator,
- name => $name,
- arg => $arg,
- collection => $collection,
- as => $as,
- into => $into,
- };
- push @exported, [ $name, ($verbose ? $everything : $arg) ];
+ my $generator = sub {
+ my ($arg) = @_;
+ # my ($class, $name, $generator) = @$arg{qw(class name generator)};
+
+ return $arg;
};
- return ($reset, $export, \@exported);
+ my $installer = sub {
+ my ($arg, $to_export) = @_;
+
+ for (my $i = 0; $i < @$to_export; $i += 2) {
+ my ($as, $gen_arg) = @$to_export[ $i, $i+1 ];
+
+ # my ($class, $generator, $name, $arg, $collection, $as, $into) = @_;
+ my $everything = {
+ class => $gen_arg->{class},
+ generator => $gen_arg->{generator},
+ name => $gen_arg->{name},
+ arg => $gen_arg->{arg},
+ collection => $gen_arg->{col},
+ as => $as,
+ into => $arg->{into},
+ };
+
+ push @exported, [
+ $gen_arg->{name},
+ ($verbose ? $everything : $gen_arg->{arg}),
+ ];
+ }
+ };
+
+ return ($generator, $installer, $reset, \@exported);
}
sub exports_ok {
Modified: branches/upstream/libsub-exporter-perl/current/t/pod-coverage.t
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/t/pod-coverage.t?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/t/pod-coverage.t (original)
+++ branches/upstream/libsub-exporter-perl/current/t/pod-coverage.t Fri Nov 30 15:47:23 2007
@@ -17,5 +17,11 @@
}
all_pod_coverage_ok({
- trustme => [ 'curry_class' ],
+ trustme => [
+ # Sub::Exporter
+ qw(default_exporter),
+
+ # Sub::Exporter::Util
+ qw(curry_class mixin_exporter),
+ ],
});
Modified: branches/upstream/libsub-exporter-perl/current/t/util-like.t
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/t/util-like.t?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/t/util-like.t (original)
+++ branches/upstream/libsub-exporter-perl/current/t/util-like.t Fri Nov 30 15:47:23 2007
@@ -8,8 +8,8 @@
use lib 't/lib';
use Test::SubExporter::Faux;
-my ($reset, $export, $exports);
-BEGIN { ($reset, $export, $exports) = faux_exporter; }
+my ($generator, $installer, $reset, $exports);
+BEGIN { ($generator, $installer, $reset, $exports) = faux_installer; }
my %generator;
BEGIN {
@@ -23,12 +23,13 @@
}
BEGIN {
- isa_ok($export, 'CODE');
+ isa_ok($installer, 'CODE');
package Thing;
BEGIN { main::use_ok('Sub::Exporter::Util', 'like'); }
use Sub::Exporter -setup => {
- exporter => $export,
+ installer => $installer,
+ generator => $generator,
collectors => {
-like => like
},
Modified: branches/upstream/libsub-exporter-perl/current/t/util-mixin.t
URL: http://svn.debian.org/wsvn/branches/upstream/libsub-exporter-perl/current/t/util-mixin.t?rev=10040&op=diff
==============================================================================
--- branches/upstream/libsub-exporter-perl/current/t/util-mixin.t (original)
+++ branches/upstream/libsub-exporter-perl/current/t/util-mixin.t Fri Nov 30 15:47:23 2007
@@ -29,9 +29,9 @@
BEGIN {
package Thing::Mixin;
- BEGIN { main::use_ok("Sub::Exporter::Util", 'mixin_exporter'); }
+ BEGIN { main::use_ok("Sub::Exporter::Util", 'mixin_installer'); }
use Sub::Exporter -setup => {
- exporter => mixin_exporter,
+ installer => mixin_installer,
exports => {
bar => sub { sub { 1 } },
foo => sub {
@@ -46,7 +46,7 @@
BEGIN {
Thing->import(
- { exporter => Sub::Exporter::Util::mixin_exporter },
+ { installer => Sub::Exporter::Util::mixin_installer },
-all => { arg => '0' },
);
}
@@ -55,7 +55,7 @@
BEGIN {
Thing->import(
- { exporter => Sub::Exporter::Util::mixin_exporter },
+ { installer => Sub::Exporter::Util::mixin_installer },
-all => { arg => '1' },
);
}
More information about the Pkg-perl-cvs-commits
mailing list