added docs for engine/dispatcher
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Action.pm
CommitLineData
fbcc39ad 1package Catalyst::Action;
2
3use strict;
4use base qw/Class::Accessor::Fast/;
5
11bd4e3e 6__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
fbcc39ad 7
8use overload (
9
10 # Stringify to reverse for debug output etc.
11 q{""} => sub { shift->{reverse} },
12
13 # Codulate to encapsulated action coderef
14 '&{}' => sub { shift->{code} },
15
6a064886 16 # Make general $stuff still work
17 fallback => 1,
18
fbcc39ad 19);
20
21=head1 NAME
22
23Catalyst::Action - Catalyst Action
24
25=head1 SYNOPSIS
26
27See L<Catalyst>.
28
29=head1 DESCRIPTION
30
4ab87e27 31This class represents a Catalyst Action. You can access the object for the
32currently dispatched action via $c->action
33
fbcc39ad 34=head1 METHODS
35
b5ecfcf0 36=head2 attributes
fbcc39ad 37
4ab87e27 38The sub attributes that are set for this action, like Local, Path, Private
39and so on.
40
b5ecfcf0 41=head2 class
b96f127f 42
4ab87e27 43Returns the class name of this action
44
b5ecfcf0 45=head2 code
11bd4e3e 46
4ab87e27 47Returns a code reference to this action
48
49=head2 execute <c>
50
51Execute this action against a context
fbcc39ad 52
53=cut
54
55sub execute { # Execute ourselves against a context
56 my ( $self, $c ) = @_;
261c571e 57 local $c->namespace = $self->namespace;
11bd4e3e 58 return $c->execute( $self->class, $self );
fbcc39ad 59}
60
4ab87e27 61=head2 match <context>
62
63Check Args setting, and makes sure number of args matches the setting.
4082e678 64
65=cut
66
67sub match {
68 my ( $self, $c ) = @_;
69 return 1 unless exists $self->attributes->{Args};
70 return scalar(@{$c->req->args}) == $self->attributes->{Args}[0];
71}
72
b5ecfcf0 73=head2 namespace
fbcc39ad 74
4ab87e27 75Returns the private namespace this action lives in.
76
b5ecfcf0 77=head2 reverse
6b239949 78
4ab87e27 79Returns the private path for this action.
80
b5ecfcf0 81=head2 name
fbcc39ad 82
4ab87e27 83returns the sub name of this action.
84
fbcc39ad 85=head1 AUTHOR
86
87Matt S. Trout
88
89=head1 COPYRIGHT
90
91This program is free software, you can redistribute it and/or modify it under
92the same terms as Perl itself.
93
94=cut
95
961;