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.100054
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

PERL VERSION SUPPORT

65       This module has a long-term perl support period.  That means it will
66       not require a version of perl released fewer than five years ago.
67
68       Although it may work on older versions of perl, no guarantee is made
69       that the minimum required version will not be increased.  The version
70       may be increased for any reason, and there is no promise that patches
71       will be accepted to lower the minimum required perl.
72

EXPORTS

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

AUTHOR

91       Ricardo Signes <rjbs@cpan.org>
92

CONTRIBUTOR

94       Ricardo Signes <rjbs@semiotic.systems>
95
97       This software is copyright (c) 2021 by Ricardo Signes.
98
99       This is free software; you can redistribute it and/or modify it under
100       the same terms as the Perl 5 programming language system itself.
101
102
103
104perl v5.34.0                      2022-01-21      Sub::Exporter::ForMethods(3)
Impressum