Skip to content

Commit

Permalink
docs, dist.ini; ready to release?
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Jun 30, 2009
1 parent d435b93 commit 3a45853
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dist.ini
@@ -0,0 +1,10 @@
name = Sub-Exporter-ForMethods
author = Ricardo Signes <rjbs@cpan.org>
license = Perl_5
copyright_holder = Ricardo Signes

[@RJBS]

[Prereq]
Sub::Name = 0
Sub::Exporter = 0.978 ; installer / generator stuff
70 changes: 70 additions & 0 deletions lib/Sub/Exporter/ForMethods.pm
@@ -1,13 +1,83 @@
use strict; use strict;
use warnings; use warnings;
package Sub::Exporter::ForMethods; package Sub::Exporter::ForMethods;
# ABSTRACT: helper routines for using Sub::Exporter to build methods


use Sub::Name (); use Sub::Name ();


use Sub::Exporter -setup => { use Sub::Exporter -setup => {
exports => [ qw(method_installer) ], exports => [ qw(method_installer) ],
}; };


=head1 SYNOPSIS
In an exporting library:
package Method::Builder;
use Sub::Exporter::ForMethods qw(method_installer);
use Sub::Exporter -setup => {
exports => [ method => \'_method_generator' ],
installer => method_installer,
};
sub _method_generator {
my ($self, $name, $arg, $col) = @_;
return sub { ... };
};
In an importing library:
package Vehicle::Autobot;
use Method::Builder method => { -as => 'transform' };
=head1 DESCRIPTION
The synopsis section, above, looks almost indistinguishable from any other
use of L<Sub::Exporter|Sub::Exporter>, apart from the use of
C<method_installer>. It is nearly indistinguishable in behavior, too. The
only change is that subroutines exported from Method::Builder into named slots
in Vehicle::Autobot will be wrapped in a subroutine called
C<Vehicle::Autobot::transform>. This will insert a named frame into stack
traces to aid in debugging.
More importantly (for the author, anyway), they will not be removed by
L<namespace::autoclean|namespace::autoclean>. This makes the following code
work:
package MyLibrary;
use Math::Trig qw(tan); # uses Exporter.pm
use String::Truncate qw(trunc); # uses Sub::Exporter's defaults
use Sub::Exporter::ForMethods qw(method_installer);
use Mixin::Linewise { installer => method_installer }, qw(read_file);
use namespace::autoclean;
...
1;
After MyLibrary is compiled, C<namespace::autoclean> will remove C<tan> and
C<trunc> as foreign contaminants, but will leave C<read_file> in place. It
will also remove C<method_installer>, an added win.
=head1 EXPORTS
Sub::Exporter::ForMethods offers only one routine for export, and it may also
be called by its full package name:
=head2 method_installer
This routine returns an installer suitable for use as the C<installer> argument
to Sub::Exporter. It updates the C<\@to_export> argument to wrap all code that
will be installed by name in a named subroutine, then passes control to the
default Sub::Exporter installer.
=cut

sub method_installer { sub method_installer {
sub { sub {
my ($arg, $to_export) = @_; my ($arg, $to_export) = @_;
Expand Down

0 comments on commit 3a45853

Please sign in to comment.