lots of new docs,
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Action.pm
1 package Catalyst::Action;
2
3 use strict;
4 use base qw/Class::Accessor::Fast/;
5
6 __PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
7
8 use 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
16     # Make general $stuff still work
17     fallback => 1,
18
19 );
20
21 =head1 NAME
22
23 Catalyst::Action - Catalyst Action
24
25 =head1 SYNOPSIS
26
27 See L<Catalyst>.
28
29 =head1 DESCRIPTION
30
31 This class represents a Catalyst Action. You can access the object for the 
32 currently dispatched action via $c->action
33
34 =head1 METHODS
35
36 =head2 attributes
37
38 The sub attributes that are set for this action, like Local, Path, Private
39 and so on.
40
41 =head2 class
42
43 Returns the class name of this action
44
45 =head2 code
46
47 Returns a code reference to this action
48
49 =head2 execute( $c )
50
51 Execute this action against a context
52
53 =cut
54
55 sub execute {    # Execute ourselves against a context
56     my ( $self, $c ) = @_;
57     local $c->namespace = $self->namespace;
58     return $c->execute( $self->class, $self );
59 }
60
61 =head2 match( $c )
62
63 Check Args attribute, and makes sure number of args matches the setting.
64
65 =cut
66
67 sub 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
73 =head2 namespace
74
75 Returns the private namespace this action lives in.
76
77 =head2 reverse
78
79 Returns the private path for this action.
80
81 =head2 name
82
83 returns the sub name of this action.
84
85 =head1 AUTHOR
86
87 Matt S. Trout
88
89 =head1 COPYRIGHT
90
91 This program is free software, you can redistribute it and/or modify it under
92 the same terms as Perl itself.
93
94 =cut
95
96 1;