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