From: Kennedy Clark
Date: Tue, 24 Feb 2009 14:46:48 +0000 (+0000)
Subject: More updates for Chained. Rewrite the discussion about different action types and...
X-Git-Tag: v5.8005~204
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=commitdiff_plain;h=0416017e10f523ec522ef48e0acef28217b57b55
More updates for Chained. Rewrite the discussion about different action types and move it into MoreCatalystBasics.pod.
---
diff --git a/lib/Catalyst/Manual/Tutorial/Authentication.pod b/lib/Catalyst/Manual/Tutorial/Authentication.pod
index d8c4978..54cca78 100644
--- a/lib/Catalyst/Manual/Tutorial/Authentication.pod
+++ b/lib/Catalyst/Manual/Tutorial/Authentication.pod
@@ -392,7 +392,8 @@ definition of C to match:
if ($c->authenticate({ username => $username,
password => $password } )) {
# If successful, then let them use the application
- $c->response->redirect($c->uri_for('/books/list'));
+ $c->response->redirect($c->uri_for(
+ $c->controller('Books')->action_for('list')));
return;
} else {
# Set an error message
@@ -524,69 +525,14 @@ the following method:
return 1;
}
-
-B Catalyst provides a number of different types of actions,
-such as C, C, C, C and C. You
-should refer to L for a more
-detailed explanation, but the following bullet points provide a quick
-introduction:
-
-=over 4
-
-=item *
-
-In the past, the majority of applications have traditionally used
-C actions for items that respond to user requests and
-C actions for those that do not directly respond to user
-input.
-
-=item *
-
-As discussed in Part 4 of the tutorial, newer Catalyst applications
-tend to use the Chained dispatch form of action types because of its
-power and flexibility. See
-L
-and
-L
-for more information on chained actions.
-
-=item *
-
-C actions provide a limited subset of what can be found done
-with Chained actions. You can match on different portions of the URI
-(for example C in C would
-match on the URL C but
-C would match on C). You
-can also specify the number of arguments to match via C much
-like the endpoint of a chain. However, becaused Chained actions offer
-these features and so much more (at the expense of some additional
-complexity), Chained action types are generally recommened.
-
-=item *
-
-There are five types of build-in C actions: C, C,
-C, C, and C.
-
-=item *
-
-With C, C, C, C private actions, only the
-most specific action of each type will be called. For example, if you
-define a C action in your controller it will I a
-C action in your application/root controller -- I the
-action in your controller will be called.
-
-=item *
-
-Unlike the other actions where only a single method is called for each
-request, I auto action along the chain of namespaces will be
-called. Each C action will be called I.
-
-=back
-
-By placing the authentication enforcement code inside the C method
-of C (or C), it will be
-called for I request that is received by the entire application.
+As discussed in
+L,
+every C method from the application/root controller down to the
+most specific controller will be called. By placing the
+authentication enforcement code inside the C method of
+C (or C), it will be
+called for I request that is received by the entire
+application.
=head2 Displaying Content Only to Authenticated Users
@@ -655,7 +601,7 @@ bottom (below the closing tag):
Login
- Create
+ Create
Reload your browser and you should now see a "Login" and "Create" links
@@ -820,7 +766,7 @@ has changed):
$c->flash->{status_msg} = "Book deleted";
# Redirect the user back to the list page
- $c->response->redirect($c->uri_for('/books/list'));
+ $c->response->redirect($c->uri_for($self->action_for('list')));
}
Next, open C and update the TT code to pull from
diff --git a/lib/Catalyst/Manual/Tutorial/Authorization.pod b/lib/Catalyst/Manual/Tutorial/Authorization.pod
index b59facf..0773675 100644
--- a/lib/Catalyst/Manual/Tutorial/Authorization.pod
+++ b/lib/Catalyst/Manual/Tutorial/Authorization.pod
@@ -168,7 +168,7 @@ lines to the bottom of the file:
[% # Can also use $c->user->check_roles() to check authz -%]
[% IF c.check_user_roles('admin') %]
[% # Give admin users a link for 'create' %]
- Admin Create
+ Admin Create
[% END %]
diff --git a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
index d636da4..b6afd45 100644
--- a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
+++ b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
@@ -631,12 +631,31 @@ right side of the table with a C "button" (for simplicity,
links will be used instead of full HTML buttons).
Also notice that we are using a more advanced form of C than
-we have seen before. Here we use C<$c-Econtroller-Eaction_for>
-to automatically generate a URI appropriate for that action while
-inserting the C value into the appropriate place. Now, if
-you ever change C<:PathPart('delete')> in your controller method to
-C<:PathPart('kill')>, then your links will automatically update without
-any changes to your .tt2 template file.
+we have seen before. Here we use C<$c-Econtroller-
+Eaction_for> to automatically generate a URI appropriate for that
+action based on the method we want to link to while inserting the
+C value into the appropriate place. Now, if you ever change
+C<:PathPart('delete')> in your controller method to
+C<:PathPart('kill')>, then your links will automatically update
+without any changes to your .tt2 template file. As long as the name
+of your method does not changed ("delete" here), then your links will
+still be correct. There are a few shortcuts and options when using
+C:
+
+=over 4
+
+=item *
+
+If you are referring to a method in the current controller, you can
+use C<$self-Eaction_for('_method_name_')>.
+
+=item *
+
+If you are referring to a method in a different controller, you need
+to include that as an argument to C, as in
+C<$c-Econtroller('_controller_name_')-Eaction_for('_method_name_')>.
+
+=back
B You should use more than just a simple link with your
applications. Consider using some sort of of confirmation page
@@ -820,7 +839,8 @@ C method to match:
# Set a status message to be displayed at the top of the view
$c->stash->{status_msg} = "Book deleted.";
- # Redirect the user back to the list page
+ # Redirect the user back to the list page. Note the use
+ # of $self->action_for as earlier in this section (BasicCRUD)
$c->response->redirect($c->uri_for($self->action_for('list'));
}
diff --git a/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod b/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
index 3ec9249..b6d944d 100644
--- a/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
+++ b/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
@@ -294,26 +294,89 @@ Context object is automatically passed to all Catalyst components. It
is used to pass information between components and provide access to
Catalyst and plugin functionality.
-B Catalyst actions are regular Perl methods, but they make use
-of Nicholas Clark's C module (that's the "C<: Local>" next
-to the C in the code above) to provide additional
-information to the Catalyst dispatcher logic. Many newer Catalyst
-applications are switching to the use of "Literal" C<:Path> actions
-and C attribute in lieu of C<: Local> and C<: Private>. For
-example, C can be used instead of C (because no path was supplied to C it matches
-the "empty" URL in the namespace of that module... the same thing
-C would do) or C could be
-used instead of the C above (the C argument to
-C would make it match on the URL C under C, the
-namespace of the current module). See "Action Types" in
-L as well as Part 5
-of this tutorial (Authentication) for additional information. Another
-popular but more advanced feature is C actions that allow a
-single URL to "chain together" multiple action method calls, each with
-an appropriate number of arguments (see
-L for
-details).
+Catalyst actions are regular Perl methods, but they make use
+of attributes (the "C<: Local>" next to the "C" in the code
+above) to provide additional information to the Catalyst dispatcher
+logic (note that the space between the colon and the attribute name is
+optional... you will see them written both ways). Over time, the
+recommended style for most Catalyst applications has changed:
+
+=over 4
+
+=item * From "C<:Local>" and "C<:Private>"
+
+=item * To "C<:Path>" and "C<:Args>"
+
+=item * To "C<:Chained>"
+
+=back
+
+Although all three styles work just fine, the newer forms offer more
+advanced capbilities and allow you to be more expressive with the URIs
+that your application uses.
+
+Here is a quick summary of the most commonly used action types:
+C, C, C and C:
+
+=over 4
+
+=item *
+
+B -- In the past, the majority of applications have
+traditionally used C actions for items that respond to user
+requests and C actions for those that do not directly respond
+to user input.
+
+=over 4
+
+There are five types of build-in C actions: C,
+C, C, C, and C.
+
+=item *
+
+With C, C, C, C private actions, only the
+most specific action of each type will be called. For example, if you
+define a C action in your controller it will I a
+C action in your application/root controller -- I the
+action in your controller will be called.
+
+=item *
+
+Unlike the other actions where only a single method is called for each
+request, I auto action along the chain of namespaces will be
+called. Each C action will be called I.
+
+=back
+
+=item *
+
+B -- C actions were the next style of action types to
+become popular and essentially provide a limited subset of what can be
+found done with Chained actions. You can match on different portions
+of the URI (for example C in
+C would match on the URL
+C but C would match
+on C) and it let's you be very specific with
+what arguments each controller method will accept. See
+L for more information and a few
+examples.
+
+=item *
+
+B -- Newer Catalyst applications tend to use the Chained
+dispatch form of action types because of its power and flexibility.
+It allows a series of controller methods to automatically be dispatched
+to service a single user request. See
+L
+and L
+for more information on chained actions.
+
+=back
+
+You should refer to L for
+additional information and for coverage of some lesser-used action
+types not discussed here (C, C and C).
=head1 CATALYST VIEWS