File Coverage

blib/lib/Apache2/Controller/X.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Apache2::Controller::X;
2 2     2   117758 use warnings FATAL => 'all';
  2         5  
  2         112  
3 2     2   13 use strict;
  2         3  
  2         80  
4              
5             =head1 NAME
6              
7             Apache2::Controller::X - Exception::Class hierarchy for Apache2::Controller
8              
9             =head1 VERSION
10              
11             Version 1.001.001
12              
13             =cut
14              
15 2     2   983 use version;
  2         2401  
  2         15  
16             our $VERSION = version->new('1.001.001');
17              
18             =head1 SYNOPSIS
19              
20             package MyApp::C::Foo;
21             use base qw( Apache2::Controller MyApp::Blabber );
22             use Apache2::Controller::X;
23             # ...
24             sub some_page_controller_method {
25             my ($self, @path_args) = @_;
26             $self->print( $self->blabber() || a2cx "Cannot blabber: $OS_ERROR" );
27             }
28              
29             # or subclass and extend the errors...
30            
31             package MyApp::X;
32             use base qw( Apache2::Controller::X );
33             use Exception::Class (
34             'MyApp::X' => {
35             isa => 'Apache2::Controller::X',
36             fields => [qw( message status dump action )],
37             },
38             alias => 'myx',
39             );
40              
41             package MyApp::C::Bar;
42             use base qw( Apache2::Controller );
43             use Apache2::Const -compile => qw( :http );
44             use MyApp::X;
45             # ...
46             sub page_controller_method {
47             myx message => q{ You're not supposed to be here. },
48             status => Apache2::Const::FORBIDDEN,
49             action => sub {"not sure how you'd implement this actually"},
50             dump => {
51             this => q{structure will get YAML::Syck::Dump'd},
52             that => [qw( to the error log )],
53             };
54             }
55              
56             TODO: when $X is intercepted by handler() in each of the controller layers,
57             attach it to pnotes.
58              
59             =head1 DESCRIPTION
60              
61             Hierarchy of L objects for L.
62             All are subclasses of Apache2::Controller::X.
63              
64             =head1 FIELDS
65              
66             All Apache2::Controller::X exceptions implement three fields:
67              
68             =head2 message
69              
70             Required.
71             The standard L message field. If you call C
72             or the alias C
73             with only one argument, a string, then this gets set as the message
74             field, which is displayed when the object is referred to in string context.
75              
76             eval { a2cx "booyeah" };
77             if (my $X = Exception::Class->caught('Apache2::Controller::X')) {
78             warn "my exception 'message' was '$X'\n";
79             warn $X->trace;
80             }
81              
82             =head2 status
83              
84             This can be set to an L constant, which
85             will then be set as the status for the request.
86              
87             a2cx message => "oh no!",
88             status => Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
89              
90             =head2 status_line
91              
92             Combined with status, when intercepted by L
93             this sets a custom message with L.
94              
95             a2cx message => "Warp injection coil failure in unit 3-A-73",
96             status => Apache2::Const::HTTP_INTERNAL_SERVER_ERROR,
97             status_line => "Turbulence ahead. Please buckle your safety belts.";
98              
99             This differentiation can be used to display technical information
100             in the log while giving a nice message to the user.
101              
102             If L is used,
103             status_line is preferentially used to translate the error code,
104             otherwise it uses L.
105              
106             =head2 dump
107              
108             An arbitrary data structure which Apache2::Controller will send
109             through L Dump() when printing to the error log.
110              
111             =head1 SUBCLASSES
112              
113             =head2 Apache2::Controller::X
114              
115             The basic exception object that implements the three basic fields.
116              
117             After abandoning redirects, I have no use for any subclasses.
118             Should not re-invent the wheel, after all. Just set the
119             outgoing location header and return REDIRECT from a controller
120             if you want to do that. Or other actions should be done.
121              
122             =cut
123              
124 2     2   217 use base qw( Exporter );
  2         3  
  2         295  
125             our @EXPORT = qw( a2cx );
126              
127             use Exception::Class (
128 2         18 'Apache2::Controller::X' => {
129             alias => 'a2cx',
130             fields => [qw( message dump status status_line )],
131             },
132 2     2   1902 ); # whoopdeedoo
  2         40122  
133              
134             =head1 METHODS
135              
136             =head2 Fields
137              
138             This is the Fields() method provided by L.
139             For some reason the pod test wants this method enumerated.
140              
141             =head1 SEE ALSO
142              
143             L
144              
145             L
146              
147             L
148              
149             L
150              
151             =head1 AUTHOR
152              
153             Mark Hedges, C<< >>
154              
155             =head1 COPYRIGHT & LICENSE
156              
157             Copyright 2008-2010 Mark Hedges, all rights reserved.
158              
159             This program is free software; you can redistribute it and/or modify it
160             under the same terms as Perl itself.
161              
162             This software is provided as-is, with no warranty
163             and no guarantee of fitness
164             for any particular purpose.
165              
166             =cut
167              
168              
169             1;