1Class::C3::Adopt::NEXT(U3s)er Contributed Perl DocumentatCiloanss::C3::Adopt::NEXT(3)
2
3
4

NAME

6       Class::C3::Adopt::NEXT - make NEXT suck less
7

VERSION

9       version 0.14
10

SYNOPSIS

12           package MyApp::Plugin::FooBar;
13           #use NEXT;
14           use Class::C3::Adopt::NEXT;
15           # or 'use Class::C3::Adopt::NEXT -no_warn;' to suppress warnings
16
17           # Or use warnings::register
18           # no warnings 'Class::C3::Adopt::NEXT';
19
20           # Or suppress warnings in a set of modules from one place
21           # no Class::C3::Adopt::NEXT qw/ Module1 Module2 Module3 /;
22           # Or suppress using a regex
23           # no Class::C3::Adopt::NEXT qr/^Module\d$/;
24
25           sub a_method {
26               my ($self) = @_;
27               # Do some stuff
28
29               # Re-dispatch method
30               # Note that this will generate a warning the _first_ time the package
31               # uses NEXT unless you un comment the 'no warnings' line above.
32               $self->NEXT::method();
33           }
34

DESCRIPTION

36       NEXT was a good solution a few years ago, but isn't any more.  It's
37       slow, and the order in which it re-dispatches methods appears random at
38       times. It also encourages bad programming practices, as you end up with
39       code to re-dispatch methods when all you really wanted to do was run
40       some code before or after a method fired.
41
42       However, if you have a large application, then weaning yourself off
43       "NEXT" isn't easy.
44
45       This module is intended as a drop-in replacement for NEXT, supporting
46       the same interface, but using Class::C3 to do the hard work. You can
47       then write new code without "NEXT", and migrate individual source files
48       to use "Class::C3" or method modifiers as appropriate, at whatever pace
49       you're comfortable with.
50

WARNINGS

52       This module will warn once for each package using NEXT. It uses
53       warnings::register, and so can be disabled like by adding "no warnings
54       'Class::C3::Adopt::NEXT';" to each package which generates a warning,
55       or adding "use Class::C3::Adopt::NEXT -no_warn;", or disable multiple
56       modules at once by saying:
57
58           no Class::C3::Adopt::NEXT qw/ Module1 Module2 Module3 /;
59
60       somewhere before the warnings are first triggered. You can also setup
61       entire name spaces of modules which will not warn using a regex, e.g.
62
63           no Class::C3::Adopt::NEXT qr/^Module\d$/;
64

MIGRATING

66   Current code using NEXT
67       You add "use MRO::Compat" to the top of a package as you start
68       converting it, and gradually replace your calls to "NEXT::method()"
69       with "maybe::next::method()", and calls to "NEXT::ACTUAL::method()"
70       with "next::method()".
71
72       Example:
73
74           sub yourmethod {
75               my $self = shift;
76
77               # $self->NEXT::yourmethod(@_); becomes
78               $self->maybe::next::method();
79           }
80
81           sub othermethod {
82               my $self = shift;
83
84               # $self->NEXT::ACTUAL::yourmethodname(); becomes
85               $self->next::method();
86           }
87
88       On systems with Class::C3::XS present, this will automatically be used
89       to speed up method re-dispatch. If you are running perl version 5.9.5
90       or greater then the C3 method resolution algorithm is included in perl.
91       Correct use of MRO::Compat as shown above allows your code to be
92       seamlessly forward and backwards compatible, taking advantage of native
93       versions if available, but falling back to using pure perl "Class::C3".
94
95   Writing new code
96       Use Moose and make all of your plugins Moose::Roles, then use method
97       modifiers to wrap methods.
98
99       Example:
100
101           package MyApp::Role::FooBar;
102           use Moose::Role;
103
104           before 'a_method' => sub {
105               my ($self) = @_;
106               # Do some stuff
107           };
108
109           around 'a_method' => sub {
110               my $orig = shift;
111               my $self = shift;
112               # Do some stuff before
113               my $ret = $self->$orig(@_); # Run wrapped method (or not!)
114               # Do some stuff after
115               return $ret;
116           };
117
118           package MyApp;
119           use Moose;
120
121           with 'MyApp::Role::FooBar';
122

CAVEATS

124       There are some inheritance hierarchies that it is possible to create
125       which cannot be resolved to a simple C3 hierarchy. In that case, this
126       module will fall back to using "NEXT". In this case a warning will be
127       emitted.
128
129       Because calculating the method resolution order of every class every
130       time "->NEXT::foo" is used from within it is too expensive, runtime
131       manipulations of @ISA are prohibited.
132

FUNCTIONS

134       This module replaces "NEXT::AUTOLOAD" with its own version. If warnings
135       are enabled then a warning will be emitted on the first use of "NEXT"
136       by each package.
137

SEE ALSO

139       MRO::Compat and Class::C3 for method re-dispatch and Moose for method
140       modifiers and roles.
141
142       NEXT for documentation on the functionality you'll be removing.
143

AUTHORS

145       ·   Florian Ragwitz <rafl@debian.org>
146
147       ·   Tomas Doran <bobtfish@bobtfish.net>
148

CONTRIBUTOR

150       Karen Etheridge <ether@cpan.org>
151
153       This software is copyright (c) 2015 by Florian Ragwitz.
154
155       This is free software; you can redistribute it and/or modify it under
156       the same terms as the Perl 5 programming language system itself.
157
158
159
160perl v5.32.0                      2020-07-28         Class::C3::Adopt::NEXT(3)
Impressum