File Coverage

blib/lib/Error/Exception.pm
Criterion Covered Total %
statement 12 33 36.3
branch 0 8 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 1 1 100.0
total 17 51 33.3


line stmt bran cond sub pod time code
1             # Copyright (C) 2008 Stephen Vance
2             #
3             # This library is free software; you can redistribute it and/or
4             # modify it under the terms of the Perl Artistic License.
5             #
6             # This library is distributed in the hope that it will be useful,
7             # but WITHOUT ANY WARRANTY; without even the implied warranty of
8             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Perl
9             # Artistic License for more details.
10             #
11             # You should have received a copy of the Perl Artistic License along
12             # with this library; if not, see:
13             #
14             # http://www.perl.com/language/misc/Artistic.html
15             #
16             # Designed and written by Stephen Vance (steve@vance.com) on behalf
17             # of The MathWorks, Inc.
18              
19             package Error::Exception;
20              
21 1     1   21083 use strict;
  1         3  
  1         41  
22 1     1   5 use warnings;
  1         2  
  1         26  
23              
24 1     1   908 use Exception::Class;
  1         17425  
  1         6  
25 1     1   43 use base qw( Error Exception::Class::Base );
  1         2  
  1         991  
26              
27             our $VERSION = '1.1';
28              
29             # This "no critic" is open because I couldn't find the policy name
30             sub new { ## no critic
31 0     0 1   my $class = shift;
32              
33 0           local $Error::Depth = $Error::Depth + 1; ## no critic 'Dynamic::ValidateAgainstSymbolTable'
34              
35 0           my $self = $class->SUPER::new(@_);
36              
37 0           $self->{'-text'} = $self->_stringify();
38 0           return $self;
39             }
40              
41             sub _stringify {
42 0     0     my $self = shift;
43            
44 0           my $text = ref( $self ) . ' thrown in ' . $self->file
45             . ' at line ' . $self->line . "\n";
46 0           my $msg = $self->{'-text'};
47 0 0 0       if( defined( $msg ) && length( $msg ) > 0 ) {
48 0           $text .= "with message <<" . $msg . ">>\n";
49             }
50              
51 0           my @fields = $self->Fields();
52 0 0         if( scalar @fields > 0 ) {
53 0           $text .= "with fields:\n";
54 0           for my $field ( @fields ) {
55 0           my $value = $self->$field();
56 0 0         if( ! defined( $value ) ) {
    0          
57 0           $value = 'undef';
58             }
59             elsif( ref( $value ) eq 'ARRAY' ) {
60 0           $value = '[ ' . join( "\n", @{$value} ) . ' ]';
  0            
61             }
62             # Don't expect hashes or objects
63 0           $text .= "\t" . $field . " = '" . $value . "'\n";
64             }
65             }
66              
67 0           return $text;
68             }
69              
70             1;
71             __END__