1 package Catalyst::Action;
5 Catalyst::Action - Catalyst Action
9 <form action="[%c.uri_for(c.action.reverse)%]">
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 has class => (is => 'rw');
23 has namespace => (is => 'rw');
24 has 'reverse' => (is => 'rw');
25 has attributes => (is => 'rw');
26 has name => (is => 'rw');
27 has code => (is => 'rw');
33 # Stringify to reverse for debug output etc.
34 q{""} => sub { shift->{reverse} },
36 # Codulate to execute to invoke the encapsulated action coderef
37 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
39 # Make general $stuff still work
46 no warnings 'recursion';
48 #__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
50 sub dispatch { # Execute ourselves against a context
51 my ( $self, $c ) = @_;
52 #Moose todo: grrrrrr. this is no good. i don't know enough about it to
53 # debug it though. why can't we just call the accessor?
54 #local $c->{namespace} = $self->namespace;
55 #return $c->execute( $self->class, $self );
57 #believed to be equivalent:
58 my $orig = $c->namespace;
59 $c->namespace($self->namespace);
60 my $ret = $c->execute( $self->class, $self );
71 my ( $self, $c ) = @_;
72 #would it be unreasonable to store the number of arguments
73 #the action has as it's own attribute?
74 #it would basically eliminate the code below. ehhh. small fish
75 return 1 unless exists $self->attributes->{Args};
76 my $args = $self->attributes->{Args}[0];
77 return 1 unless defined($args) && length($args);
78 return scalar( @{ $c->req->args } ) == $args;
81 __PACKAGE__->meta->make_immutable;
91 The sub attributes that are set for this action, like Local, Path, Private
92 and so on. This determines how the action is dispatched to.
96 Returns the class name where this action is defined.
100 Returns a code reference to this action.
102 =head2 dispatch( $c )
104 Dispatch this action against a context
106 =head2 execute( $controller, $c, @args )
108 Execute this action's coderef against a given controller with a given
109 context and arguments
113 Check Args attribute, and makes sure number of args matches the setting.
114 Always returns true if Args is omitted.
118 Returns the private namespace this action lives in.
122 Returns the private path for this action.
126 returns the sub name of this action.
138 This program is free software, you can redistribute it and/or modify it under
139 the same terms as Perl itself.