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