File Coverage

blib/lib/Error/SystemException.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2006,2009 -- leonerd@leonerd.org.uk
5              
6             package Error::SystemException;
7              
8 1     1   1210 use strict;
  1         3  
  1         48  
9 1     1   7 use warnings;
  1         2  
  1         44  
10              
11 1     1   15 use base qw( Error );
  1         2  
  1         342  
12              
13             our $VERSION = '0.05';
14              
15             =head1 NAME
16              
17             C - an L subclass to represent OS-thrown
18             errors.
19              
20             =head1 DESCRIPTION
21              
22             This exception is used to indicate errors returned by the operating system, or
23             underlying libraries. As well as a string error message, it also contains the
24             string form of C<$!> at the time the exception was thrown.
25              
26             =cut
27              
28             =head1 FUNCTIONS
29              
30             =cut
31              
32             =head2 $e = Error::SystemException->new( $message )
33              
34             This function constructs a new exception object and returns it. Normally this
35             function should not be necessary from most code, as it would be constructed
36             during the C<< Error->throw() >> method.
37              
38             throw Error::SystemException( "Something went wrong" );
39              
40             The value of C<$message> is passed as the C<-text> key to the superclass
41             constructor, and the numerical value of C<$!> at the time the exception object
42             is built is passed as the C<-value> key. The string value of C<$!> is also
43             stored in the object.
44              
45             =cut
46              
47             sub new
48             {
49 1     1 1 460 my $class = shift;
50 1         3 my $perror = "$!";
51 1         4 my $errno = $!+0;
52              
53 1         2 my ( $message ) = @_;
54              
55 1         3 local $Error::Depth = $Error::Depth + 1;
56              
57 1         11 my $self = $class->SUPER::new( -text => $message, -value => $errno );
58              
59 1         90 $self->{perror} = $perror;
60              
61 1         4 $self;
62             }
63              
64             =head2 $str = $self->perror
65              
66             This function returns the stored string value of Perl's C<$!> variable at the
67             time the exception object was created.
68              
69             =cut
70              
71             sub perror
72             {
73 3     3 1 720 my $self = shift;
74 3         18 return $self->{perror};
75             }
76              
77             sub stringify
78             {
79 2     2 1 330 my $self = shift;
80 2         11 return $self->SUPER::stringify() . " - " . $self->perror;
81             }
82              
83             # Keep perl happy; keep Britain tidy
84             1;
85              
86             __END__