Fix my retardedness with ::MVC:: warning having no conditional. Pull all the stuff...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Upgrading.pod
CommitLineData
7e2ec16e 1=head1 Upgrading to Catalyst 5.80
2
5687c7f9 3Most applications and plugins should run unaltered on Catalyst 5.80.
7e2ec16e 4
e11cac87 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.
5687c7f9 9
e11cac87 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.
7e2ec16e 13
5687c7f9 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.
7e2ec16e 16
5687c7f9 17=head1 Known backwards compatibility breakages.
7e2ec16e 18
6f04e56a 19=head2 Components which inherit from Moose::Object before Catalyst::Component
7e2ec16e 20
6f04e56a 21Moose components which say:
7e2ec16e 22
6f04e56a 23 package TestApp::Controller::Example;
24 use Moose;
845bfcd2 25 extends qw/Moose::Object Catalyst::Component/;
7e2ec16e 26
6f04e56a 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.
7e2ec16e 38
8566c0de 39You will also see this issue if you do the following:
40
6f04e56a 41 package TestApp::Controller::Example;
42 use Moose;
8566c0de 43 use base 'Catalyst::Controller';
44
45as C< use base > appends to @ISA.
46
6f04e56a 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.
8566c0de 56
e11cac87 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
04a48104 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
e11cac87 84 # Original code, likely to break:
04a48104 85 my $full_method_name = join('::',$package_name, $method_name);
86 *$full_method_name = sub { ... };
87
e11cac87 88 # Fixed Code
04a48104 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
e11cac87 93Additionally, you can take advantage of Catalysts use of L<Class::MOP> and
04a48104 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
780654ad 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
e11cac87 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.
780654ad 116
e11cac87 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.
780654ad 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
e11cac87 127=head2 Components with a new method which returns false
7e2ec16e 128
8dd2f514 129Previously, if you had a component which inherited from Catalyst::COMPONENT,
e11cac87 130but overrode the new method to return false, then your class' configuration
8dd2f514 131would be blessed into a hash on your behalf, and this would be returned from
a87f5aa5 132the COMPONENT method.
7e2ec16e 133
e11cac87 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.
7e2ec16e 138
139=head2 __PACKAGE__->mk_accessor('meta');
140
e11cac87 141Won't work due to a limitation of L<Moose>. This is currently being fixed
142inside Moose.
7e2ec16e 143
144=head2 Class::Data::Inheritable side effects
145
8dd2f514 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.
7e2ec16e 151
8dd2f514 152Therefore anything relying on the side-effect of the accessor being copied down
153will be broken.
7e2ec16e 154
8dd2f514 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');
e11cac87 170
171 use Test::More;
8dd2f514 172 isnt(BaseClass->can('foo'), Child->can('foo'));
7e2ec16e 173
5687c7f9 174=head2 Extending Catalyst::Request or other classes in an ad-hoc manor using mk_accessors
7e2ec16e 175
8dd2f514 176Previously, it was possible to add additional accessors to Catalyst::Request
177(or other classes) by calling the mk_accessors class method.
7e2ec16e 178
e11cac87 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.
8be895a7 182
10011c19 183=head2 Confused multiple inheritance with Catalyst::Component::COMPONENT
8be895a7 184
5687c7f9 185Warning message:
7e2ec16e 186
8dd2f514 187 There is a COMPONENT method resolving after Catalyst::Component
5687c7f9 188 in ${next_package}.
8dd2f514 189
190This means that one of the packages on the right hand side of
e11cac87 191Catalyst::Component in your Class' inheritance hierarchy defines a COMPONENT
192method.
7e2ec16e 193
e11cac87 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.
5687c7f9 198
e11cac87 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.
7e2ec16e 202
c571d2c8 203=head1 WARNINGS
204
205=head2 Methods in Catalyst::Dispatcher
206
8f5a2bd9 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.
c571d2c8 210
211=over
212
8dd2f514 213=item tree
c571d2c8 214
8dd2f514 215=item dispatch_types
c571d2c8 216
8dd2f514 217=item registered_dispatch_types
c571d2c8 218
8dd2f514 219=item method_action_class
c571d2c8 220
8dd2f514 221=item action_hash
c571d2c8 222
223=item container_hash
224
225=back
226
227The first time one of these methods is called, a warning will be emitted:
7e2ec16e 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
c571d2c8 232You should B<NEVER> be calling any of these methods from application code.
233
8f5a2bd9 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.
7e2ec16e 238
5687c7f9 239=head2 require $class was successful but the package is not defined.
7e2ec16e 240
e11cac87 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.
7e2ec16e 244
10011c19 245This is to protect against confusing bugs caused by mis-typing package names.
7e2ec16e 246
5687c7f9 247This will become a fatal error in a future version.
7e2ec16e 248
5687c7f9 249=head2 $c->plugin method
250
8dd2f514 251Calling the plugin method is deprecated, and calling it at runtime is B<highly
252deprecated>.
7e2ec16e 253
8dd2f514 254Instead you are recommended to use L< Catalyst::Model::Adaptor > or similar to
255compose the functionality you need outside of the main application namespace.
7e2ec16e 256
257=cut