Fix Engine::Stomp with psgi
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Upgrading.pod
1 =head1 NAME
2
3 Catalyst::Upgrading - Instructions for upgrading to the latest Catalyst
4
5 =head1 Upgrading to Catalyst 5.90
6
7 The major change is that L<Plack> now replaces most of the subclasses of
8 L<Catalyst::Engine>.  If you are using one of the standard subclasses of
9 L<Catalyst::Engine> this should be a straightforward upgrade for you. It was
10 a design goal for this release to be as backwardly compatible as possible.
11 However since L<Plack> is different from L<Catalyst::Engine> it would be 
12 possible that edge case differences would exist.  Therefore we recommend care
13 be taken with this upgrade and that testing should be greater than would be
14 the case with a minor point update.
15
16 It is highly recommended that you become familar with the L<Plack> ecosystem
17 and documentation.  Being able to take advantage of L<Plack> development and
18 middleware is a major bonus to this upgrade.
19
20 If you have created a custom subclass of L<Catalyst:Engine> you will need to
21 convert it to be a subclass of L<Plack::Handler>.
22
23 If you are using the L<Plack> engine, L<Catalyst::Engine::PSGI>, this new
24 release supercedes that code.
25
26 If you are using a subclass of L<Catalyst::Engine> that is aimed at nonstandard
27 or internal / testing uses, such as L<Catalyst::Engine::Embeddable> you should
28 still be able to continue using that engine.
29
30 Advice for specific subclasses of L<Catalyst::Engine> follows:
31
32 =head2 Upgrading the FastCGI Engine
33
34 No upgrade needed if your myapp_fastcgi.pl script is already upgraded
35 enough to use L<Catalyst::Script::FastCGI>.
36
37 =head2 Upgrading the mod_perl / Apache Engines
38
39 The engines that are build upon the various iterations of mod_perl,
40 L<Catalyst::Engine::Apache::MP13> and
41 L<Catalyst::Engine::Apache2::MP20> should be seemless upgrades and will
42 work using using L<Plack::Handler::Apache1> or L<Plack::Handler::Apache2>
43 as required.  
44
45 L<Catalyst::Engine::Apache2::MP19>, is however no longer supported, as Plack
46 does not support mod_perl version 1.99??? FIXME - is this true?
47
48 =head2 Upgrading the HTTP Engine
49
50 The default development server that comes with the L<Catalyst> distribution
51 should continue to work as expected with no changes as long as your C<myapp_server>
52 script is upgraded to use L<Catalyst::Script::HTTP>.
53
54 =head2 Upgrading the CGI Engine
55
56 If you were using L<Catalyst::Engine::CGI> there is no upgrade needed if your
57 myapp_cgi.pl script is already upgraded enough to use L<Catalyst::Script::CGI>.
58
59 =head2 Upgrading the Preforking Engine
60
61 If you were using L<Catalyst::Engine::HTTP::Prefork> then L<Starman>
62 is automatically loaded. 
63
64 =head2 Upgrading the PSGI Engine
65
66 If you were using L<Catalyst::Engine::PSGI> this new release supercedes this
67 engine in supporting L<Plack>. By default the Engine is now always L<Plack>.
68 As a result, you can stop depending on L<Catalyst::Engine::PSGI> in your
69 C<Makefile.PL>.  Additionally, if you have an C<app.psgi> script you no longer
70 need to specify the PSGI engine.  Instead, the L<Catalyst> application class
71 now has a new method C<psgi_app> which returns a L<Plack> compatible coderef.
72
73 For example, if you were using L<Catalyst::Engine::PSGI> in the past, you may
74 have written an C<app.psgi> file similar to this one:
75
76     use Plack::Builder;
77     use MyCatalytApp;
78
79     MyCatalystApp->setup_engine('PSGI');
80
81     builder {
82         enable ... # enable your desired middleware
83         sub { MyCatalystApp->run(@_) };
84     };
85
86 Instead, you now just do
87
88     use Plack::Builder;
89     use MyCatalystApp;
90
91     builder {
92         enable ... #enable your desired middleware
93         MyCatalystApp->psgi_app;
94     };
95
96 =head2 Engines with unknown status
97
98 The following engines have untested or unknown compatibility.  Reports are
99 highly welcomed:
100
101     Catalyst::Engine::Embeddable
102     Catalyst::Engine::XMPP2
103     Catalyst::Engine::SCGI
104     Catalyst::Engine::Mojo
105     Catalyst::Engine::Zeus
106     Catalyst::Engine::JobQueue::POE
107     Catalyst::Engine::Wx
108     Catalyst::Engine::Stomp
109     Catalyst::Engine::Server (Marked as Deprecated)
110     Catalyst::Engine::HTTP::POE (Marked as Deprecated)
111
112 =head2 Using middleware
113
114 XXX Should this be here or elsewhere?
115
116 =head2 Making an app.psgi file
117
118 =head2 Running with plackup?
119
120 =head1 Upgrading to Catalyst 5.80
121
122 Most applications and plugins should run unaltered on Catalyst 5.80.
123
124 However, a lot of refactoring work has taken place, and several changes have
125 been made which could cause incompatibilities. If your application or plugin
126 is using deprecated code, or relying on side effects, then you could have
127 issues upgrading to this release.
128
129 Most issues found with pre-existing components have been easy to
130 solve. This document provides a complete description of behavior changes
131 which may cause compatibility issues, and of new Catalyst warnings which
132 be unclear.
133
134 If you think you have found an upgrade-related issue which is not covered in
135 this document, please email the Catalyst list to discuss the problem.
136
137 =head1 Moose features
138
139 =head2 Application class roles
140
141 You can only apply method modifiers after the application's C<< ->setup >>
142 method has been called. This means that modifiers will not work with methods
143 which run during the call to C<< ->setup >>.
144
145 See L<Catalyst::Manual::ExtendingCatalyst> for more information about using
146 L<Moose> in your applications.
147
148 =head2 Controller actions in Moose roles
149
150 You can use L<MooseX::MethodAttributes::Role> if you want to declare actions
151 inside Moose roles.
152
153 =head2 Using Moose in Components
154
155 The correct way to use Moose in a component in a both forward and backwards
156 compatible way is:
157
158     package TestApp::Controller::Root;
159     use Moose;
160     BEGIN { extends 'Catalyst::Component' }; # Or ::Controller, or whatever
161
162 See L<Components which inherit from Moose::Object before Catalyst::Component>.
163
164 =head1 Known backwards compatibility breakages
165
166 =head2 Applications in a single file
167
168 Applications must be in their own file, and loaded at compile time. This
169 issue generally only affects the tests of CPAN distributions. Your
170 application will fail if you try to define an application inline in a
171 block, and use plugins which supply a C< new > method, then use that
172 application latter in tests within the same file.
173
174 This is due to the fact that Catalyst is inlining a new method on your
175 application class allowing it to be compatible with Moose. The method
176 used to do this changed in 5.80004 to avoid the possibility of reporting
177 an 'Unknown Error' if your application failed to compile.
178
179 =head2 Issues with Class::C3
180
181 Catalyst 5.80 uses the L<Algorithm::C3> method dispatch order. This is
182 built into Perl 5.10, and comes via L<Class::C3> for Perl 5.8. This
183 replaces L<NEXT> with L<Class::C3::Adopt::NEXT>, forcing all components
184 to resolve methods using C3, rather than the unpredictable dispatch
185 order of L<NEXT>.
186
187 This issue is characterised by your application failing to start due to an
188 error message about having a non-linear @ISA.
189
190 The Catalyst plugin most often causing this is
191 L<Catalyst::Plugin::Session::Store::FastMmap> - if you are using this
192 plugin and see issues, then please upgrade your plugins, as it has been
193 fixed. Note that Makefile.PL in the distribution will warn about known
194 incompatible components.
195
196 This issue can, however, be found in your own application - the only solution is
197 to go through each base class of the class the error was reported against, until
198 you identify the ones in conflict, and resolve them.
199
200 To be able to generate a linear @ISA, the list of superclasses for each
201 class must be resolvable using the C3 algorithm. Unfortunately, when
202 superclasses are being used as mixins (to add functionality used in your class),
203 and with multiple inheritence, it is easy to get this wrong.
204
205 Most common is the case of:
206
207     package Component1; # Note, this is the common case
208     use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
209
210     package Component2; # Accidentally saying it this way causes a failure
211     use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
212
213     package GoesBang;
214     use base qw/Component1 Component2/;
215
216 Any situation like this will cause your application to fail to start.
217
218 For additional documentation about this issue, and how to resolve it, see
219 L<Class::C3::Adopt::NEXT>.
220
221 =head2 Components which inherit from Moose::Object before Catalyst::Component
222
223 Moose components which say:
224
225     package TestApp::Controller::Example;
226     use Moose;
227     extends qw/Moose::Object Catalyst::Component/;
228
229 to use the constructor provided by Moose, while working (if you do some hacks
230 with the C< BUILDARGS > method), will not work with Catalyst 5.80 as
231 C<Catalyst::Component> inherits from C<Moose::Object>, and so C< @ISA > fails
232 to linearize.
233
234 The correct way to use Moose in a component in a both forward and backwards
235 compatible way is:
236
237     package TestApp::Controller::Root;
238     use Moose;
239     BEGIN { extends 'Catalyst::Component' }; # Or ::Controller, or whatever
240
241 Note that the C< extends > declaration needs to occur in a begin block for
242 L<attributes> to operate correctly.
243
244 This way you do not inherit directly from C<Moose::Object>
245 yourself. Having components which do not inherit their constructor from
246 C<Catalyst::Component> is B<unsupported>, and has never been recommended,
247 therefore you're on your own if you're using this technique. You'll need
248 to detect the version of Catalyst your application is running, and deal
249 with it appropriately.
250
251 You also don't get the L<Moose::Object> constructor, and therefore attribute
252 initialization will not work as normally expected. If you want to use Moose
253 attributes, then they need to be made lazy to correctly initialize.
254
255 Note that this only applies if your component needs to maintain component
256 backwards compatibility for Catalyst versions before 5.71001 - in 5.71001
257 attributes work as expected, and the BUILD method is called normally
258 (although BUILDARGS is not).
259
260 If you depend on Catalyst 5.8, then B<all> Moose features work as expected.
261
262 You will also see this issue if you do the following:
263
264     package TestApp::Controller::Example;
265     use Moose;
266     use base 'Catalyst::Controller';
267
268 as C< use base > appends to @ISA.
269
270 =head3 use Moose in MyApp
271
272 Similar to the above, this will also fail:
273
274     package MyApp;
275     use Moose;
276     use Catalyst qw/
277       ConfigLoader
278     /;
279     __PACKAGE__->setup;
280
281 If you need to use Moose in your application class (e.g. for method modifiers
282 etc.) then the correct technique is:
283
284     package MyApp;
285     use Moose;
286     use Catalyst;
287
288     extends 'Catalyst';
289
290     __PACKAGE__->config( name => 'MyApp' );
291     __PACKAGE__->setup(qw/
292         ConfigLoader
293     /);
294
295 =head2 Anonymous closures installed directly into the symbol table
296
297 If you have any code which installs anonymous subroutine references directly
298 into the symbol table, you may encounter breakages. The simplest solution is
299 to use L<Sub::Name> to name the subroutine. Example:
300
301     # Original code, likely to break:
302     my $full_method_name = join('::', $package_name, $method_name);
303     *$full_method_name = sub { ... };
304
305     # Fixed Code
306     use Sub::Name 'subname';
307     my $full_method_name = join('::',$package_name, $method_name);
308     *$full_method_name = subname $full_method_name, sub { ... };
309
310 Additionally, you can take advantage of Catalyst's use of L<Class::MOP> and
311 install the closure using the appropriate metaclass. Example:
312
313     use Class::MOP;
314     my $metaclass = Moose::Meta::Class->initialize($package_name);
315     $metaclass->add_method($method_name => sub { ... });
316
317 =head2 Hooking into application setup
318
319 To execute code during application start-up, the following snippet in MyApp.pm
320 used to work:
321
322     sub setup {
323         my ($class, @args) = @_;
324         $class->NEXT::setup(@args);
325         ... # things to do after the actual setup
326     }
327
328 With Catalyst 5.80 this won't work anymore, because Catalyst no longer
329 uses NEXT.pm for method resolution. The functionality was only ever
330 originally operational as L<NEXT> remembers what methods have already
331 been called, and will not call them again.
332
333 Using this now causes infinite recursion between MyApp::setup and
334 Catalyst::setup, due to other backwards compatibility issues related to how
335 plugin setup works. Moose method modifiers like C<< before|after|around setup
336 => sub { ... }; >> also will not operate correctly on the setup method.
337
338 The right way to do it is this:
339
340     after setup_finalize => sub {
341         ... # things to do after the actual setup
342     };
343
344 The setup_finalize hook was introduced as a way to avoid this issue.
345
346 =head2 Components with a new method which returns false
347
348 Previously, if you had a component which inherited from Catalyst::COMPONENT,
349 but overrode the new method to return false, then your class's configuration
350 would be blessed into a hash on your behalf, and this would be returned from
351 the COMPONENT method.
352
353 This behavior makes no sense, and so has been removed. Implementing your own
354 C< new > method in components is B<highly> discouraged. Instead, you should
355 inherit the new method from Catalyst::Component, and use Moose's BUILD
356 functionality and/or Moose attributes to perform any construction work
357 necessary for your class.
358
359 =head2 __PACKAGE__->mk_accessor('meta');
360
361 Won't work due to a limitation of L<Moose>. This is currently being fixed
362 inside Moose.
363
364 =head2 Class::Data::Inheritable side effects
365
366 Previously, writing to a class data accessor would copy the accessor method
367 down into your package.
368
369 This behavior has been removed. While the class data is still stored
370 per-class, it is stored on the metaclass of the class defining the accessor.
371
372 Therefore anything relying on the side effect of the accessor being copied down
373 will be broken.
374
375 The following test demonstrates the problem:
376
377     {
378         package BaseClass;
379         use base qw/Class::Data::Inheritable/;
380         __PACKAGE__->mk_classdata('foo');
381     }
382
383     {
384         package Child;
385         use base qw/BaseClass/;
386     }
387
388     BaseClass->foo('base class');
389     Child->foo('sub class');
390
391     use Test::More;
392     isnt(BaseClass->can('foo'), Child->can('foo'));
393
394 =head2 Extending Catalyst::Request or other classes in an ad-hoc manner using mk_accessors
395
396 Previously, it was possible to add additional accessors to Catalyst::Request
397 (or other classes) by calling the mk_accessors class method.
398
399 This is no longer supported - users should make a subclass of the class whose
400 behavior they would like to change, rather than globally polluting the
401 Catalyst objects.
402
403 =head2 Confused multiple inheritance with Catalyst::Component::COMPONENT
404
405 Previously, Catalyst's COMPONENT method would delegate to the method on
406 the right hand side, which could then delegate back again with
407 NEXT. This is poor practice, and in addition, makes no sense with C3
408 method dispatch order, and is therefore no longer supported.
409
410 If a COMPONENT method is detected in the inheritance hierarchy to the right
411 hand side of Catalyst::Component::COMPONENT, then the following warning
412 message will be emitted:
413
414     There is a COMPONENT method resolving after Catalyst::Component
415     in ${next_package}.
416
417 The correct fix is to re-arrange your class's inheritance hierarchy so that the
418 COMPONENT method you would like to inherit is the first (left-hand most)
419 COMPONENT method in your @ISA.
420
421 =head1 WARNINGS
422
423 =head2 Actions in your application class
424
425 Having actions in your application class will now emit a warning at application
426 startup as this is deprecated. It is highly recommended that these actions are moved
427 into a MyApp::Controller::Root (as demonstrated by the scaffold application
428 generated by catalyst.pl). 
429
430 This warning, also affects tests. You should move actions in your test,
431 creating a myTest::Controller::Root, like the following example:
432
433     package MyTest::Controller::Root;
434
435     use strict;
436     use warnings;
437
438     use parent 'Catalyst::Controller';
439
440     __PACKAGE__->config(namespace => '');
441
442     sub action : Local {
443         my ( $self, $c ) = @_;
444         $c->do_something; 
445     }
446
447     1;
448
449 =head2 ::[MVC]:: naming scheme
450
451 Having packages called MyApp::[MVC]::XX is deprecated and can no longer be generated
452 by catalyst.pl
453
454 This is still supported, but it is recommended that you rename your application
455 components to Model/View/Controller.
456
457 A warning will be issued at application startup if the ::[MVC]:: naming scheme is
458 in use.
459
460 =head2 Catalyst::Base
461
462 Any code using L<Catalyst::Base> will now emit a warning; this
463 module will be removed in a future release.
464
465 =head2 Methods in Catalyst::Dispatcher
466
467 The following methods in Catalyst::Dispatcher are implementation
468 details, which may change in the 5.8X release series, and therefore their use
469 is highly deprecated.
470
471 =over
472
473 =item tree
474
475 =item dispatch_types
476
477 =item registered_dispatch_types
478
479 =item method_action_class
480
481 =item action_hash
482
483 =item container_hash
484
485 =back
486
487 The first time one of these methods is called, a warning will be emitted:
488
489     Class $class is calling the deprecated method Catalyst::Dispatcher::$public_method_name,
490     this will be removed in Catalyst 5.9X
491
492 You should B<NEVER> be calling any of these methods from application code.
493
494 Plugin authors and maintainers whose plugins currently call these methods
495 should change to using the public API, or, if you do not feel the public API
496 adequately supports your use case, please email the development list to
497 discuss what API features you need so that you can be appropriately supported.
498
499 =head2 Class files with names that don't correspond to the packages they define
500
501 In this version of Catalyst, if a component is loaded from disk, but no
502 symbols are defined in that component's name space after it is loaded, this
503 warning will be issued:
504
505     require $class was successful but the package is not defined.
506
507 This is to protect against confusing bugs caused by mistyping package names,
508 and will become a fatal error in a future version.
509
510 Please note that 'inner packages' (via L<Devel::InnerPackage>) are still fully
511 supported; this warning is only issued when component file naming does not map
512 to B<any> of the packages defined within that component.
513
514 =head2 $c->plugin method
515
516 Calling the plugin method is deprecated, and calling it at run time is B<highly
517 deprecated>.
518
519 Instead you are recommended to use L<Catalyst::Model::Adaptor> or similar to
520 compose the functionality you need outside of the main application name space.
521
522 Calling the plugin method will not be supported past Catalyst 5.81.
523
524 =cut
525