Commit | Line | Data |
fbcc39ad |
1 | package Catalyst::Action; |
2 | |
3 | use strict; |
4 | use base qw/Class::Accessor::Fast/; |
5 | |
b2ddf6d7 |
6 | |
7 | =head1 NAME |
8 | |
9 | Catalyst::Action - Catalyst Action |
10 | |
11 | =head1 SYNOPSIS |
12 | |
85d9fce6 |
13 | <form action="[%c.uri_for(c.action.reverse)%]"> |
14 | |
b2ddf6d7 |
15 | =head1 DESCRIPTION |
16 | |
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. |
21 | |
22 | =cut |
23 | |
11bd4e3e |
24 | __PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/); |
fbcc39ad |
25 | |
26 | use overload ( |
27 | |
28 | # Stringify to reverse for debug output etc. |
29 | q{""} => sub { shift->{reverse} }, |
30 | |
b8f669f3 |
31 | # Codulate to execute to invoke the encapsulated action coderef |
32 | '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; }, |
fbcc39ad |
33 | |
6a064886 |
34 | # Make general $stuff still work |
35 | fallback => 1, |
36 | |
fbcc39ad |
37 | ); |
38 | |
b2ddf6d7 |
39 | sub dispatch { # Execute ourselves against a context |
40 | my ( $self, $c ) = @_; |
b2ddf6d7 |
41 | return $c->execute( $self->class, $self ); |
42 | } |
fbcc39ad |
43 | |
b2ddf6d7 |
44 | sub execute { |
45 | my $self = shift; |
46 | $self->{code}->(@_); |
47 | } |
fbcc39ad |
48 | |
b2ddf6d7 |
49 | sub match { |
50 | my ( $self, $c ) = @_; |
51 | return 1 unless exists $self->attributes->{Args}; |
52 | my $args = $self->attributes->{Args}[0]; |
53 | return 1 unless defined($args) && length($args); |
54 | return scalar( @{ $c->req->args } ) == $args; |
55 | } |
fbcc39ad |
56 | |
b2ddf6d7 |
57 | 1; |
fbcc39ad |
58 | |
b2ddf6d7 |
59 | __END__ |
4ab87e27 |
60 | |
fbcc39ad |
61 | =head1 METHODS |
62 | |
b5ecfcf0 |
63 | =head2 attributes |
fbcc39ad |
64 | |
4ab87e27 |
65 | The sub attributes that are set for this action, like Local, Path, Private |
b2ddf6d7 |
66 | and so on. This determines how the action is dispatched to. |
4ab87e27 |
67 | |
b5ecfcf0 |
68 | =head2 class |
b96f127f |
69 | |
b2ddf6d7 |
70 | Returns the class name where this action is defined. |
4ab87e27 |
71 | |
b5ecfcf0 |
72 | =head2 code |
11bd4e3e |
73 | |
b2ddf6d7 |
74 | Returns a code reference to this action. |
4ab87e27 |
75 | |
b8f669f3 |
76 | =head2 dispatch( $c ) |
4ab87e27 |
77 | |
b8f669f3 |
78 | Dispatch this action against a context |
fbcc39ad |
79 | |
b8f669f3 |
80 | =head2 execute( $controller, $c, @args ) |
81 | |
82 | Execute this action's coderef against a given controller with a given |
83 | context and arguments |
84 | |
649fd1fa |
85 | =head2 match( $c ) |
4ab87e27 |
86 | |
649fd1fa |
87 | Check Args attribute, and makes sure number of args matches the setting. |
b2ddf6d7 |
88 | Always returns true if Args is omitted. |
4082e678 |
89 | |
b5ecfcf0 |
90 | =head2 namespace |
fbcc39ad |
91 | |
4ab87e27 |
92 | Returns the private namespace this action lives in. |
93 | |
b5ecfcf0 |
94 | =head2 reverse |
6b239949 |
95 | |
4ab87e27 |
96 | Returns the private path for this action. |
97 | |
b5ecfcf0 |
98 | =head2 name |
fbcc39ad |
99 | |
4ab87e27 |
100 | returns the sub name of this action. |
101 | |
0bf7ab71 |
102 | =head1 AUTHORS |
fbcc39ad |
103 | |
0bf7ab71 |
104 | Catalyst Contributors, see Catalyst.pm |
fbcc39ad |
105 | |
106 | =head1 COPYRIGHT |
107 | |
108 | This program is free software, you can redistribute it and/or modify it under |
109 | the same terms as Perl itself. |
110 | |
85d9fce6 |
111 | =cut |