3 Catalyst::Upgrading - Instructions for upgrading to the latest Catalyst
5 =head1 Upgrading to Catalyst 5.80
7 Most applications and plugins should run unaltered on Catalyst 5.80.
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
12 issues upgrading to this release.
14 Most issues found with pre-existing components have been easy to solve, and a
15 complete description of behaviour changes which may cause compatibility issues,
16 or warnings which are now emitted is included below to help if you have problems.
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.
23 =head2 Application class roles.
25 You can only apply method modifiers after the applications C<< ->setup >>
26 method has been called. This means that modifiers will not work with methods
27 which run during the call to C<< ->setup >>.
29 See L<Catalyst::Manual::ExtendingCatalyst> for more information about using
30 L<Moose> in your applications.
32 =head2 Controller actions in Moose roles
34 Currently having actions declared in Roles is unsupported.
36 =head1 Known backwards compatibility breakages.
38 =head2 Applications in a single file.
40 Applications must be in their own file, and loaded at compile time. This
41 issue generally only affects the tests of cpan distributions. Defining an
42 application inline in a block, and using plugins which supply a C< new >
43 method, then using that application latter in tests, within the same file
44 will cause your application to fail.
46 This is due to the fact that Catalyst is inlining a new method on your
47 application class allowing it to be compatible with Moose. The method used
48 to do this changed in 5.80004 to avoid the possibility of reporting
49 'Unknown Error' if your application failed to compile.
51 =head2 Issues with Class::C3
53 Catalyst 5.80 uses L<Algorithm::C3> method dispatch order. This is built into
54 perl 5.10, and comes via L<Class::C3> for perl 5.8. This replaces L<NEXT>
55 with L<Class::C3::Adopt::NEXT>, forcing all components to resolve methods using
56 C3, rather than the unpredictable dispatch order of L<NEXT>.
58 This issue is characterised by your application failing to start due to an
59 error message about having a non-linear @ISA.
61 The Catalyst plugin most often causing this, is
62 L<Catalyst::Plugin::Session::Store::FastMmap> - if you are using this plugin
63 and see issues, then please upgrade - and please try upgrading your plugins
64 if you have this issue, as it has been fixed. Note that Makefile.PL in the
65 distribution will warn about known incompatible components.
67 This issue can, however, be found in your own application - the only solution is
68 to go through each base class of the class the error was reported against, until
69 you identify the ones in conflict, and resolve them.
71 To be able to generate a linear @ISA, the list of superclasses for each
72 class must be resolvable using the C3 algorithm. Unfortunately, when
73 superclasses are being used as mixins (to add functionality used in your class),
74 and with multiple inheritence, it is easy to get this wrong.
76 Most common is the case of:
78 package Component1; # Note, this is the common case
79 use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
81 package Component2; # Accidentally saying it this way round causes fail.
82 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
85 use base qw/Component1 Component2/;
87 Any situation like this will cause your application to fail to start.
89 Please see additional documentation about this issue, and how to resolve it in
90 L<Class::C3::Adopt::NEXT>.
92 =head2 Components which inherit from Moose::Object before Catalyst::Component
94 Moose components which say:
96 package TestApp::Controller::Example;
98 extends qw/Moose::Object Catalyst::Component/;
100 to use the constructor provided by Moose, whilst working (if you do some hacks
101 with the C< BUILDARGS > method), will not work with Catalyst 5.80 as
102 C<Catalyst::Component> inherits from C<Moose::Object>, and so C< @ISA > fails
105 The fix for this is to not inherit directly from C<Moose::Object>
106 yourself. Having components which do not inherit their constructor from
107 C<Catalyst::Component> is B<unsupported>, and has never been recommended,
108 therefore you're on your own if you're using this technique. You'll need
109 to detect the version of Catalyst your application is running with and deal
110 with it appropriately.
112 You will also see this issue if you do the following:
114 package TestApp::Controller::Example;
116 use base 'Catalyst::Controller';
118 as C< use base > appends to @ISA.
120 The correct way to use Moose in a component in a both forward and backwards
123 package TestApp::Controller::Root;
125 BEGIN { extends 'Catalyst::Component' }; # Or ::Controller, or whatever
127 Note that the C< extends > declaration needs to occur in a begin block for
128 L<attributes> to operate correctly.
130 You also don't get the L<Moose::Object> constructor, and therefore attribute
131 initialization will not work as normally expected. If you want to use Moose
132 attributes, then they need to be made lazy to correctly initialize.
134 Note that this only applies if your component needs to maintain component
135 backwards compatibility for Catalyst versions before 5.71001 - in 5.71001
136 attributes work as expected, and the BUILD method is called normally
137 (although BUILDARGS is not).
139 If you depend on Catalyst 5.8, then B<all> Moose features work as expected.
141 =head3 use Moose in MyApp
143 Similar to the above, this will also fail:
152 If you need to use Moose in your application class (e.g. for method modifiers
153 etc) then the correct technique is:
161 __PACKAGE__->config( name => 'MyApp' );
162 __PACKAGE__->setup(qw/
166 =head2 Anonymous closures installed directly into the symbol table
168 If you have any code which installs anonymous subroutine references directly
169 into the symbol table, you may encounter breakages. The simplest solution is
170 to use L<Sub::Name> to name the subroutine. Example:
172 # Original code, likely to break:
173 my $full_method_name = join('::', $package_name, $method_name);
174 *$full_method_name = sub { ... };
177 use Sub::Name 'subname';
178 my $full_method_name = join('::',$package_name, $method_name);
179 *$full_method_name = subname $full_method_name, sub { ... };
181 Additionally, you can take advantage of Catalysts use of L<Class::MOP> and
182 install the closure using the appropriate meta class. Example:
185 my $metaclass = Moose::Meta::Class->initialize($package_name);
186 $metaclass->add_method($method_name => sub { ... });
188 =head2 Hooking into application setup
190 To execute code during application start-up the following snippet in MyApp.pm
194 my ($class, @args) = @_;
195 $class->NEXT::setup(@args);
196 ... # things to do after the actual setup
199 With Catalyst 5.80 this won't work anymore. Due to the fact that Catalyst is
200 no longer using NEXT.pm for method resolution, this no longer works. The
201 functionality was only ever originally operational as L<NEXT> remembers what
202 methods have already been called, and will not call them again.
204 Using this now causes infinite recursion between MyApp::setup and
205 Catalyst::setup, due to other backwards compatibility issues related to how
206 plugin setup works. Moose method modifiers like C<< before|after|around 'setup
207 => sub { ... }; >> also will not operate correctly on the setup method.
209 The right way to do it is this:
211 after setup_finalize => sub {
212 ... # things to do after the actual setup
215 The setup_finalize hook was introduced as a way to avoid this issue.
217 =head2 Components with a new method which returns false
219 Previously, if you had a component which inherited from Catalyst::COMPONENT,
220 but overrode the new method to return false, then your class' configuration
221 would be blessed into a hash on your behalf, and this would be returned from
222 the COMPONENT method.
224 This behaviour makes no sense, and so has been removed. Implementing your own
225 C< new > method in components is B<highly> discouraged, instead, you should
226 inherit the new method from Catalyst::Component, and use Mooses BUILD
227 functionality and/or Moose attributes to perform any construction work
228 necessary for your class.
230 =head2 __PACKAGE__->mk_accessor('meta');
232 Won't work due to a limitation of L<Moose>. This is currently being fixed
235 =head2 Class::Data::Inheritable side effects
237 Previously, writing to a class data accessor would copy the accessor method
238 down into your package.
240 This behaviour has been removed. Whilst the class data is still stored
241 per-class, it is stored on the metaclass of the class defining the accessor.
243 Therefore anything relying on the side-effect of the accessor being copied down
246 The following test demonstrates the problem:
250 use base qw/Class::Data::Inheritable/;
251 __PACKAGE__->mk_classdata('foo');
256 use base qw/BaseClass/;
259 BaseClass->foo('base class');
260 Child->foo('sub class');
263 isnt(BaseClass->can('foo'), Child->can('foo'));
265 =head2 Extending Catalyst::Request or other classes in an ad-hoc manor using mk_accessors
267 Previously, it was possible to add additional accessors to Catalyst::Request
268 (or other classes) by calling the mk_accessors class method.
270 This is no longer supported - users should make a sub-class of the class whose
271 behaviour they would like to change, rather than globally polluting the
274 =head2 Confused multiple inheritance with Catalyst::Component::COMPONENT
276 Previously, Catalyst's COMPONENT method would delegate to the method on the
277 right hand side, which could then delegate back again with NEXT. This (as it
278 is insane AND makes no sense with C3 method dispatch order), and is therefore
281 If a COMPONENT method is detected in the inheritance hierarchy to the right
282 hand side of Catalyst::Component::COMPONENT, then the following warning
283 message will be emitted:
285 There is a COMPONENT method resolving after Catalyst::Component
288 The correct fix is to re-arrange your class' inheritance hierarchy so that the
289 COMPONENT method you would like to inherit is the first (left-hand most)
290 COMPONENT method in your @ISA.
294 =head2 Catalyst::Base
296 Any code using L<Catalyst::Base> will now warn, and this module will be removed
299 =head2 Methods in Catalyst::Dispatcher
301 The following methods in Catalyst::Dispatcher are both an implementation
302 detail, which may change in the 5.8X release series, and therefore their use
303 is highly deprecated.
311 =item registered_dispatch_types
313 =item method_action_class
321 The first time one of these methods is called, a warning will be emitted:
323 Class $class is calling the deprecated method Catalyst::Dispatcher::$public_method_name,
324 this will be removed in Catalyst 5.9X
326 You should B<NEVER> be calling any of these methods from application code.
328 Plugins authors and maintainers whose plugins currently call these methods
329 should change to using the public API, or, if you do not feel the public API
330 adequately supports your use-case, please email the development list to
331 discuss what API features you need so that you can be appropriately supported.
333 =head2 Class files with names that don't correspond to the packages they define
335 In this version of Catalyst, if a component is loaded from disk, but no
336 symbols are defined in that component's name space after it is loaded, this
337 warning will be issued:
339 require $class was successful but the package is not defined.
341 This is to protect against confusing bugs caused by mis-typing package names,
342 and will become a fatal error in a future version.
344 Please note that 'inner packages' (via L<Devel::InnerPackage>) are still fully
345 supported, this warning is only issued when component file naming does not map
346 to B<any> of the packages defined within that component.
348 =head2 $c->plugin method
350 Calling the plugin method is deprecated, and calling it at run time is B<highly
353 Instead you are recommended to use L< Catalyst::Model::Adaptor > or similar to
354 compose the functionality you need outside of the main application name space.
356 Calling the plugin method will not be supported past Catalyst 5.81.