1 package Catalyst::Action;
5 Catalyst::Action - Catalyst Action
9 <form action="[%c.uri_for(c.action)%]">
13 This class represents a Catalyst Action. You can access the object for the
14 currently dispatched action via $c->action. See the L<Catalyst::Dispatcher>
15 for more information on how actions are dispatched. Actions are defined in
16 L<Catalyst::Controller> subclasses.
22 with 'MooseX::Emulate::Class::Accessor::Fast';
24 has class => (is => 'rw');
25 has namespace => (is => 'rw');
26 has 'reverse' => (is => 'rw');
27 has attributes => (is => 'rw');
28 has name => (is => 'rw');
29 has code => (is => 'rw');
35 # Stringify to reverse for debug output etc.
36 q{""} => sub { shift->{reverse} },
38 # Codulate to execute to invoke the encapsulated action coderef
39 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
41 # Make general $stuff still work
48 no warnings 'recursion';
50 #__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
52 sub dispatch { # Execute ourselves against a context
53 my ( $self, $c ) = @_;
54 return $c->execute( $self->class, $self );
63 my ( $self, $c ) = @_;
64 #would it be unreasonable to store the number of arguments
65 #the action has as it's own attribute?
66 #it would basically eliminate the code below. ehhh. small fish
67 return 1 unless exists $self->attributes->{Args};
68 my $args = $self->attributes->{Args}[0];
69 return 1 unless defined($args) && length($args);
70 return scalar( @{ $c->req->args } ) == $args;
73 __PACKAGE__->meta->make_immutable;
83 The sub attributes that are set for this action, like Local, Path, Private
84 and so on. This determines how the action is dispatched to.
88 Returns the class name where this action is defined.
92 Returns a code reference to this action.
96 Dispatch this action against a context
98 =head2 execute( $controller, $c, @args )
100 Execute this action's coderef against a given controller with a given
101 context and arguments
105 Check Args attribute, and makes sure number of args matches the setting.
106 Always returns true if Args is omitted.
110 Returns the private namespace this action lives in.
114 Returns the private path for this action.
118 returns the sub name of this action.
126 Catalyst Contributors, see Catalyst.pm
130 This program is free software, you can redistribute it and/or modify it under
131 the same terms as Perl itself.