@@ -514,6 +514,8 @@ sub _parse_Chained_attr {
514514 my @levels = split ' /' , $rel ;
515515
516516 $value = ' /' .join (' /' , @parts [0 .. $#parts - @levels ], $rest );
517+ } elsif ($value =~ / ^\* / ) {
518+ $value = " /$value " ;
517519 } elsif ($value !~ m / ^\/ / ) {
518520 my $action_ns = $self -> action_namespace($c );
519521
@@ -1030,6 +1032,125 @@ like websockets.
10301032
10311033See L<Catalyst::ActionRole::Scheme> for more.
10321034
1035+ =head2 Name
1036+
1037+ Allows you to give you action a globally addressable name, in addition to its private
1038+ name. Useful to decouple action referencing via Chaining and link creation from the
1039+ actions private name, which is tightly bound to the controller namespace as well as the
1040+ action subroutine name. Example:
1041+
1042+ package MyApp::Controller::Root;
1043+
1044+ use warnings;
1045+ use strict;
1046+ use base 'Catalyst::Controller';
1047+
1048+ sub root :Chained(/) PathPart('') CaptureArgs(0) Name(Root) {
1049+ my ($self, $c) = @_;
1050+ }
1051+
1052+ MyApp::Controller::Root->config(namespace=>'');
1053+
1054+ package MyApp::Controller::Home;
1055+
1056+ use warnings;
1057+ use strict;
1058+ use base 'Catalyst::Controller';
1059+
1060+ sub home :Chained(*Root) Args(0) {
1061+ my ($self, $c) = @_;
1062+ }
1063+
1064+ In this case the 'Home' controller's action '/home/home' is chained to the Root controllers action
1065+ '/root'. These declarations are the in practice the same:
1066+
1067+ package MyApp::Controller::Home;
1068+
1069+ use warnings;
1070+ use strict;
1071+ use base 'Catalyst::Controller';
1072+
1073+ # Reference the target prior chain link via its full private action name
1074+ sub home :Chained(/root) Args(0) {
1075+ my ($self, $c) = @_;
1076+ }
1077+
1078+ or:
1079+
1080+ # Reference the target prior chain link via a relative action path
1081+ sub home :Chained(../root) Args(0) {
1082+ my ($self, $c) = @_;
1083+ }
1084+
1085+ When using a named action's name in a :Chained attribute, when using forward/detach/go/visit or
1086+ when using $c->action_for and $controller->action_for you must prefix the name with a '*' so that
1087+ we can disambiguate a named action from an action relative path:
1088+
1089+ package MyApp::Controller::URI;
1090+
1091+ use warnings;
1092+ use strict;
1093+ use base 'Catalyst::Controller';
1094+
1095+ sub target :Path(/target) Args(0) Name (Target) {
1096+ my ($self, $c) = @_;
1097+ }
1098+
1099+ sub uri :Path(/uri) Args(0) {
1100+ my ($self, $c) = @_;
1101+ $c->response->body($c->uri_for( $c->action_for('*Target') ));
1102+ }
1103+
1104+ package MyApp::Controller::Flow;
1105+
1106+ use warnings;
1107+ use strict;
1108+ use base 'Catalyst::Controller';
1109+
1110+ sub test_forward :Path(/forward) Args(0) {
1111+ my ($self, $c) = @_;
1112+ $c->forward('*ForForward');
1113+ }
1114+
1115+ sub forward_target :Action Name(ForForward) {
1116+ my ($self, $c) = @_;
1117+ $c->response->body('forward');
1118+ }
1119+
1120+ sub test_detach :Path(/detach) Args(0) {
1121+ my ($self, $c) = @_;
1122+ $c->detach('*ForDetach');
1123+ }
1124+
1125+ sub detach_target :Action Name(ForDetach) {
1126+ my ($self, $c) = @_;
1127+ $c->response->body('detach');
1128+ }
1129+
1130+ sub test_go :Path(/go) Args(0) {
1131+ my ($self, $c) = @_;
1132+ $c->detach('*ForGo');
1133+ }
1134+
1135+ sub go_target :Action Name(ForGo) {
1136+ my ($self, $c) = @_;
1137+ $c->response->body('go');
1138+ }
1139+
1140+ sub test_visit :Path(/visit) Args(0) {
1141+ my ($self, $c) = @_;
1142+ $c->detach('*ForVisit');
1143+ }
1144+
1145+ sub visit_target :Action Name(ForVisit) {
1146+ my ($self, $c) = @_;
1147+ $c->response->body('visit');
1148+ }
1149+
1150+ B<NOTE > : Named actions are not a replacement for using an actions private name, but are offered
1151+ as an option for when additional clarity or action namespace decoupling improve code understanding
1152+ and maintainability.
1153+
10331154=head1 OPTIONAL METHODS
10341155
10351156=head2 _parse_[$name]_attr
0 commit comments