remove warning for undef captures
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Action.pm
CommitLineData
fbcc39ad 1package Catalyst::Action;
2
3use strict;
4use base qw/Class::Accessor::Fast/;
5
b2ddf6d7 6
7=head1 NAME
8
9Catalyst::Action - Catalyst Action
10
11=head1 SYNOPSIS
12
13 <form action="[%c.uri_for(c.action.reverse)%]">
14
15=head1 DESCRIPTION
16
17This class represents a Catalyst Action. You can access the object for the
18currently dispatched action via $c->action. See the L<Catalyst::Dispatcher>
19for more information on how actions are dispatched. Actions are defined in
20L<Catalyst::Controller> subclasses.
21
22=cut
23
11bd4e3e 24__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
fbcc39ad 25
26use 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 39sub dispatch { # Execute ourselves against a context
40 my ( $self, $c ) = @_;
41 local $c->namespace = $self->namespace;
42 return $c->execute( $self->class, $self );
43}
fbcc39ad 44
b2ddf6d7 45sub execute {
46 my $self = shift;
47 $self->{code}->(@_);
48}
fbcc39ad 49
b2ddf6d7 50sub match {
51 my ( $self, $c ) = @_;
52 return 1 unless exists $self->attributes->{Args};
53 my $args = $self->attributes->{Args}[0];
54 return 1 unless defined($args) && length($args);
55 return scalar( @{ $c->req->args } ) == $args;
56}
fbcc39ad 57
b2ddf6d7 581;
fbcc39ad 59
b2ddf6d7 60__END__
4ab87e27 61
fbcc39ad 62=head1 METHODS
63
b5ecfcf0 64=head2 attributes
fbcc39ad 65
4ab87e27 66The sub attributes that are set for this action, like Local, Path, Private
b2ddf6d7 67and so on. This determines how the action is dispatched to.
4ab87e27 68
b5ecfcf0 69=head2 class
b96f127f 70
b2ddf6d7 71Returns the class name where this action is defined.
4ab87e27 72
b5ecfcf0 73=head2 code
11bd4e3e 74
b2ddf6d7 75Returns a code reference to this action.
4ab87e27 76
b8f669f3 77=head2 dispatch( $c )
4ab87e27 78
b8f669f3 79Dispatch this action against a context
fbcc39ad 80
b8f669f3 81=head2 execute( $controller, $c, @args )
82
83Execute this action's coderef against a given controller with a given
84context and arguments
85
649fd1fa 86=head2 match( $c )
4ab87e27 87
649fd1fa 88Check Args attribute, and makes sure number of args matches the setting.
b2ddf6d7 89Always returns true if Args is omitted.
4082e678 90
b5ecfcf0 91=head2 namespace
fbcc39ad 92
4ab87e27 93Returns the private namespace this action lives in.
94
b5ecfcf0 95=head2 reverse
6b239949 96
4ab87e27 97Returns the private path for this action.
98
b5ecfcf0 99=head2 name
fbcc39ad 100
4ab87e27 101returns the sub name of this action.
102
fbcc39ad 103=head1 AUTHOR
104
105Matt S. Trout
106
107=head1 COPYRIGHT
108
109This program is free software, you can redistribute it and/or modify it under
110the same terms as Perl itself.
111
b2ddf6d7 112=cut