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