Create branch register_actions.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Upgrading.pod
CommitLineData
ae29b412 1=head1 Upgrading to Catalyst 5.80
2
3Most applications and plugins should run unaltered on Catalyst 5.80.
4
5However as a lot of refactoring work has taken place, several changes have
6been made which could cause incompatibilities, if your application or plugin
7is using deprecated code, or relying on side-effects then there could be
8incompatibility.
9
10Most issues found with pre-existing components have been easy to solve, and a
11complete description of behavior changes which may cause compatibility issues,
12or warnings to be emitted is included below to help if you have problems.
13
14If you think you have found an upgrade related issue which is not covered in
15this document, then please email the Catalyst list to discuss the problem.
16
17=head1 Known backwards compatibility breakages.
18
19=head2 Components which inherit from Moose::Object before Catalyst::Component
20
21Moose components which say:
22
23 package TestApp::Controller::Example;
24 use Moose;
25 extends qw/Moose::Object Catalyst::Component/;
26
27to use the constructor provided by Moose, whilst working if you do some hacks
28with the C< BUILDARGS > method, will not work with Catalyst 5.80 as
29C<Catalyst::Component> inherits from C<Moose::Object>, and so C< @ISA > fails
30to linearise.
31
32The fix for this, is to not inherit directly from C<Moose::Object>
33yourself. Having components which do not inherit their constructor from
34C<Catalyst::Component> is B<unsupported>, and has never been recommended,
35therefore you're on your own if you're using this technique. You'll need
36to detect the version of Catalyst your application is running with and deal
37with it appropriately.
38
39You will also see this issue if you do the following:
40
41 package TestApp::Controller::Example;
42 use Moose;
43 use base 'Catalyst::Controller';
44
45as C< use base > appends to @ISA.
46
47The correct way to use Moose in a component in a both forward and backwards
48compatible way is:
49
50 package TestApp::Controller::Root;
51 use Moose;
52 BEGIN { extends 'Catalyst::Component' }; # Or ::Controller, or whatever
53
54Note that the C< extends > decleration needs to occur in a begin block for
55L<attributes> to operate correctly.
56
57=head3 use Moose in MyApp
58
59Similar to the above, this will also fail:
60
61 package MyApp;
62 use Moose;
63 use Catalyst qw/
64 ConfigLoader
65 /;
66 __PACKAGE__->setup;
67
68If you need to use Moose in your application class (e.g. for method modifiers
69etc) then the correct technique is:
70
71 package MyApp;
72 use Moose;
73 extends 'Catalyst';
74 __PACKAGE__->setup(qw/
75 ConfigLoader
76 /);
77
78=head2 Anonymous closures installed directly into the symbol table
79
80If you have any code which installs anonymous subroutine references directly
81into the symbol table, you may encounter breakages. The simplest solution is
82to use L<Sub::Name> to name the subroutine. Example:
83
84 # Original code, likely to break:
85 my $full_method_name = join('::',$package_name, $method_name);
86 *$full_method_name = sub { ... };
87
88 # Fixed Code
89 use Sub::Name 'subname';
90 my $full_method_name = join('::',$package_name, $method_name);
91 *$full_method_name = subname $full_method_name, sub { ... };
92
93Additionally, you can take advantage of Catalysts use of L<Class::MOP> and
94install the closure using the appropriate metaclass. Example:
95
96 use Class::MOP;
97 my $metaclass = Moose::Meta::Class->initialize($package_name);
98 $metaclass->add_method($method_name => sub { ... });
99
100=head2 Hooking into application setup
101
102To execute code during application startup the following snippet in MyApp.pm
103used to work:
104
105 sub setup {
106 my ($class, @args) = @_;
107 $class->NEXT::setup(@args);
108 ... # things to do after the actual setup
109 }
110
111With Catalyst 5.80 this won't work anymore. Because instead of using NEXT.pm it
112relies on L<Class::C3::Adopt::NEXT>, which uses plain C3 method resolution.
113
114As L<NEXTs|NEXT> hacks to remember what methods have already been called, this
115causes infinite recursion between MyApp::setup and Catalyst::setup.
116
117Moose method modifiers like C<< before|after|around 'setup => sub { ... }; >>
118also will not operate correctly due to backward compatibility issues with the
119way plugin setup methods.
120
121The right way to do it is this:
122
123 after setup_finalize => sub {
124 ... # things to do after the actual setup
125 };
126
127=head2 Components with a new method which returns false
128
129Previously, if you had a component which inherited from Catalyst::COMPONENT,
130but overrode the new method to return false, then your class' configuration
131would be blessed into a hash on your behalf, and this would be returned from
132the COMPONENT method.
133
134This behaviour makes no sense, and so has been removed. Implementing your own
135new method in components is B<highly> discouraged, instead, you should inherit
136the new method from Catalyst::Component, and use Moose's BUILD functionality
137to perform any construction work necessary for your sub-class.
138
139=head2 __PACKAGE__->mk_accessor('meta');
140
141Won't work due to a limitation of L<Moose>. This is currently being fixed
142inside Moose.
143
144=head2 Class::Data::Inheritable side effects
145
146Previously, writing to a class data accessor would copy the accessor method
147down into your package.
148
149This behavior has been removed. Whilst the class data is still stored
150per-class, it is stored on the metaclass of the class defining the accessor.
151
152Therefore anything relying on the side-effect of the accessor being copied down
153will be broken.
154
155The following example demonstrates the problem:
156
157 {
158 package BaseClass;
159 use base qw/Class::Data::Inheritable/;
160 __PACKAGE__->mk_classdata('foo');
161 }
162
163 {
164 package Child;
165 use base qw/BaseClass/;
166 }
167
168 BaseClass->foo('base class');
169 Child->foo('sub class');
170
171 use Test::More;
172 isnt(BaseClass->can('foo'), Child->can('foo'));
173
174=head2 Extending Catalyst::Request or other classes in an ad-hoc manor using mk_accessors
175
176Previously, it was possible to add additional accessors to Catalyst::Request
177(or other classes) by calling the mk_accessors class method.
178
179This is no longer supported - users should make a sub-class of the class whos
180behavior they would like to change, rather than globally polluting the
181Catalyst objects.
182
183=head2 Confused multiple inheritance with Catalyst::Component::COMPONENT
184
185Warning message:
186
187 There is a COMPONENT method resolving after Catalyst::Component
188 in ${next_package}.
189
190This means that one of the packages on the right hand side of
191Catalyst::Component in your Class' inheritance hierarchy defines a COMPONENT
192method.
193
194Previously, Catalyst's COMPONENT method would delegate to the method on the
195right hand side, which could then delegate back again with NEXT. This (as it
196is insane), is no longer supported, as it makes no sense with C3 method
197dispatch order.
198
199Therefore the correct fix is to re-arrange your class' inheritance hierarchy
200so that the COMPONENT method you would like to inherit is the first COMPONENT
201method in your @ISA.
202
203=head1 WARNINGS
204
205=head2 Methods in Catalyst::Dispatcher
206
207The following methods in Catalyst::Dispatcher are both an implementation detail,
208and also likely to change significantly in the 5.8X release series, and therefore
209their use is highly deprecated.
210
211=over
212
213=item tree
214
215=item dispatch_types
216
217=item registered_dispatch_types
218
219=item method_action_class
220
221=item action_hash
222
223=item container_hash
224
225=back
226
227The first time one of these methods is called, a warning will be emitted:
228
229 Class $class is calling the deprecated method Catalyst::Dispatcher::$public_method_name,\n"
230 . "this will be removed in Catalyst 5.9X"
231
232You should B<NEVER> be calling any of these methods from application code.
233
234Plugins authors and maintainers whos plugins currently call these methods
235should change to using the public API, or, if you do not feel the public API
236adaquately supports your use-case, please email the development list to
237discuss what API features you need so that you can be appropriately supported.
238
239=head2 require $class was successful but the package is not defined.
240
241In this version of Catalyst, if a component is loaded from disk, but no
242symbols are defined in that component's namespace after it is loaded, this
243warning will be issued.
244
245This is to protect against confusing bugs caused by mis-typing package names.
246
247This will become a fatal error in a future version.
248
249=head2 $c->plugin method
250
251Calling the plugin method is deprecated, and calling it at runtime is B<highly
252deprecated>.
253
254Instead you are recommended to use L< Catalyst::Model::Adaptor > or similar to
255compose the functionality you need outside of the main application namespace.
256
257=cut