blib/lib/XAS/Lib/Mixins/Handlers.pm

filter: Statementstmt 10.8% 5 / 46 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 20.0% 1 / 5 Podpod 50.0% 2 / 4 totaltotal 10.0% 8 / 80 CC 11 SCAR 40.2
CC
11
Cov
7%
parse_exception
90.0
exception_handler
6.0
exit_handler
6.0
CRAP 55.8
« blib/lib/XAS/Apps/Rotate.pm ↑ Summary blib/lib/XAS/Lib/SSH/Client/Shell.pm »
1 package XAS::Lib::Mixins::Handlers;
2  
3 1 our $VERSION = '0.01';
4  
5 use XAS::Class
6 1 debug => 0,
7 version => $VERSION,
8 base => 'XAS::Base',
9 utils => 'compress',
10 mixins => 'exit_handler exception_handler error_handler parse_exception',
11 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ----------------------------------------------------------------------
14 # Public Methods
15 # ----------------------------------------------------------------------
16  
17 sub exception_handler {
18 0 ▶ my $self = shift;
Subroutine exception_handler: not called CC=2 SCAR=17.9
Pod undocumented
19  
20 0 my ($ex) = $self->validate_params(\@_, [1]);
21  
22 0 my $errors = $self->parse_exception($ex);
23 0 my $script = $self->class->any_var('SCRIPT');
24  
25 0 $self->log->error($errors);
26  
27 0 ▶ if ($self->alerts->check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->alerts->check) 0 0 0
28  
29 0 $self->alert->send(
30 -process => $script,
31 -priority => $self->priority,
32 -facility => $self->facility,
33 -message => $errors
34 );
35  
36 }
37  
38 }
39  
40 sub exit_handler {
41 0 ▶ my $self = shift;
Subroutine exit_handler: not called CC=2 SCAR=17.9
Pod documented
42  
43 0 my ($ex) = $self->validate_params(\@_, [1]);
44 0 my $script = $self->class->any_var('SCRIPT');
45 0 my ($errors, $rc) = $self->parse_exception($ex);
46  
47 0 $self->log->fatal($errors);
48  
49 0 ▶ if ($self->alerts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->alerts) 0 0 0
50  
51 0 $self->alert->send(
52 -process => $script,
53 -priority => $self->priority,
54 -facility => $self->facility,
55 -message => $errors
56 );
57  
58 }
59  
60 0 return $rc;
61  
62 }
63  
64 sub error_handler {
65 0 ▶ my $self = shift;
Subroutine error_handler: not called CC=1 SCAR=6.9
Pod documented
66  
67 0 my ($ex) = $self->validate_params(\@_, [1]);
68 0 my $errors = $self->parse_exception($ex);
69  
70 0 $self->log->error($errors);
71  
72 }
73  
74 sub parse_exception {
75 0 ▶ my $self= shift;
Subroutine parse_exception: not called CC=9 SCAR=45.0
Pod undocumented
76  
77 0 my ($ex) = $self->validate_params(\@_, [1]);
78  
79 0 my $rc = 0;
80 0 my $errors;
81 0 my $ref = ref($ex);
82  
83 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
84  
85 0 ▶ if ($ex->can('info') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($ex->can('info') and $ex->can('type') and $ex->can('match_type')) { } 0 0 0
Condition0%0/6
$ex->can("info") and $ex->can("type") and $ex->can("match_type")
!ll&&!rl&&r
000
$ex->can("info") and $ex->can("type")
!ll&&!rl&&r
000
MC/DC0%0/3
$ex->can("info") and $ex->can("type") and $ex->can("match_type")
$ex->can("info") $ex->can("type") $ex->can("match_type")
Truth table0%0/4
A and B and C
A= $ex->can("info")B= $ex->can("type")C= $ex->can("match_type")
ABCresult
0XX0
10X0
1100
1111
86 $ex->can('type') &&
87 $ex->can('match_type')) {
88  
89 0 my $type = $ex->type;
90 0 my $info = compress($ex->info);
91  
92 0 ▶ if ($ex->match_type('dbix.class')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ex->match_type('dbix.class')) { } 0 0 0
elsif ($ex->match_type('xas.lib.app.signal_handler')) { } 0 0 0
93  
94 0 ▶ if ($info =~ m/(.*) XAS::Database::Model::dbix_exception/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ /(.*) XAS::Database::Model::dbix_exception/) 0 0 0
95  
96 0 $rc = 1;
97 0 $info = $1; # strip off the dbix stack dump
98
99 }
100  
101 } elsif ($ex->match_type('xas.lib.app.signal_handler')) {
102
103 0 die $ex; # propagate to the next level of error handlers
104  
105 }
106  
107 0 ▶ if ($ex->type =~ /pidfile\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex->type =~ /pidfile\./) 0 0 0
108  
109 0 $rc = 2;
110  
111 }
112  
113 0 $errors = $self->message('exception', $type, $info);
114  
115 } else {
116  
117 0 $rc = 1;
118 0 $errors = $self->message('unexpected', compress($ex));
119  
120 }
121  
122 } else {
123  
124 0 $rc = 1;
125 0 $errors = $self->message('unknownerror', compress($ex));
126  
127 }
128  
129 0 return $errors, $rc;
130  
131 }
132  
133 # ----------------------------------------------------------------------
134 # Private Methods
135 # ----------------------------------------------------------------------
136  
137 1 1;
138  
139 __END__
140  
141 =head1 NAME
142  
143 XAS::Lib::Mixin::Handlers - A mixin to provide exception handlers.
144  
145 =head1 SYNOPSIS
146  
147 use XAS::Class
148 version => '0.01',
149 base => 'XAS::Base',
150 mixin => 'XAS::Lib::Mixin::Handlers'
151 ;
152  
153  
154 =head1 DESCRIPTION
155  
156 This module provides exception handlers. It is implemented as a mixin.
157  
158 =head1 METHODS
159  
160 =head2 error_handler($ex)
161  
162 This method will write an 'error' entry to the current log. It takes
163 these parameters:
164  
165 =over 4
166  
167 =item B<$ex>
168  
169 The exception to handle.
170  
171 =back
172  
173 =head2 exception_hander($ex)
174  
175 The method will write an 'error' entry to the current log and send an
176 alert. It takes these parameters:
177  
178 =over 4
179  
180 =item B<$ex>
181  
182 The exception to handle.
183  
184 =back
185  
186 =head2 exit_handler($ex)
187  
188 The method will write an 'fatal' entry to the current log, send an
189 alert and return an exit code. It takes these parameters:
190  
191 =over 4
192  
193 =item B<$ex>
194  
195 The exception to handle.
196  
197 =back
198  
199 =head1 SEE ALSO
200  
201 =over 4
202  
203 =item L<XAS|XAS>
204  
205 =back
206  
207 =head1 AUTHOR
208  
209 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
210  
211 =head1 COPYRIGHT AND LICENSE
212  
213 Copyright (C) 2014 Kevin L. Esteb
214  
215 This is free software; you can redistribute it and/or modify it under
216 the terms of the Artistic License 2.0. For details, see the full text
217 of the license at http://www.perlfoundation.org/artistic_license_2_0.
218  
219 =cut
« blib/lib/XAS/Apps/Rotate.pm ↑ Summary blib/lib/XAS/Lib/SSH/Client/Shell.pm »