1Sub::Exporter::ForMethoUdsse(r3)Contributed Perl DocumenStuabt:i:oEnxporter::ForMethods(3)
2
3
4

NAME

6       Sub::Exporter::ForMethods - helper routines for using Sub::Exporter to
7       build methods
8

VERSION

10       version 0.100052
11

SYNOPSIS

13       In an exporting library:
14
15         package Method::Builder;
16
17         use Sub::Exporter::ForMethods qw(method_installer);
18
19         use Sub::Exporter -setup => {
20           exports   => [ method => \'_method_generator' ],
21           installer => method_installer,
22         };
23
24         sub _method_generator {
25           my ($self, $name, $arg, $col) = @_;
26           return sub { ... };
27         };
28
29       In an importing library:
30
31         package Vehicle::Autobot;
32         use Method::Builder method => { -as => 'transform' };
33

DESCRIPTION

35       The synopsis section, above, looks almost indistinguishable from any
36       other use of Sub::Exporter, apart from the use of "method_installer".
37       It is nearly indistinguishable in behavior, too.  The only change is
38       that subroutines exported from Method::Builder into named slots in
39       Vehicle::Autobot will be wrapped in a subroutine called
40       "Vehicle::Autobot::transform".  This will insert a named frame into
41       stack traces to aid in debugging.
42
43       More importantly (for the author, anyway), they will not be removed by
44       namespace::autoclean.  This makes the following code work:
45
46         package MyLibrary;
47
48         use Math::Trig qw(tan);         # uses Exporter.pm
49         use String::Truncate qw(trunc); # uses Sub::Exporter's defaults
50
51         use Sub::Exporter::ForMethods qw(method_installer);
52         use Mixin::Linewise { installer => method_installer }, qw(read_file);
53
54         use namespace::autoclean;
55
56         ...
57
58         1;
59
60       After MyLibrary is compiled, "namespace::autoclean" will remove "tan"
61       and "trunc" as foreign contaminants, but will leave "read_file" in
62       place.  It will also remove "method_installer", an added win.
63

EXPORTS

65       Sub::Exporter::ForMethods offers only one routine for export, and it
66       may also be called by its full package name:
67
68   method_installer
69         my $installer = method_installer(\%arg);
70
71       This routine returns an installer suitable for use as the "installer"
72       argument to Sub::Exporter.  It updates the "\@to_export" argument to
73       wrap all code that will be installed by name in a named subroutine,
74       then passes control to the default Sub::Exporter installer.
75
76       The only argument to "method_installer" is an optional hashref which
77       may contain a single entry for "rebless".  If the value for "rebless"
78       is true, when a blessed subroutine is wrapped, the wrapper will be
79       blessed into the same package.
80

AUTHOR

82       Ricardo Signes <rjbs@cpan.org>
83
85       This software is copyright (c) 2015 by Ricardo Signes.
86
87       This is free software; you can redistribute it and/or modify it under
88       the same terms as the Perl 5 programming language system itself.
89
90
91
92perl v5.32.0                      2020-07-28      Sub::Exporter::ForMethods(3)
Impressum