mro compat stuff
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Action.pm
CommitLineData
fbcc39ad 1package Catalyst::Action;
2
b2ddf6d7 3=head1 NAME
4
5Catalyst::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 13This class represents a Catalyst Action. You can access the object for the
b2ddf6d7 14currently dispatched action via $c->action. See the L<Catalyst::Dispatcher>
15for more information on how actions are dispatched. Actions are defined in
16L<Catalyst::Controller> subclasses.
17
18=cut
19
6f1f968a 20use MRO::Compat;
21use mro 'c3';
059c085b 22use Moose;
23
5fb12dbb 24has class => (is => 'rw');
25has namespace => (is => 'rw');
26has 'reverse' => (is => 'rw');
27has attributes => (is => 'rw');
28has name => (is => 'rw');
29has code => (is => 'rw');
059c085b 30
31no Moose;
32
33no warnings 'recursion';
34
35#__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
fbcc39ad 36
b2ddf6d7 37sub 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 52sub execute {
53 my $self = shift;
059c085b 54 $self->code->(@_);
b2ddf6d7 55}
fbcc39ad 56
b2ddf6d7 57sub 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 701;
fbcc39ad 71
b2ddf6d7 72__END__
4ab87e27 73
fbcc39ad 74=head1 METHODS
75
b5ecfcf0 76=head2 attributes
fbcc39ad 77
4ab87e27 78The sub attributes that are set for this action, like Local, Path, Private
b2ddf6d7 79and so on. This determines how the action is dispatched to.
4ab87e27 80
b5ecfcf0 81=head2 class
b96f127f 82
b2ddf6d7 83Returns the class name where this action is defined.
4ab87e27 84
b5ecfcf0 85=head2 code
11bd4e3e 86
b2ddf6d7 87Returns a code reference to this action.
4ab87e27 88
b8f669f3 89=head2 dispatch( $c )
4ab87e27 90
b8f669f3 91Dispatch this action against a context
fbcc39ad 92
b8f669f3 93=head2 execute( $controller, $c, @args )
94
95Execute this action's coderef against a given controller with a given
96context and arguments
97
649fd1fa 98=head2 match( $c )
4ab87e27 99
649fd1fa 100Check Args attribute, and makes sure number of args matches the setting.
b2ddf6d7 101Always returns true if Args is omitted.
4082e678 102
b5ecfcf0 103=head2 namespace
fbcc39ad 104
4ab87e27 105Returns the private namespace this action lives in.
106
b5ecfcf0 107=head2 reverse
6b239949 108
4ab87e27 109Returns the private path for this action.
110
b5ecfcf0 111=head2 name
fbcc39ad 112
4ab87e27 113returns the sub name of this action.
114
059c085b 115=head2 meta
116
117Provided by Moose
118
fbcc39ad 119=head1 AUTHOR
120
121Matt S. Trout
122
123=head1 COPYRIGHT
124
125This program is free software, you can redistribute it and/or modify it under
126the same terms as Perl itself.
127
85d9fce6 128=cut