File Coverage

blib/lib/Bio/Polloc/Polloc/Error.pm
Criterion Covered Total %
statement 15 43 34.8
branch 2 18 11.1
condition 2 6 33.3
subroutine 3 5 60.0
pod 3 3 100.0
total 25 75 33.3


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Bio::Polloc::Polloc::Error - Errors handler for the Bio::Polloc::* packages
4              
5             =head1 AUTHOR - Luis M. Rodriguez-R
6              
7             Email lmrodriguezr at gmail dot com
8              
9             =cut
10              
11             package Bio::Polloc::Polloc::Error;
12 12     12   65 use strict;
  12         19  
  12         472  
13 12     12   11174 use Error qw(:try);
  12         44209  
  12         71  
14             our $VERSION = 1.0503; # [a-version] from Bio::Polloc::Polloc::Version
15              
16              
17             @Bio::Polloc::Polloc::Error::ISA = qw( Error );
18              
19             =head1 PUBLIC METHODS
20              
21             Methods provided by the package
22              
23             =cut
24              
25             =head2 new
26              
27             The basic initialization method
28              
29             =over
30              
31             =item -text
32              
33             Text of the message
34              
35             =item -value
36              
37             Value or objected refered by the message
38              
39             =back
40              
41             =cut
42              
43             sub new {
44 1     1 1 11 my($class, @args) = @_;
45 1         3 my($text, $value);
46 1 50 33     10 if(@args % 2 == 0 && $args[0] =~ m/^-/){
47 1         5 my %params = @args;
48 1         3 $text = $params{'-text'};
49 1         3 $value = $params{'-value'};
50             }else{
51 0         0 $text = $args[0];
52 0         0 $value = $args[1];
53             }
54              
55 1 50 33     8 if(defined $value && !$value){
56 0 0       0 $value = length($value)==0 ? "\"\"" : "zero (0)";
57             }
58              
59 1         11 my $self = $class->SUPER::new( -text=>$text, -value=>$value );
60 1         611 return $self;
61             }
62              
63             =head2 stringify
64              
65             =cut
66              
67             sub stringify {
68 0     0 1   my($self, @args) = @_;
69 0           return $self->error_msg(@args);
70             }
71              
72             =head2 error_msg
73              
74             =cut
75              
76             sub error_msg {
77 0     0 1   my($self,@args) = @_;
78 0           my $msg = $self->text;
79              
80 0           my $value = $self->value;
81 0           my $bme = Bio::Polloc::Polloc::Root->new();
82 0           my $out = " ".("-"x10)." ERROR ".("-"x10)." \n";
83 0 0         if($msg=~/[\n]/){
84 0           $msg=~s/([\n])/$1\t/g;
85 0           $msg = "\n\t".$msg;
86             }
87 0           $out.= ref($self) . "\n";
88 0           $out.= "MSG: $msg.\n";
89 0 0         if(defined $value){
90 0 0         if(ref($value)=~/hash/i){
    0          
    0          
91 0           $out.= "VALUE: HASH: ".$_."=>".
92             (defined $value->{$_} ? $value->{$_} : "undef" ).
93 0 0         "\n" for keys %{$value};
94             }elsif(ref($value)=~/array/i){
95 0           $out.= "VALUE: ARRAY: ".join(", ",@{$value}) . "\n";
  0            
96             }elsif($value=~/[\n]/){
97 0           $value =~ s/([\n])/$1\t/g;
98 0           $out.= "VALUE:\n\t" . $value . "\n";
99             }else{
100 0           $out.= "VALUE: ".$value." - ".ref(\$value)."\n";
101             }
102             }
103 0           $out.= " ".("."x27)." \n";
104 0           $out.= $bme->stack_trace_dump();
105 0           $out.= " ".("-"x27)." \n";
106 0           return $out;
107             }
108              
109             =head1 CHILDREN
110              
111             Children objects included
112              
113             =head2 Bio::Polloc::Polloc::IOException
114              
115             I/O related error
116              
117             =cut
118              
119             @Bio::Polloc::Polloc::IOException::ISA = qw( Bio::Polloc::Polloc::Error );
120              
121             =head2 Bio::Polloc::Polloc::ParsingException
122              
123             Parsing error of some external file
124              
125             =cut
126              
127             @Bio::Polloc::Polloc::ParsingException::ISA = qw( Bio::Polloc::Polloc::Error );
128              
129             =head2 Bio::Polloc::Polloc::LoudWarningException
130              
131             Warning transformed into C<throw> due to a high verbosity
132              
133             =cut
134              
135             @Bio::Polloc::Polloc::LoudWarningException::ISA = qw( Bio::Polloc::Polloc::Error );
136              
137             =head2 Bio::Polloc::Polloc::NotLogicException
138              
139             =cut
140              
141             @Bio::Polloc::Polloc::NotLogicException::ISA = qw( Bio::Polloc::Polloc::Error );
142              
143             =head2 Bio::Polloc::Polloc::UnexpectedException
144              
145             An error probably due to an internal bug
146              
147             =cut
148              
149             @Bio::Polloc::Polloc::UnexpectedException::ISA = qw( Bio::Polloc::Polloc::Error );
150              
151             =head2 Bio::Polloc::Polloc::NotImplementedException
152              
153             Error launched when a method is called from an object
154             not implementing it, despite it is defined by at least
155             one parent interface
156              
157             =cut
158              
159             @Bio::Polloc::Polloc::NotImplementedException::ISA = qw( Bio::Polloc::Polloc::Error );
160              
161             1;