| 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)
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | $path =~ s/^~([^\/]*)/$1 ? (getpwnam($1))[7] : (getpwuid($>))[7]/e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$! == 4 and not $result
MC/DC0%0/2
$! == 4 and not $result
$! == 4
not $result
Truth table0%0/3
A and not(B)
A= $! == 4B= not $result
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | defined $buffer || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'buffer' }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $length ||= length ( $buffer ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$length ||= length $buffer
MC/DC0%0/2
$length ||= length $buffer
$length
length $buffer
Truth table0%0/3
A ||= B
A= $lengthB= length $buffer
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my ( $origLength, $itemLength ) = ( $length ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | while ( $length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 0 | $length -= $itemLength; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | $buffer = substr ( $buffer, $itemLength ) if $length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | defined $itemLength ? $origLength : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | defined $buffer || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'buffer' }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $length ||= length ( $buffer ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$length ||= length $buffer
MC/DC0%0/2
$length ||= length $buffer
$length
length $buffer
Truth table0%0/3
A ||= B
A= $lengthB= length $buffer
| |||||||||||||||||||||||||||||
| 56 | 0 | $$buffer = ''; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my ( $origLength, $itemLength ) = ( $length ); | |||||||||||||||||||||||||||
| 59 | 0 | my $subBuffer; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | while ( $length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | 0 | $length -= $itemLength; | |||||||||||||||||||||||||||
| 66 | 0 | $$buffer .= $subBuffer; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | defined $itemLength ? $origLength : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
$_{'srcFile'} || die('safeCopy(): srcFile required')
$_{'srcFile'}
Truth table0%0/2
A
A= $_{'srcFile'}
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $toName = $_{dstFile} || die "safeCopy(): dstFile required"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_{'dstFile'} || die('safeCopy(): dstFile required')
MC/DC0%0/1
$_{'dstFile'} || die('safeCopy(): dstFile required')
$_{'dstFile'}
Truth table0%0/2
A
A= $_{'dstFile'}
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $bufferSize = $_{bufferSize} || 128; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_{'bufferSize'} || 128
MC/DC0%0/1
$_{'bufferSize'} || 128
$_{'bufferSize'}
Truth table0%0/2
A
A= $_{'bufferSize'}
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $tmpMask = $_{tmpMask} || "$toName.$$.\%s"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_{'tmpMask'} || "$toName.${$}.%s"
MC/DC0%0/1
$_{'tmpMask'} || "$toName.${$}.%s"
$_{'tmpMask'}
Truth table0%0/2
A
A= $_{'tmpMask'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | $fromFileNum = fileno ( FROMFILE ); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | die "flock ( $fromFileNum ): $!" unless flock ( FROMFILE, LOCK_SH ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $i = 0; while ( 1 ) { last unless -f ( $tmpToName = sprintf ( $tmpMask, $i++ ) ); } # ATT! XXX EINTR && -f ??? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | last unless $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( *FROMFILE ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | warn "close ( $fromFileNum ): $!" unless safeCall sub { close ( FROMFILE ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( *TOFILE ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | warn "close ( $toFileNum ): $!" unless safeCall sub { close ( TOFILE ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( $@ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | warn "unlink( $tmpToName ): $!" unless safeCall sub { unlink ( $tmpToName ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | die "rename ( $tmpToName, $toName ): $!" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return $line unless $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $result[1] = '' if ( ( m/=/ ) && ( ! defined $result[1] ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/=/ and not defined $result[1]
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]
| |||||||||||||||||||||||||||||
| 175 | 0 | @result; } split /:/, $command; | |||||||||||||||||||||||||||
| 176 | 0 | @params; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | 1; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||