blib/lib/File/FcntlLock/Errors.pm

filter: Statementstmt 87.0% 47 / 54 Branchbran 42.3% 11 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 67.7% 63 / 93 CC 14 SCAR 21.5
CC
14
Cov
72%
BEGIN
13.1
get_error
6.0
system_error
6.0
CRAP 8.6
↑ Summary blib/lib/File/FcntlLock.pm »
1 # -*- cperl -*-
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the same terms as Perl itself.
5 #
6 # Copyright (C) 2002-2014 Jens Thoms Toerring <jt@toerring.de>
7  
8  
9 # Helper package for File::FcntLock::Core for handling error messages
10  
11 package File::FcntlLock::Errors;
12  
13  
14 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Errno;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 4 my %fcntl_error_texts;
21  
22  
23 4 ▶BEGIN {
Subroutine BEGIN: called CC=12 SCAR=25.7
24 # Set up a hash with the error messages, but only for errno's that Errno
25 # knows about. The texts represent what is written in SUSv3 and in the
26 # man pages for Linux, TRUE64, OpenBSD3 and Solaris8.
27  
28 4 my $err;
29  
30 4 ▶ if ( $err = eval { &Errno::EACCES } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EACCES } }) 4 0 4
31 4 $fcntl_error_texts{ $err } = "File or segment already locked " .
32 "by other process(es) or file is " .
33 "mmap()ed to virtual memory";
34 }
35  
36 4 ▶ if ( $err = eval { &Errno::EAGAIN } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EAGAIN } }) 4 0 4
37 4 $fcntl_error_texts{ $err } = "File or segment already locked " .
38 "by other process(es)";
39 }
40  
41 4 ▶ if ( $err = eval { &Errno::EBADF } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EBADF } }) 4 0 4
42 4 $fcntl_error_texts{ $err } = "Not an open file or not opened for " .
43 "writing (with F_WRLCK) or reading " .
44 "(with F_RDLCK)";
45 }
46  
47 4 ▶ if ( $err = eval { &Errno::EDEADLK } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EDEADLK } }) 4 0 4
48 4 $fcntl_error_texts{ $err } = "Operation would cause a deadlock";
49 }
50  
51 4 ▶ if ( $err = eval { &Errno::EFAULT } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EFAULT } }) 4 0 4
52 4 $fcntl_error_texts{ $err } = "Lock outside accessible address space " .
53 "or to many locked regions";
54 }
55  
56 4 ▶ if ( $err = eval { &Errno::EINTR } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EINTR } }) 4 0 4
57 4 $fcntl_error_texts{ $err } = "Operation interrupted by a signal";
58 }
59  
60 4 ▶ if ( $err = eval { &Errno::ENOLCK } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::ENOLCK } }) 4 0 4
61 4 $fcntl_error_texts{ $err } = "Too many segment locks open, lock " .
62 "table full or remote locking protocol " .
63 "failure (e.g. NFS)";
64 }
65  
66 4 ▶ if ( $err = eval { &Errno::EINVAL } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EINVAL } }) 4 0 4
67 4 $fcntl_error_texts{ $err } = "Illegal parameter or file does not " .
68 "support locking";
69 }
70  
71 4 ▶ if ( $err = eval { &Errno::EOVERFLOW } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::EOVERFLOW } }) 4 0 4
72 4 $fcntl_error_texts{ $err } = "One of the parameters to be returned " .
73 "can not be represented correctly";
74 }
75  
76 4 ▶ if ( $err = eval { &Errno::ENETUNREACH } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::ENETUNREACH } }) 4 0 4
77 4 $fcntl_error_texts{ $err } = "File is on remote machine that can " .
78 "not be reached anymore";
79 }
80  
81 4 ▶ if ( $err = eval { &Errno::ENOLINK } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err = eval { do { &Errno::ENOLINK } }) 4 0 4
82 4 $fcntl_error_texts{ $err } = "File is on remote machine that can " .
83 "not be reached anymore";
84 }
85 }
86  
87  
88 ###########################################################
89 # Function for converting an errno to a useful, human readable
90 # message.
91  
92 0 ▶sub get_error {
Subroutine get_error: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my ( $self, $err ) = @_;
94 return $self->{ error } =
95 0 ▶ defined $fcntl_error_texts{ $err } ? $fcntl_error_texts{ $err }
Branch: 1 branch
BranchTrueFalseTotal
defined $fcntl_error_texts{$err} ? : 0 0 0
96 : "Unexpected error: $!";
97 }
98  
99  
100 ###########################################################
101 # Method returns the error number from the latest call of the
102 # derived classes lock() function. If the last call did not
103 # result in an error the method returns undef.
104  
105 0 ▶sub lock_errno {
Subroutine lock_errno: not called CC=1 SCAR=6.9
Pod undocumented
106 0 return shift->{ errno };
107 }
108  
109  
110 ###########################################################
111 # Method returns a short description of the error that happenend
112 # on the latest call of derived classes lock() method with the
113 # object. If there was no error the method returns undef.
114  
115 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
116 0 return shift->{ error };
117 }
118  
119  
120 ###########################################################
121 # Method returns the "normal" system error message associated
122 # with errno. The method returns undef if there was no error.
123  
124 0 ▶sub system_error {
Subroutine system_error: not called CC=2 SCAR=17.9
Pod undocumented
125 0 local $!;
126 0 my $self = shift;
127 0 ▶ return $self->{ errno } ? $! = $self->{ errno } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'errno'} ? : 0 0 0
128 }
129  
130  
131 4 1;
132  
133  
134 # Local variables:
135 # tab-width: 4
136 # indent-tabs-mode: nil
137 # End:
↑ Summary blib/lib/File/FcntlLock.pm »