RRP/Toolkit.pm

filter: Statementstmt 12.2% 14 / 114 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 13.6% 3 / 22 Podpod 55.5% 5 / 9 totaltotal 8.8% 22 / 248 CC 45 SCAR 51.1
CC
45
Cov
7%
safeCopy
462.0
safeWrite
72.0
safeRead
56.0
CRAP 165.2
↑ Summary RRP/Codec.pm »
1 package Net::RRP::Toolkit;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Errno;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Fcntl ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require Exporter;
7  
8 1 @Net::RRP::Toolkit::ISA = qw(Exporter);
9 1 @Net::RRP::Toolkit::EXPORT_OK = qw(decodeTilde safeCall safeCopy lowerKeys pathSubtract);
10 1 $Net::RRP::Toolkit::VERSION = (split " ", '# $Id: Toolkit.pm,v 1.3 2000/10/04 08:05:37 mkul Exp $ ')[3];
11  
12 sub decodeTilde
13 0 ▶{
Subroutine decodeTilde: not called CC=3 SCAR=24.8
Pod documented
14 0 ▶ my $path = shift || return undef;
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
15 0 ▶ $path =~ s/^~([^\/]*)/$1 ? (getpwnam($1))[7] : (getpwuid($>))[7]/e;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
16 0 $path;
17 }
18  
19 sub safeCall
20 0 ▶{
Subroutine safeCall: not called CC=3 SCAR=24.8
Pod documented
21 0 my $codeRef = shift;
22 0 my $result = &$codeRef;
23 0 ▶ while ( ( $! == Errno::EINTR ) && ( ! $result ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 4 and not $result) 0 0 0
Condition0%0/3
$! == 4 and not $result
!ll&&!rl&&r
000
MC/DC0%0/2
$! == 4 and not $result
$! == 4 not $result
Truth table0%0/3
A and not(B)
A= $! == 4B= not $result
ABresult
0X0
100
111
24 {
25 0 $result = &$codeRef;
26 }
27 0 $result;
28 }
29  
30 sub safeWrite
31 0 ▶{
Subroutine safeWrite: not called CC=8 SCAR=42.8
Pod undocumented
32 0 my ( $handler, $buffer, $length ) = @_;
33 0 ▶ $handler || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'hander' };
Branch: 1 branch
BranchTrueFalseTotal
$handler or "ZError"->raise("MISSING_MANDATORY_PARAM", {"name", "hander"}) 0 0 0
34 0 ▶ defined $buffer || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'buffer' };
Branch: 1 branch
BranchTrueFalseTotal
defined $buffer or "ZError"->raise("MISSING_MANDATORY_PARAM", {"name", "buffer"}) 0 0 0
35 0 ▶ $length ||= length ( $buffer );
Condition0%0/3
$length ||= length $buffer
l!l&&r!l&&!r
000
MC/DC0%0/2
$length ||= length $buffer
$length length $buffer
Truth table0%0/3
A ||= B
A= $lengthB= length $buffer
ABresult
1X1
011
000
36  
37 0 my ( $origLength, $itemLength ) = ( $length );
38  
39 0 ▶ while ( $length )
Branch: 1 branch
BranchTrueFalseTotal
if ($length) 0 0 0
40 {
41 0 ▶ $itemLength = Net::RRP::Toolkit::safeCall ( sub { $handler->syswrite ( $buffer, $length ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 ▶ last unless $itemLength;
Branch: 1 branch
BranchTrueFalseTotal
unless $itemLength 0 0 0
43 0 $length -= $itemLength;
44 0 ▶ $buffer = substr ( $buffer, $itemLength ) if $length;
Branch: 1 branch
BranchTrueFalseTotal
if $length 0 0 0
45 }
46  
47 0 ▶ defined $itemLength ? $origLength : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $itemLength ? : 0 0 0
48 }
49  
50 sub safeRead
51 0 ▶{
Subroutine safeRead: not called CC=7 SCAR=40.3
Pod undocumented
52 0 my ( $handler, $buffer, $length ) = @_;
53 0 ▶ $handler || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'hander' };
Branch: 1 branch
BranchTrueFalseTotal
$handler or "ZError"->raise("MISSING_MANDATORY_PARAM", {"name", "hander"}) 0 0 0
54 0 ▶ defined $buffer || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'buffer' };
Branch: 1 branch
BranchTrueFalseTotal
defined $buffer or "ZError"->raise("MISSING_MANDATORY_PARAM", {"name", "buffer"}) 0 0 0
55 0 ▶ $length ||= length ( $buffer );
Condition0%0/3
$length ||= length $buffer
l!l&&r!l&&!r
000
MC/DC0%0/2
$length ||= length $buffer
$length length $buffer
Truth table0%0/3
A ||= B
A= $lengthB= length $buffer
ABresult
1X1
011
000
56 0 $$buffer = '';
57  
58 0 my ( $origLength, $itemLength ) = ( $length );
59 0 my $subBuffer;
60  
61 0 ▶ while ( $length )
Branch: 1 branch
BranchTrueFalseTotal
if ($length) 0 0 0
62 {
63 0 ▶ $itemLength = Net::RRP::Toolkit::safeCall ( sub { $handler->sysread ( $subBuffer, $length ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ last unless $itemLength;
Branch: 1 branch
BranchTrueFalseTotal
unless $itemLength 0 0 0
65 0 $length -= $itemLength;
66 0 $$buffer .= $subBuffer;
67 }
68  
69 0 ▶ defined $itemLength ? $origLength : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $itemLength ? : 0 0 0
70 }
71  
72 sub safeCopy
73 0 ▶{
Subroutine safeCopy: not called CC=21 SCAR=61.4
Pod documented
74 0 ▶ my $fromName = $_{srcFile} || die "safeCopy(): srcFile required";
Condition0%0/2
$_{'srcFile'} || die('safeCopy(): srcFile required')
l!l
00
MC/DC0%0/1
$_{'srcFile'} || die('safeCopy(): srcFile required')
$_{'srcFile'}
Truth table0%0/2
A
A= $_{'srcFile'}
Aresult
11
00
75 0 ▶ my $toName = $_{dstFile} || die "safeCopy(): dstFile required";
Condition0%0/2
$_{'dstFile'} || die('safeCopy(): dstFile required')
l!l
00
MC/DC0%0/1
$_{'dstFile'} || die('safeCopy(): dstFile required')
$_{'dstFile'}
Truth table0%0/2
A
A= $_{'dstFile'}
Aresult
11
00
76  
77 0 ▶ my $bufferSize = $_{bufferSize} || 128;
Condition0%0/2
$_{'bufferSize'} || 128
l!l
00
MC/DC0%0/1
$_{'bufferSize'} || 128
$_{'bufferSize'}
Truth table0%0/2
A
A= $_{'bufferSize'}
Aresult
11
00
78 0 ▶ my $tmpMask = $_{tmpMask} || "$toName.$$.\%s";
Condition0%0/2
$_{'tmpMask'} || "$toName.${$}.%s"
l!l
00
MC/DC0%0/1
$_{'tmpMask'} || "$toName.${$}.%s"
$_{'tmpMask'}
Truth table0%0/2
A
A= $_{'tmpMask'}
Aresult
11
00
79
80 0 local ( *FROMFILE, *TOFILE ) = ( undef, undef );
81 0 my ( $fromFileNum, $toFileNum, $tmpToName ) = ( 0, 0, '' );
82
83 eval
84 0 {
85 die "sysopen ( $fromName, \"r\" ): $!"
86 0 ▶ unless safeCall sub { sysopen ( FROMFILE, $fromName, "r" ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless safeCall(sub { sysopen FROMFILE, $fromName, "r"; } ) 0 0 0
87
88 0 $fromFileNum = fileno ( FROMFILE );
89
90 0 ▶ die "flock ( $fromFileNum ): $!" unless flock ( FROMFILE, LOCK_SH );
Branch: 1 branch
BranchTrueFalseTotal
unless flock FROMFILE, 1 0 0 0
91
92 0 my @stat;
93 0 ▶ die "stat ( $fromFileNum ): $!" unless ( @stat = safeCall sub { stat ( FROMFILE ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless @stat = safeCall(sub { stat FROMFILE; } ) 0 0 0
94
95 0 ▶ my $i = 0; while ( 1 ) { last unless -f ( $tmpToName = sprintf ( $tmpMask, $i++ ) ); } # ATT! XXX EINTR && -f ???
Branch: 1 branch
BranchTrueFalseTotal
unless -f ($tmpToName = sprintf($tmpMask, $i++)) 0 0 0
96
97 die "sysopen ( $tmpToName, \"w\", $stat[2] ): $!"
98 0 ▶ unless safeCall sub { sysopen ( TOFILE, "$tmpToName", "w", $stat[2] ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless safeCall(sub { sysopen TOFILE, "$tmpToName", "w", $stat[2]; } ) 0 0 0
99
100 0 $toFileNum = fileno ( TOFILE );
101
102 0 my ( $n, $buffer );
103
104 0 while ( 1 )
105 {
106 die "sysread ( $fromFileNum, buffer, $bufferSize): $!"
107 0 ▶ unless defined ( $n = safeCall sub { sysread ( FROMFILE, $buffer, $bufferSize ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined($n = safeCall(sub { sysread FROMFILE, $buffer, $bufferSize; } )) 0 0 0
108
109 0 ▶ last unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
110
111 die "syswrite ( $toFileNum, buffer, $n): $!"
112 0 ▶ unless safeCall sub { syswrite ( TOFILE, $buffer, $n ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless safeCall(sub { syswrite TOFILE, $buffer, $n; } ) 0 0 0
113 }
114 };
115
116 0 ▶ if ( *FROMFILE )
Branch: 1 branch
BranchTrueFalseTotal
if (*FROMFILE) 0 0 0
117 {
118 0 ▶ warn "close ( $fromFileNum ): $!" unless safeCall sub { close ( FROMFILE ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless safeCall(sub { close FROMFILE; } ) 0 0 0
119 }
120
121 0 ▶ if ( *TOFILE )
Branch: 1 branch
BranchTrueFalseTotal
if (*TOFILE) 0 0 0
122 {
123 0 ▶ warn "close ( $toFileNum ): $!" unless safeCall sub { close ( TOFILE ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless safeCall(sub { close TOFILE; } ) 0 0 0
124 0 ▶ if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
125 {
126 0 ▶ warn "unlink( $tmpToName ): $!" unless safeCall sub { unlink ( $tmpToName ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless safeCall(sub { unlink $tmpToName; } ) 0 0 0
127 }
128 }
129
130 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
131
132 0 ▶ die "rename ( $tmpToName, $toName ): $!"
Branch: 1 branch
BranchTrueFalseTotal
unless rename $tmpToName, $toName 0 0 0
133 unless rename ( $tmpToName, $toName );
134
135 0 1;
136 }
137  
138 sub lowerKeys
139 0 ▶{
Subroutine lowerKeys: not called CC=2 SCAR=17.9
Pod documented
140 0 my $record = shift;
141 0 my $lcRecord;
142 0 foreach ( keys %$record )
143 {
144 0 $lcRecord->{ lc ( $_ ) } = $record->{ $_ };
145 }
146 0 $lcRecord;
147 }
148  
149 sub pathSubtract
150 0 ▶{
Subroutine pathSubtract: not called CC=2 SCAR=17.9
Pod documented
151 0 my @s1 = split '/', shift; my @s2 = split '/', shift;
152 0 ▶ my $i = 0; for ( ; $s1 [ $i ] eq $s2 [ $i ] ; $i++ ) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($s1[$i] eq $s2[$i]) 0 0 0
153 0 "../" x ( $#s1 - $i + 1 ) . join '/', @s2 [ $i .. $#s2 ];
154 }
155  
156 sub strip
157 0 ▶{
Subroutine strip: not called CC=3 SCAR=24.8
Pod undocumented
158 0 my $line = shift;
159 0 ▶ return undef unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
160 0 ▶ return $line unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
161 0 study $line;
162 0 $line =~ s/^ +//g;
163 0 $line =~ s/ +$//g;
164 0 $line =~ s/^\t+//g;
165 0 $line =~ s/\t+$//g;
166 0 $line;
167 }
168  
169 sub decodeQueueCommand
170 0 ▶{
Subroutine decodeQueueCommand: not called CC=4 SCAR=30.0
Pod undocumented
171 0 my $command = shift;
172 0 my @params = map { my @result = split /=/, $_;
173 0 ▶ $result[0] = '' unless defined $result[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result[0] 0 0 0
174 0 ▶ $result[1] = '' if ( ( m/=/ ) && ( ! defined $result[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
if /=/ and not defined $result[1] 0 0 0
Condition0%0/3
/=/ and not defined $result[1]
!ll&&!rl&&r
000
MC/DC0%0/2
/=/ and not defined $result[1]
/=/ not defined $result[1]
Truth table0%0/3
A and not(B)
A= /=/B= not defined $result[1]
ABresult
0X0
100
111
175 0 @result; } split /:/, $command;
176 0 @params;
177 }
178  
179 1 1;
180  
181 __END__
↑ Summary RRP/Codec.pm »