Commit | Line | Data |
fbcc39ad |
1 | package Catalyst::Action; |
2 | |
b2ddf6d7 |
3 | =head1 NAME |
4 | |
5 | Catalyst::Action - Catalyst Action |
6 | |
7 | =head1 SYNOPSIS |
8 | |
85d9fce6 |
9 | <form action="[%c.uri_for(c.action.reverse)%]"> |
10 | |
b2ddf6d7 |
11 | =head1 DESCRIPTION |
12 | |
ac5c933b |
13 | This class represents a Catalyst Action. You can access the object for the |
b2ddf6d7 |
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. |
17 | |
18 | =cut |
19 | |
6f1f968a |
20 | use MRO::Compat; |
21 | use mro 'c3'; |
059c085b |
22 | use Moose; |
23 | |
5fb12dbb |
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'); |
059c085b |
30 | |
31 | no Moose; |
32 | |
33 | no warnings 'recursion'; |
34 | |
35 | #__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/); |
fbcc39ad |
36 | |
b2ddf6d7 |
37 | sub dispatch { # Execute ourselves against a context |
38 | my ( $self, $c ) = @_; |
e63bdf38 |
39 | #Moose todo: grrrrrr. this is no good. i don't know enough about it to |
40 | # debug it though. why can't we just call the accessor? |
6680c772 |
41 | #local $c->{namespace} = $self->namespace; |
42 | #return $c->execute( $self->class, $self ); |
e63bdf38 |
43 | |
44 | #believed to be equivalent: |
6680c772 |
45 | my $orig = $c->namespace; |
46 | $c->namespace($self->namespace); |
47 | my $ret = $c->execute( $self->class, $self ); |
48 | $c->namespace($orig); |
49 | return $ret; |
b2ddf6d7 |
50 | } |
fbcc39ad |
51 | |
b2ddf6d7 |
52 | sub execute { |
53 | my $self = shift; |
059c085b |
54 | $self->code->(@_); |
b2ddf6d7 |
55 | } |
fbcc39ad |
56 | |
b2ddf6d7 |
57 | sub match { |
58 | my ( $self, $c ) = @_; |
e5ecd5bc |
59 | #would it be unreasonable to store the number of arguments |
60 | #the action has as it's own attribute? |
61 | #it would basically eliminate the code below. ehhh. small fish |
b2ddf6d7 |
62 | return 1 unless exists $self->attributes->{Args}; |
63 | my $args = $self->attributes->{Args}[0]; |
64 | return 1 unless defined($args) && length($args); |
65 | return scalar( @{ $c->req->args } ) == $args; |
66 | } |
fbcc39ad |
67 | |
e5ecd5bc |
68 | __PACKAGE__->meta->make_immutable; |
69 | |
b2ddf6d7 |
70 | 1; |
fbcc39ad |
71 | |
b2ddf6d7 |
72 | __END__ |
4ab87e27 |
73 | |
fbcc39ad |
74 | =head1 METHODS |
75 | |
b5ecfcf0 |
76 | =head2 attributes |
fbcc39ad |
77 | |
4ab87e27 |
78 | The sub attributes that are set for this action, like Local, Path, Private |
b2ddf6d7 |
79 | and so on. This determines how the action is dispatched to. |
4ab87e27 |
80 | |
b5ecfcf0 |
81 | =head2 class |
b96f127f |
82 | |
b2ddf6d7 |
83 | Returns the class name where this action is defined. |
4ab87e27 |
84 | |
b5ecfcf0 |
85 | =head2 code |
11bd4e3e |
86 | |
b2ddf6d7 |
87 | Returns a code reference to this action. |
4ab87e27 |
88 | |
b8f669f3 |
89 | =head2 dispatch( $c ) |
4ab87e27 |
90 | |
b8f669f3 |
91 | Dispatch this action against a context |
fbcc39ad |
92 | |
b8f669f3 |
93 | =head2 execute( $controller, $c, @args ) |
94 | |
95 | Execute this action's coderef against a given controller with a given |
96 | context and arguments |
97 | |
649fd1fa |
98 | =head2 match( $c ) |
4ab87e27 |
99 | |
649fd1fa |
100 | Check Args attribute, and makes sure number of args matches the setting. |
b2ddf6d7 |
101 | Always returns true if Args is omitted. |
4082e678 |
102 | |
b5ecfcf0 |
103 | =head2 namespace |
fbcc39ad |
104 | |
4ab87e27 |
105 | Returns the private namespace this action lives in. |
106 | |
b5ecfcf0 |
107 | =head2 reverse |
6b239949 |
108 | |
4ab87e27 |
109 | Returns the private path for this action. |
110 | |
b5ecfcf0 |
111 | =head2 name |
fbcc39ad |
112 | |
4ab87e27 |
113 | returns the sub name of this action. |
114 | |
059c085b |
115 | =head2 meta |
116 | |
117 | Provided by Moose |
118 | |
fbcc39ad |
119 | =head1 AUTHOR |
120 | |
121 | Matt S. Trout |
122 | |
123 | =head1 COPYRIGHT |
124 | |
125 | This program is free software, you can redistribute it and/or modify it under |
126 | the same terms as Perl itself. |
127 | |
85d9fce6 |
128 | =cut |