1 package Catalyst::Controller;
5 use Class::Load ':all';
6 use String::RewritePrefix;
7 use Moose::Util qw/find_meta/;
8 use List::Util qw/first/;
9 use List::MoreUtils qw/uniq/;
10 use namespace::clean -except => 'meta';
13 extends qw/Catalyst::Component/;
14 with qw/MooseX::MethodAttributes::Role::AttrContainer::Inheritable/;
17 use MooseX::MethodAttributes;
18 use Catalyst::Exception;
21 with 'Catalyst::Component::ApplicationAttribute';
27 predicate => 'has_path_prefix',
30 has action_namespace => (
33 init_arg => 'namespace',
34 predicate => 'has_action_namespace',
38 accessor => '_controller_actions',
43 has _action_role_args => (
44 traits => [qw(Array)],
45 isa => 'ArrayRef[Str]',
46 init_arg => 'action_roles',
47 default => sub { [] },
49 _action_role_args => 'elements',
53 has _action_roles => (
54 traits => [qw(Array)],
55 isa => 'ArrayRef[RoleName]',
58 builder => '_build__action_roles',
60 _action_roles => 'elements',
64 has action_args => (is => 'ro');
66 # ->config(actions => { '*' => ...
67 has _all_actions_attributes => (
72 builder => '_build__all_actions_attributes',
76 my ($self, $args) = @_;
77 my $action = delete $args->{action} || {};
78 my $actions = delete $args->{actions} || {};
79 my $attr_value = $self->merge_config_hashes($actions, $action);
80 $self->_controller_actions($attr_value);
82 # trigger lazy builder
83 $self->_all_actions_attributes;
87 sub _build__action_roles {
89 my @roles = $self->_expand_role_shortname($self->_action_role_args);
90 load_class($_) for @roles;
94 sub _build__all_actions_attributes {
96 delete $self->_controller_actions->{'*'} || {};
101 Catalyst::Controller - Catalyst Controller base class
105 package MyApp::Controller::Search
106 use base qw/Catalyst::Controller/;
109 my ($self,$c,@args) = @_;
111 } # Dispatches to /search/foo
115 Controllers are where the actions in the Catalyst framework
116 reside. Each action is represented by a function with an attribute to
117 identify what kind of action it is. See the L<Catalyst::Dispatcher>
118 for more info about how Catalyst dispatches to actions.
122 #I think both of these could be attributes. doesn't really seem like they need
123 #to be class data. i think that attributes +default would work just fine
124 __PACKAGE__->mk_classdata($_) for qw/_dispatch_steps _action_class _action_role_prefix/;
126 __PACKAGE__->_dispatch_steps( [qw/_BEGIN _AUTO _ACTION/] );
127 __PACKAGE__->_action_class('Catalyst::Action');
128 __PACKAGE__->_action_role_prefix([ 'Catalyst::ActionRole::' ]);
131 sub _DISPATCH : Private {
132 my ( $self, $c ) = @_;
134 foreach my $disp ( @{ $self->_dispatch_steps } ) {
135 last unless $c->forward($disp);
141 sub _BEGIN : Private {
142 my ( $self, $c ) = @_;
143 my $begin = ( $c->get_actions( 'begin', $c->namespace ) )[-1];
144 return 1 unless $begin;
145 $begin->dispatch( $c );
146 return !@{ $c->error };
149 sub _AUTO : Private {
150 my ( $self, $c ) = @_;
151 my @auto = $c->get_actions( 'auto', $c->namespace );
152 foreach my $auto (@auto) {
153 $auto->dispatch( $c );
154 return 0 unless $c->state;
159 sub _ACTION : Private {
160 my ( $self, $c ) = @_;
162 && $c->action->can('execute')
163 && defined $c->req->action )
165 $c->action->dispatch( $c );
167 return !@{ $c->error };
171 my ( $self, $c ) = @_;
172 my $end = ( $c->get_actions( 'end', $c->namespace ) )[-1];
173 return 1 unless $end;
174 $end->dispatch( $c );
175 return !@{ $c->error };
179 my ( $self, $name ) = @_;
180 my $app = ($self->isa('Catalyst') ? $self : $self->_application);
181 return $app->dispatcher->get_action($name, $self->action_namespace);
184 #my opinion is that this whole sub really should be a builder method, not
185 #something that happens on every call. Anyone else disagree?? -- groditi
186 ## -- apparently this is all just waiting for app/ctx split
187 around action_namespace => sub {
189 my ( $self, $c ) = @_;
191 my $class = ref($self) || $self;
192 my $appclass = ref($c) || $c;
194 return $self->$orig if $self->has_action_namespace;
196 return $class->config->{namespace} if exists $class->config->{namespace};
201 $case_s = $appclass->config->{case_sensitive};
203 if ($self->isa('Catalyst')) {
204 $case_s = $class->config->{case_sensitive};
207 $case_s = ref($self->_application)->config->{case_sensitive};
209 confess("Can't figure out case_sensitive setting");
214 my $namespace = Catalyst::Utils::class2prefix($self->catalyst_component_name, $case_s) || '';
215 $self->$orig($namespace) if ref($self);
219 #Once again, this is probably better written as a builder method
220 around path_prefix => sub {
224 return $self->$orig if $self->has_path_prefix;
226 return $self->config->{path} if exists $self->config->{path};
228 my $namespace = $self->action_namespace(@_);
229 $self->$orig($namespace) if ref($self);
233 sub get_action_methods {
235 my $meta = find_meta($self) || confess("No metaclass setup for $self");
237 sprintf "Metaclass %s for %s cannot support register_actions.",
238 ref $meta, $meta->name,
239 ) unless $meta->can('get_nearest_methods_with_attributes');
240 my @methods = $meta->get_nearest_methods_with_attributes;
242 # actions specified via config are also action_methods
246 $meta->find_method_by_name($_)
247 || confess( sprintf 'Action "%s" is not available from controller %s',
249 } keys %{ $self->_controller_actions }
251 return uniq @methods;
255 sub register_actions {
256 my ( $self, $c ) = @_;
257 $self->register_action_methods( $c, $self->get_action_methods );
260 sub register_action_methods {
261 my ( $self, $c, @methods ) = @_;
262 my $class = $self->catalyst_component_name;
263 #this is still not correct for some reason.
264 my $namespace = $self->action_namespace($c);
267 if (!blessed($self) && $self eq $c && scalar(@methods)) {
268 my @really_bad_methods = grep { ! /^_(DISPATCH|BEGIN|AUTO|ACTION|END)$/ } map { $_->name } @methods;
269 if (scalar(@really_bad_methods)) {
270 $c->log->warn("Action methods (" . join(', ', @really_bad_methods) . ") found defined in your application class, $self. This is deprecated, please move them into a Root controller.");
274 foreach my $method (@methods) {
275 my $name = $method->name;
276 # Horrible hack! All method metaclasses should have an attributes
277 # method, core Moose bug - see r13354.
278 my $attributes = $method->can('attributes') ? $method->attributes : [];
279 my $attrs = $self->_parse_attrs( $c, $name, @{ $attributes } );
280 if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
281 $c->log->warn( 'Bad action definition "'
282 . join( ' ', @{ $attributes } )
283 . qq/" for "$class->$name"/ )
287 my $reverse = $namespace ? "${namespace}/${name}" : $name;
288 my $action = $self->create_action(
290 code => $method->body,
292 namespace => $namespace,
294 attributes => $attrs,
297 $c->dispatcher->register( $c, $action );
301 sub _apply_action_class_roles {
302 my ($self, $class, @roles) = @_;
304 load_class($_) for @roles;
305 my $meta = Moose::Meta::Class->initialize($class)->create_anon_class(
306 superclasses => [$class],
310 $meta->add_method(meta => sub { $meta });
319 my $class = (exists $args{attributes}{ActionClass}
320 ? $args{attributes}{ActionClass}[0]
321 : $self->_action_class);
331 my $class = $self->action_class(%args);
334 Moose->init_meta(for_class => $class)
335 unless Class::MOP::does_metaclass_exist($class);
337 unless ($args{name} =~ /^_(DISPATCH|BEGIN|AUTO|ACTION|END)$/) {
338 my @roles = $self->gather_action_roles(%args);
339 push @roles, $self->gather_default_action_roles(%args);
341 $class = $self->_apply_action_class_roles($class, @roles) if @roles;
347 : $self->config->{action_args}
351 %{ $action_args->{'*'} || {} },
352 %{ $action_args->{ $args{name} } || {} },
355 return $class->new({ %extra_args, %args });
358 sub gather_action_roles {
359 my ($self, %args) = @_;
361 (blessed $self ? $self->_action_roles : ()),
362 @{ $args{attributes}->{Does} || [] },
366 sub gather_default_action_roles {
367 my ($self, %args) = @_;
369 push @roles, 'Catalyst::ActionRole::HTTPMethods'
370 if $args{attributes}->{Method};
372 push @roles, 'Catalyst::ActionRole::ConsumesContent'
373 if $args{attributes}->{Consumes};
375 push @roles, 'Catalyst::ActionRole::Scheme'
376 if $args{attributes}->{Scheme};
381 my ( $self, $c, $name, @attrs ) = @_;
385 foreach my $attr (@attrs) {
387 # Parse out :Foo(bar) into Foo => bar etc (and arrayify)
389 if ( my ( $key, $value ) = ( $attr =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/ ) )
392 if ( defined $value ) {
393 ( $value =~ s/^'(.*)'$/$1/ ) || ( $value =~ s/^"(.*)"/$1/ );
395 push( @{ $raw_attributes{$key} }, $value );
399 my ($actions_config, $all_actions_config);
401 $actions_config = $self->_controller_actions;
402 # No, you're not getting actions => { '*' => ... } with actions in MyApp.
403 $all_actions_config = $self->_all_actions_attributes;
405 my $cfg = $self->config;
406 $actions_config = $self->merge_config_hashes($cfg->{actions}, $cfg->{action});
407 $all_actions_config = {};
412 # Note we deep copy array refs here to stop crapping on config
413 # when attributes are parsed. RT#65463
414 exists $actions_config->{$name} ? map { ref($_) eq 'ARRAY' ? [ @$_ ] : $_ } %{ $actions_config->{$name } } : (),
417 # Private actions with additional attributes will raise a warning and then
418 # be ignored. Adding '*' arguments to the default _DISPATCH / etc. methods,
419 # which are Private, will prevent those from being registered. They should
420 # probably be turned into :Actions instead, or we might want to otherwise
421 # disambiguate between those built-in internal actions and user-level
423 %raw_attributes = (%{ $all_actions_config }, %raw_attributes)
424 unless $raw_attributes{Private};
426 my %final_attributes;
428 while (my ($key, $value) = each %raw_attributes){
429 my $new_attrs = $self->_parse_attr($c, $name, $key => $value );
430 push @{ $final_attributes{$_} }, @{ $new_attrs->{$_} } for keys %$new_attrs;
433 return \%final_attributes;
437 my ($self, $c, $name, $key, $values) = @_;
439 my %final_attributes;
440 foreach my $value (ref($values) eq 'ARRAY' ? @$values : $values) {
441 my $meth = "_parse_${key}_attr";
442 if ( my $code = $self->can($meth) ) {
443 my %new_attrs = $self->$code( $c, $name, $value );
444 while (my ($new_key, $value) = each %new_attrs){
445 my $new_attrs = $key eq $new_key ?
446 { $new_key => [$value] } :
447 $self->_parse_attr($c, $name, $new_key => $value );
448 push @{ $final_attributes{$_} }, @{ $new_attrs->{$_} } for keys %$new_attrs;
452 push( @{ $final_attributes{$key} }, $value );
456 return \%final_attributes;
459 sub _parse_Global_attr {
460 my ( $self, $c, $name, $value ) = @_;
461 # _parse_attr will call _parse_Path_attr for us
462 return Path => "/$name";
465 sub _parse_Absolute_attr { shift->_parse_Global_attr(@_); }
467 sub _parse_Local_attr {
468 my ( $self, $c, $name, $value ) = @_;
469 # _parse_attr will call _parse_Path_attr for us
470 return Path => $name;
473 sub _parse_Relative_attr { shift->_parse_Local_attr(@_); }
475 sub _parse_Path_attr {
476 my ( $self, $c, $name, $value ) = @_;
477 $value = '' if !defined $value;
478 if ( $value =~ m!^/! ) {
479 return ( 'Path', $value );
481 elsif ( length $value ) {
482 return ( 'Path', join( '/', $self->path_prefix($c), $value ) );
485 return ( 'Path', $self->path_prefix($c) );
489 sub _parse_Chained_attr {
490 my ($self, $c, $name, $value) = @_;
492 if (defined($value) && length($value)) {
494 $value = '/'.$self->action_namespace($c);
495 } elsif (my ($rel, $rest) = $value =~ /^((?:\.{2}\/)+)(.*)$/) {
496 my @parts = split '/', $self->action_namespace($c);
497 my @levels = split '/', $rel;
499 $value = '/'.join('/', @parts[0 .. $#parts - @levels], $rest);
500 } elsif ($value !~ m/^\//) {
501 my $action_ns = $self->action_namespace($c);
504 $value = '/'.join('/', $action_ns, $value);
506 $value = '/'.$value; # special case namespace '' (root)
513 return Chained => $value;
516 sub _parse_ChainedParent_attr {
517 my ($self, $c, $name, $value) = @_;
518 return $self->_parse_Chained_attr($c, $name, '../'.$name);
521 sub _parse_PathPrefix_attr {
522 my ( $self, $c ) = @_;
523 return PathPart => $self->path_prefix($c);
526 sub _parse_ActionClass_attr {
527 my ( $self, $c, $name, $value ) = @_;
528 my $appname = $self->_application;
529 $value = Catalyst::Utils::resolve_namespace($appname . '::Action', $self->_action_class, $value);
530 return ( 'ActionClass', $value );
533 sub _parse_MyAction_attr {
534 my ( $self, $c, $name, $value ) = @_;
536 my $appclass = Catalyst::Utils::class2appclass($self);
537 $value = "+${appclass}::Action::${value}";
539 return ( 'ActionClass', $value );
542 sub _parse_Does_attr {
543 my ($self, $app, $name, $value) = @_;
544 return Does => $self->_expand_role_shortname($value);
547 sub _parse_GET_attr { Method => 'GET' }
548 sub _parse_POST_attr { Method => 'POST' }
549 sub _parse_PUT_attr { Method => 'PUT' }
550 sub _parse_DELETE_attr { Method => 'DELETE' }
551 sub _parse_OPTIONS_attr { Method => 'OPTIONS' }
552 sub _parse_HEAD_attr { Method => 'HEAD' }
554 sub _expand_role_shortname {
555 my ($self, @shortnames) = @_;
556 my $app = $self->_application;
558 my $prefix = $self->can('_action_role_prefix') ? $self->_action_role_prefix : ['Catalyst::ActionRole::'];
559 my @prefixes = (qq{${app}::ActionRole::}, @$prefix);
561 return String::RewritePrefix->rewrite(
563 my $loaded = load_first_existing_class(
564 map { "$_$_[0]" } @prefixes
566 return first { $loaded =~ /^$_/ }
567 sort { length $b <=> length $a } @prefixes;
575 __PACKAGE__->meta->make_immutable;
583 Like any other L<Catalyst::Component>, controllers have a config hash,
584 accessible through $self->config from the controller actions. Some
585 settings are in use by the Catalyst framework:
589 This specifies the internal namespace the controller should be bound
590 to. By default the controller is bound to the URI version of the
591 controller name. For instance controller 'MyApp::Controller::Foo::Bar'
592 will be bound to 'foo/bar'. The default Root controller is an example
593 of setting namespace to '' (the null string).
597 Sets 'path_prefix', as described below.
601 Allows you to set the attributes that the dispatcher creates actions out of.
602 This allows you to do 'rails style routes', or override some of the
603 attribute definitions of actions composed from Roles.
604 You can set arguments globally (for all actions of the controller) and
605 specifically (for a single action).
609 '*' => { Chained => 'base', Args => 0 },
610 base => { Chained => '/', PathPart => '', CaptureArgs => 0 },
614 In the case above every sub in the package would be made into a Chain
615 endpoint with a URI the same as the sub name for each sub, chained
616 to the sub named C<base>. Ergo dispatch to C</example> would call the
617 C<base> method, then the C<example> method.
621 Allows you to set constructor arguments on your actions. You can set arguments
622 globally and specifically (as above).
623 This is particularly useful when using C<ActionRole>s
624 (L<Catalyst::Controller::ActionRole>) and custom C<ActionClass>es.
628 '*' => { globalarg1 => 'hello', globalarg2 => 'goodbye' },
629 'specific_action' => { customarg => 'arg1' },
633 In the case above the action class associated with C<specific_action> would get
634 passed the following arguments, in addition to the normal action constructor
635 arguments, when it is instantiated:
637 (globalarg1 => 'hello', globalarg2 => 'goodbye', customarg => 'arg1')
641 =head2 BUILDARGS ($app, @args)
643 From L<Catalyst::Component::ApplicationAttribute>, stashes the application
644 instance as $self->_application.
646 =head2 $self->action_for('name')
648 Returns the Catalyst::Action object (if any) for a given method name
651 =head2 $self->action_namespace($c)
653 Returns the private namespace for actions in this component. Defaults
654 to a value from the controller name (for
655 e.g. MyApp::Controller::Foo::Bar becomes "foo/bar") or can be
656 overridden from the "namespace" config key.
659 =head2 $self->path_prefix($c)
661 Returns the default path prefix for :PathPrefix, :Local and
662 relative :Path actions in this component. Defaults to the action_namespace or
663 can be overridden from the "path" config key.
665 =head2 $self->register_actions($c)
667 Finds all applicable actions for this component, creates
668 Catalyst::Action objects (using $self->create_action) for them and
669 registers them with $c->dispatcher.
671 =head2 $self->get_action_methods()
673 Returns a list of L<Moose::Meta::Method> objects, doing the
674 L<MooseX::MethodAttributes::Role::Meta::Method> role, which are the set of
675 action methods for this package.
677 =head2 $self->register_action_methods($c, @methods)
679 Creates action objects for a set of action methods using C< create_action >,
680 and registers them with the dispatcher.
682 =head2 $self->action_class(%args)
684 Used when a controller is creating an action to determine the correct base
687 =head2 $self->create_action(%args)
689 Called with a hash of data to be use for construction of a new
690 Catalyst::Action (or appropriate sub/alternative class) object.
692 =head2 $self->gather_action_roles(\%action_args)
694 Gathers the list of roles to apply to an action with the given %action_args.
696 =head2 $self->gather_default_action_roles(\%action_args)
698 returns a list of action roles to be applied based on core, builtin rules.
699 Currently only the L<Catalyst::ActionRole::HTTPMethods> role is applied
702 =head2 $self->_application
706 Returns the application instance stored by C<new()>
708 =head1 ACTION SUBROUTINE ATTRIBUTES
710 Please see L<Catalyst::Manual::Intro> for more details
712 Think of action attributes as a sort of way to record metadata about an action,
713 similar to how annotations work in other languages you might have heard of.
714 Generally L<Catalyst> uses these to influence how the dispatcher sees your
715 action and when it will run it in response to an incoming request. They can
716 also be used for other things. Here's a summary, but you should refer to the
717 linked manual page for additional help.
721 sub homepage :Global { ... }
723 A global action defined in any controller always runs relative to your root.
724 So the above is the same as:
726 sub myaction :Path("/homepage") { ... }
730 Status: Deprecated alias to L</Global>.
734 Alias to "Path("$action_name"). The following two actions are the same:
736 sub myaction :Local { ... }
737 sub myaction :Path('myaction') { ... }
741 Status: Deprecated alias to L</Local>
745 Handle various types of paths:
747 package MyApp::Controller::Baz {
751 sub myaction1 :Path { ... } # -> /baz
752 sub myaction2 :Path('foo') { ... } # -> /baz/foo
753 sub myaction2 :Path('/bar') { ... } # -> /bar
756 This is a general toolbox for attaching your action to a given path.
763 B<Status: Deprecated.> Use Chained methods or other techniques.
764 If you really depend on this, install the standalone
765 L<Catalyst::DispatchType::Regex> distribution.
767 A global way to match a give regular expression in the incoming request path.
773 B<Status: Deprecated.> Use Chained methods or other techniques.
774 If you really depend on this, install the standalone
775 L<Catalyst::DispatchType::Regex> distribution.
777 Like L</Regex> but scoped under the namespace of the containing controller
789 Allowed values for CaptureArgs is a single integer (CaptureArgs(2), meaning two
790 allowed) or you can declare a L<Moose>, L<MooseX::Types> or L<Type::Tiny>
791 named constraint such as CaptureArgs(Int,Str) would require two args with
792 the first being a Integer and the second a string. You may declare your own
793 custom type constraints and import them into the controller namespace:
795 package MyApp::Controller::Root;
798 use MooseX::MethodAttributes;
799 use MyApp::Types qw/Int/;
801 extends 'Catalyst::Controller';
803 sub chain_base :Chained(/) CaptureArgs(1) { }
805 sub any_priority_chain :Chained(chain_base) PathPart('') Args(1) { }
807 sub int_priority_chain :Chained(chain_base) PathPart('') Args(Int) { }
809 See L<Catalyst::RouteMatching> for more.
811 Please see L<Catalyst::DispatchType::Chained> for more.
815 Set the base class for the action, defaults to L</Catalyst::Action>. It is now
816 preferred to use L</Does>.
820 Set the ActionClass using a custom Action in your project namespace.
822 The following is exactly the same:
824 sub foo_action1 : Local ActionClass('+MyApp::Action::Bar') { ... }
825 sub foo_action2 : Local MyAction('Bar') { ... }
829 package MyApp::Controller::Zoo;
831 sub foo : Local Does('Moo') { ... } # Catalyst::ActionRole::
832 sub bar : Local Does('~Moo') { ... } # MyApp::ActionRole::Moo
833 sub baz : Local Does('+MyApp::ActionRole::Moo') { ... }
851 Sets the give action path to match the specified HTTP method, or via one of the
852 broadly accepted methods of overriding the 'true' method (see
853 L<Catalyst::ActionRole::HTTPMethods>).
857 When used with L</Path> indicates the number of arguments expected in
858 the path. However if no Args value is set, assumed to 'slurp' all
859 remaining path pars under this namespace.
861 Allowed values for Args is a single integer (Args(2), meaning two allowed) or you
862 can declare a L<Moose>, L<MooseX::Types> or L<Type::Tiny> named constraint such
863 as Args(Int,Str) would require two args with the first being a Integer and the
864 second a string. You may declare your own custom type constraints and import
865 them into the controller namespace:
867 package MyApp::Controller::Root;
870 use MooseX::MethodAttributes;
871 use MyApp::Types qw/Tuple Int Str StrMatch UserId/;
873 extends 'Catalyst::Controller';
875 sub user :Local Args(UserId) {
876 my ($self, $c, $int) = @_;
879 sub an_int :Local Args(Int) {
880 my ($self, $c, $int) = @_;
883 sub many_ints :Local Args(ArrayRef[Int]) {
884 my ($self, $c, @ints) = @_;
887 sub match :Local Args(StrMatch[qr{\d\d-\d\d-\d\d}]) {
888 my ($self, $c, $int) = @_;
891 See L<Catalyst::RouteMatching> for more.
893 =head2 Consumes('...')
895 Matches the current action against the content-type of the request. Typically
896 this is used when the request is a POST or PUT and you want to restrict the
897 submitted content type. For example, you might have an HTML for that either
898 returns classic url encoded form data, or JSON when Javascript is enabled. In
899 this case you may wish to match either incoming type to one of two different
900 actions, for properly processing.
904 sub is_json : Chained('start') Consumes('application/json') { ... }
905 sub is_urlencoded : Chained('start') Consumes('application/x-www-form-urlencoded') { ... }
906 sub is_multipart : Chained('start') Consumes('multipart/form-data') { ... }
908 To reduce boilerplate, we include the following content type shortcuts:
912 sub is_json : Chained('start') Consume(JSON) { ... }
913 sub is_urlencoded : Chained('start') Consumes(UrlEncoded) { ... }
914 sub is_multipart : Chained('start') Consumes(Multipart) { ... }
916 You may specify more than one match:
920 : Consumes('application/x-www-form-urlencoded')
921 : Consumes('multipart/form-data')
925 : Consumes(UrlEncoded)
926 : Consumes(Multipart)
928 Since it is a common case the shortcut C<HTMLForm> matches both
929 'application/x-www-form-urlencoded' and 'multipart/form-data'. Here's the full
930 list of available shortcuts:
932 JSON => 'application/json',
933 JS => 'application/javascript',
934 PERL => 'application/perl',
937 Plain => 'text/plain',
938 UrlEncoded => 'application/x-www-form-urlencoded',
939 Multipart => 'multipart/form-data',
940 HTMLForm => ['application/x-www-form-urlencoded','multipart/form-data'],
942 Please keep in mind that when dispatching, L<Catalyst> will match the first most
943 relevant case, so if you use the C<Consumes> attribute, you should place your
944 most accurate matches early in the Chain, and your 'catchall' actions last.
946 See L<Catalyst::ActionRole::ConsumesContent> for more.
950 Allows you to specify a URI scheme for the action or action chain. For example
951 you can required that a given path be C<https> or that it is a websocket endpoint
952 C<ws> or C<wss>. For an action chain you may currently only have one defined
955 package MyApp::Controller::Root;
957 use base 'Catalyst::Controller';
959 sub is_http :Path(scheme) Scheme(http) Args(0) {
961 $c->response->body("is_http");
964 sub is_https :Path(scheme) Scheme(https) Args(0) {
966 $c->response->body("is_https");
969 In the above example http://localhost/root/scheme would match the first
970 action (is_http) but https://localhost/root/scheme would match the second.
972 As an added benefit, if an action or action chain defines a Scheme, when using
973 $c->uri_for the scheme of the generated URL will use what you define in the action
974 or action chain (the current behavior is to set the scheme based on the current
975 incoming request). This makes it easier to use uri_for on websites where some
976 paths are secure and others are not. You may also use this to other schemes
979 See L<Catalyst::ActionRole::Scheme> for more.
981 =head1 OPTIONAL METHODS
983 =head2 _parse_[$name]_attr
985 Allows you to customize parsing of subroutine attributes.
987 sub myaction1 :Path TwoArgs { ... }
989 sub _parse_TwoArgs_attr {
990 my ( $self, $c, $name, $value ) = @_;
991 # $self -> controller instance
996 Please note that this feature does not let you actually assign new functions
997 to actions via subroutine attributes, but is really more for creating useful
998 aliases to existing core and extended attributes, and transforms based on
999 existing information (like from configuration). Code for actually doing
1000 something meaningful with the subroutine attributes will be located in the
1001 L<Catalyst::Action> classes (or your subclasses), L<Catalyst::Dispatcher> and
1002 in subclasses of L<Catalyst::DispatchType>. Remember these methods only get
1003 called basically once when the application is starting, not per request!
1007 Catalyst Contributors, see Catalyst.pm
1011 This library is free software. You can redistribute it and/or modify
1012 it under the same terms as Perl itself.