Sub::Exporter::Util - utilities to make Sub::Exporter easier
version 0.022
$Id$
This module provides a number of utility functions for performing common or useful operations when setting up a Sub::Exporter configuration. All of the utilites may be exported, but none are by default.
exports => { some_method => curry_class, }
This utility returns a generator which will produce a class-curried version of a method. In other words, it will export a method call with the exporting class built in as the invocant.
A module importing the code some the above example might do this:
use Some::Module qw(some_method); my $x = some_method;
This would be equivalent to:
use Some::Module; my $x = Some::Module->some_method;
If Some::Module is subclassed and the subclass's import method is called to import some_method, the subclass will be curried in as the invocant.
some_method
If an argument is provided for curry_class it is used as the name of the curried method to export. This means you could export a Widget constructor like this:
curry_class
exports => { widget => curry_class('new') }
exports => { merge_col(defaults => { twiddle => \&_twiddle_gen, tweak => \&_tweak_gen, }), }
This utility wraps the given generator in one that will merge the named collection into its args before calling it. This means that you can support a "default" collector in multipe exports without writing the code each time.
use Sub::Exporter -setup => { exporter => Sub::Exporter::Util::mixin_exporter, 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.
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.
Prerequisites: This utility requires that Package::Generator be installed.
It's a collector that adds imports for anything like given regex.
If you provide this configuration:
exports => [ qw(igrep imap islurp exhausted) ], collectors => { -like => Sub::Exporter::Util::like },
A user may import from your module like this:
use Your::Iterator -like => qr/^i/; # imports igre, imap, islurp
or
use Your::Iterator -like => [ qr/^i/ => { -prefix => 'your_' } ];
The group-like prefix and suffix arguments are respected; other arguments are passed on to the generators for matching exports.
Ricardo SIGNES, <rjbs@cpan.org>
<rjbs@cpan.org>
Please report any bugs or feature requests to bug-sub-exporter@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-sub-exporter@rt.cpan.org
Copyright 2006 Ricardo SIGNES. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Sub::Exporter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Exporter
CPAN shell
perl -MCPAN -e shell install Sub::Exporter
For more information on module installation, please visit the detailed CPAN module installation guide.