Re-phrase parts of the text, respace it all, remove superflous apostophes etc
[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, 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 there could be
8 incompatibility.
9
10 Most issues found with pre-existing components have been easy to solve, and a
11 complete description of behavior changes which may cause compatibility issues,
12 or warnings to be 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 Components which inherit from Moose::Object before Catalyst::Component
20
21 Moose components which say:
22
23     package TestApp::Controller::Example;
24     use Moose;
25     extends qw/Moose::Object Catalyst::Component/;
26
27 to use the constructor provided by Moose, whilst working if you do some hacks
28 with the C< BUILDARGS > method, will not work with Catalyst 5.80 as
29 C<Catalyst::Component> inherits from C<Moose::Object>, and so C< @ISA > fails
30 to linearise.
31
32 The fix for this, is to not inherit directly from C<Moose::Object>
33 yourself. Having components which do not inherit their constructor from
34 C<Catalyst::Component> is B<unsupported>, and has never been recommended,
35 therefore you're on your own if you're using this technique. You'll need
36 to detect the version of Catalyst your application is running with and deal
37 with it appropriately.
38
39 You 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
45 as C< use base > appends to @ISA.
46
47 The correct way to use Moose in a component in a both forward and backwards
48 compatible way is:
49
50     package TestApp::Controller::Root;
51     use Moose;
52     BEGIN { extends 'Catalyst::Component' }; # Or ::Controller, or whatever
53
54 Note that the C< extends > decleration needs to occur in a begin block for
55 L<attributes> to operate correctly.
56
57 =head3 use Moose in MyApp
58
59 Similar 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
68 If you need to use Moose in your application class (e.g. for method modifiers
69 etc) 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
80 If you have any code which installs anonymous subroutine references directly
81 into the symbol table, you may encounter breakages. The simplest solution is
82 to 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
93 Additionally, you can take advantage of Catalysts use of L<Class::MOP> and
94 install 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
102 To execute code during application startup the following snippet in MyApp.pm
103 used 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
111 With Catalyst 5.80 this won't work anymore. Because instead of using NEXT.pm it
112 relies on L<Class::C3::Adopt::NEXT>, which uses plain C3 method resolution.
113
114 As L<NEXTs|NEXT> hacks to remember what methods have already been called, this
115 causes infinite recursion between MyApp::setup and Catalyst::setup.
116
117 Moose method modifiers like C<< before|after|around 'setup => sub { ... }; >>
118 also will not operate correctly due to backward compatibility issues with the
119 way plugin setup methods.
120
121 The 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
129 Previously, if you had a component which inherited from Catalyst::COMPONENT,
130 but overrode the new method to return false, then your class' configuration
131 would be blessed into a hash on your behalf, and this would be returned from
132 the COMPONENT method.
133
134 This behaviour makes no sense, and so has been removed. Implementing your own
135 new method in components is B<highly> discouraged, instead, you should inherit
136 the new method from Catalyst::Component, and use Moose's BUILD functionality
137 to perform any construction work necessary for your sub-class.
138
139 =head2 __PACKAGE__->mk_accessor('meta');
140
141 Won't work due to a limitation of L<Moose>. This is currently being fixed
142 inside Moose.
143
144 =head2 Class::Data::Inheritable side effects
145
146 Previously, writing to a class data accessor would copy the accessor method
147 down into your package.
148
149 This behavior has been removed. Whilst the class data is still stored
150 per-class, it is stored on the metaclass of the class defining the accessor.
151
152 Therefore anything relying on the side-effect of the accessor being copied down
153 will be broken.
154
155 The 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
176 Previously, it was possible to add additional accessors to Catalyst::Request
177 (or other classes) by calling the mk_accessors class method.
178
179 This is no longer supported - users should make a sub-class of the class whos
180 behavior they would like to change, rather than globally polluting the
181 Catalyst objects.
182
183 =head2 Confused multiple inheritance with Catalyst::Component::COMPONENT
184
185 Warning message:
186
187     There is a COMPONENT method resolving after Catalyst::Component
188     in ${next_package}.
189
190 This means that one of the packages on the right hand side of
191 Catalyst::Component in your Class' inheritance hierarchy defines a COMPONENT
192 method.
193
194 Previously, Catalyst's COMPONENT method would delegate to the method on the
195 right hand side, which could then delegate back again with NEXT. This (as it
196 is insane), is no longer supported, as it makes no sense with C3 method
197 dispatch order.
198
199 Therefore the correct fix is to re-arrange your class' inheritance hierarchy
200 so that the COMPONENT method you would like to inherit is the first COMPONENT
201 method in your @ISA.
202
203 =head1 WARNINGS
204
205 =head2 Methods in Catalyst::Dispatcher
206
207 The following methods in Catalyst::Dispatcher are likely to change
208 significantly in the 5.8X release series, and therefore their use is highly
209 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
227 The 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
232 You should B<NEVER> be calling any of these methods from application code.
233
234 Plugins authors and maintainers whos plugins need to call these methods should
235 email the development list to discuss your use-case, and what a better API
236 should look like.
237
238 =head2 require $class was successful but the package is not defined.
239
240 In this version of Catalyst, if a component is loaded from disk, but no
241 symbols are defined in that component's namespace after it is loaded, this
242 warning will be issued.
243
244 This is to protect against confusing bugs caused by mis-typing package names.
245
246 This will become a fatal error in a future version.
247
248 =head2 $c->plugin method
249
250 Calling the plugin method is deprecated, and calling it at runtime is B<highly
251 deprecated>.
252
253 Instead you are recommended to use L< Catalyst::Model::Adaptor > or similar to
254 compose the functionality you need outside of the main application namespace.
255
256 =cut