1 package Catalyst::Action;
4 use base qw/Class::Accessor::Fast/;
9 Catalyst::Action - Catalyst Action
13 <form action="[%c.uri_for(c.action.reverse)%]">
17 This class represents a Catalyst Action. You can access the object for the
18 currently dispatched action via $c->action. See the L<Catalyst::Dispatcher>
19 for more information on how actions are dispatched. Actions are defined in
20 L<Catalyst::Controller> subclasses.
24 __PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
28 # Stringify to reverse for debug output etc.
29 q{""} => sub { shift->{reverse} },
31 # Codulate to execute to invoke the encapsulated action coderef
32 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
34 # Make general $stuff still work
39 sub dispatch { # Execute ourselves against a context
40 my ( $self, $c ) = @_;
41 local $c->namespace = $self->namespace;
42 return $c->execute( $self->class, $self );
51 my ( $self, $c ) = @_;
52 return 1 unless exists $self->attributes->{Args};
53 my $args = $self->attributes->{Args}[0];
54 return 1 unless defined($args) && length($args);
55 return scalar( @{ $c->req->args } ) == $args;
66 The sub attributes that are set for this action, like Local, Path, Private
67 and so on. This determines how the action is dispatched to.
71 Returns the class name where this action is defined.
75 Returns a code reference to this action.
79 Dispatch this action against a context
81 =head2 execute( $controller, $c, @args )
83 Execute this action's coderef against a given controller with a given
88 Check Args attribute, and makes sure number of args matches the setting.
89 Always returns true if Args is omitted.
93 Returns the private namespace this action lives in.
97 Returns the private path for this action.
101 returns the sub name of this action.
109 This program is free software, you can redistribute it and/or modify it under
110 the same terms as Perl itself.