typo in Chained docs
[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
b8f669f3 13 # Codulate to execute to invoke the encapsulated action coderef
14 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
fbcc39ad 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
b8f669f3 49=head2 dispatch( $c )
4ab87e27 50
b8f669f3 51Dispatch this action against a context
fbcc39ad 52
53=cut
54
b8f669f3 55sub dispatch { # Execute ourselves against a context
fbcc39ad 56 my ( $self, $c ) = @_;
261c571e 57 local $c->namespace = $self->namespace;
11bd4e3e 58 return $c->execute( $self->class, $self );
fbcc39ad 59}
60
b8f669f3 61=head2 execute( $controller, $c, @args )
62
63Execute this action's coderef against a given controller with a given
64context and arguments
65
66=cut
67
68sub execute {
69 my $self = shift;
70 $self->{code}->(@_);
71}
72
649fd1fa 73=head2 match( $c )
4ab87e27 74
649fd1fa 75Check Args attribute, and makes sure number of args matches the setting.
4082e678 76
77=cut
78
79sub match {
80 my ( $self, $c ) = @_;
81 return 1 unless exists $self->attributes->{Args};
141459fa 82 my $args = $self->attributes->{Args}[0];
83 return 1 unless defined($args) && length($args);
84 return scalar( @{ $c->req->args } ) == $args;
4082e678 85}
86
b5ecfcf0 87=head2 namespace
fbcc39ad 88
4ab87e27 89Returns the private namespace this action lives in.
90
b5ecfcf0 91=head2 reverse
6b239949 92
4ab87e27 93Returns the private path for this action.
94
b5ecfcf0 95=head2 name
fbcc39ad 96
4ab87e27 97returns the sub name of this action.
98
fbcc39ad 99=head1 AUTHOR
100
101Matt S. Trout
102
103=head1 COPYRIGHT
104
105This program is free software, you can redistribute it and/or modify it under
106the same terms as Perl itself.
107
108=cut
109
1101;