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