X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FIntro.pod;h=8e58d7f847219b52151a17f6de6c16686bb8e12d;hb=5b387dfc825bb5a5a78672693497f5d7e792e9d4;hp=d43614abc1a1964ac3784c33b76a4d650cc6c307;hpb=cda8d1ac93da3a50d217e4e4ad5aa96d8d1ab1b2;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Manual/Intro.pod b/lib/Catalyst/Manual/Intro.pod index d43614a..8e58d7f 100644 --- a/lib/Catalyst/Manual/Intro.pod +++ b/lib/Catalyst/Manual/Intro.pod @@ -105,8 +105,8 @@ Here's how to install Catalyst and get a simple application up and running, usin =head3 Setup - $ catalyst.pl My::App - $ cd My-App + $ catalyst.pl MyApp + $ cd MyApp $ script/create.pl controller My::Controller =head3 Run @@ -234,10 +234,10 @@ The last of these, the stash, is a universal hash for sharing data among applica sub hello : Global { my ( $self, $c ) = @_; $c->stash->{message} = 'Hello World!'; - $c->forward('show-message'); + $c->forward('show_message'); } - show-message : Private { + sub show_message : Private { my ( $self, $c ) = @_; $c->res->output( $c->stash->{message} ); } @@ -277,12 +277,12 @@ directly to the application base. =item * B - package MyApp::Controller::My::Controller; + package MyApp::C::My::Controller; sub foo : Local { } Matches http://localhost:3000/my/controller/foo. -This action type indicates that the matching URL must be prefixed with a modified form of the component's class (package) name. This modified class name excludes the parts that have a pre-defined meaning in Catalyst ("MyApp::Controller" in the above example), replaces "::" with "_" and converts the name to lower case. See L for a full explanation of the pre-defined meaning of Catalyst component class names. +This action type indicates that the matching URL must be prefixed with a modified form of the component's class (package) name. This modified class name excludes the parts that have a pre-defined meaning in Catalyst ("MyApp::C" in the above example), replaces "::" with "/" and converts the name to lower case. See L for a full explanation of the pre-defined meaning of Catalyst component class names. =item * B @@ -325,28 +325,54 @@ Called at the end of a request, after all matching actions are called. sub begin : Private { } sub default : Private { } -You can define the Builtin Private Actions within your controllers as well. Default actions will override the ones in lower level controllers/global, while begin/end actions will be chained together, so if you have a default action in MyApp::C::Foo::Bar as well as a global one, and a global begin/end, as well as a begin end in MyApp::C::Foo and MyApp::C::Foo::Bar, the components will be called as follows: +You can define the Builtin Private Actions within your controllers as +well. The actions will override the ones in lower level controllers/ +global. + +In addition to the normal builtins, you have a special action for +making inheritance chains, 'auto'. These will be run after begin, +but before your action is processed. =over 4 =item for a request for /foo/foo MyApp::begin - MyApp::default + MyApp::auto + MyApp::C::Foo::default MyApp::end =item for a request for /foo/bar/foo - MyApp::begin - MyApp::C::Foo::begin MyApp::C::Foo::Bar::begin + MyApp::auto + MyApp::C::Foo::auto MyApp::C::Foo::Bar::default MyApp::C::Foo::Bar::end - MyApp::C::Foo::end - MyApp::end =back +Also, if you need to break out of the chain in one of your auto +actions, you can return 0, if so, your action will not be processed, +but the end will, so for the request above, if the first auto returns +false, it would look like this: + +=over 4 + +=item for a request for /foo/bar/foo where auto returns false + + MyApp::C::Foo::Bar::begin + MyApp::auto + MyApp::C::Foo::Bar::end + +=back + +I auto actions have to return a true value to continue processing! +You can also die in the autochain action, in that case, +the request will go straight to the finalize stage, without processing +further actions. + + =head4 B If you want to pass variable arguments at the end of a URL, you must use regex actions keys with '^' and '$' anchors, and the arguments must be separated with forward slashes (/) in the URL. For example, suppose you want to handle /foo/$bar/$baz, where $bar and $baz may vary: @@ -373,16 +399,16 @@ You control the application flow with the C method, which accepts the k sub hello : Global { my ( $self, $c ) = @_; $c->stash->{message} = 'Hello World!'; - $c->forward('check-message'); + $c->forward('check_message'); } - sub check-message : Private { + sub check_message : Private { my ( $self, $c ) = @_; return unless $c->stash->{message}; - $c->forward('show-message'); + $c->forward('show_message'); } - sub show-message : Private { + sub show_message : Private { my ( $self, $c ) = @_; $c->res->output( $c->stash->{message} ); } @@ -425,7 +451,7 @@ Again, Catalyst has an uncommonly flexible component system. You can define as m All components must inherit from L, which provides a simple class structure and some common class methods like C and C (constructor). - package MyApp::Controller::MyController; + package MyApp::C::MyController; use strict; use base 'Catalyst::Base'; @@ -472,7 +498,7 @@ This gives us a process() method and we can now just do $c->forward('MyApp::V::T sub end : Private { my ( $self, $c ) = @_; - $c->forward('MyApp::View::TT'); + $c->forward('MyApp::V::TT'); } You normally render templates at the end of a request, so it's a perfect use for the global end action.