| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Exception::ThrowUnless; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | our(@ISA)=qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $VERSION = "1.11"; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 12 | schdir schmod sclose sexec sfork slink | ||||||||||||||||||||||||||||||||||||||||||
| 13 | smkdir sopen sopendir spipe sreadlink srename | ||||||||||||||||||||||||||||||||||||||||||
| 14 | srename_nc srmdir ssocketpair sspit ssuck ssymlink | ||||||||||||||||||||||||||||||||||||||||||
| 15 | sunlink | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub _throw(@) { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | eval q[ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | use Carp; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | *Exception::_throw = \&Carp::confess; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | goto &Carp::confess; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | die "$@"; | |||||||||||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | sub _checktrue($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | ▶ | _throw splice(@_,1) unless $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_checktrue: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _checkdef($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 2054 | ▶ | _throw splice(@_,1) unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_checkdef: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2052 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | sub schdir($){ | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | _checktrue(chdir($_[0]),"chdir:$_[0]:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schdir: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | sub srmdir(;$) { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | local $_ = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
srmdir: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | _checktrue(rmdir($_),"rmdir:$_:$!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | sub schmod(@) { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | local $"=','; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schmod: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | return @_-1 if ( chmod(@_) == @_-1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | _throw("chmod:@_:$!"); | |||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | sub sclose(*){ | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sclose: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | return 1 if close($_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | die "close:$_:$!"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | sub sexec(@){ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | exec @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sexec: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | die _throw "exec (@_):$!"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | sub sfork() { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | _checkdef(fork,"fork:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sfork: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | sub slink($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ($f,$t) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slink: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | _checkdef(link($f, $t),"link:$f,$t:$!"); | |||||||||||||||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | sub smkdir($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | my ( $dir, $mode ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smkdir: called CC=5 SCAR=27.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | my $res = mkdir $dir, $mode; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | ▶ | return $res if $res; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return $res if -d $dir && $! == 17; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $dir and $! == 17
MC/DC0%0/2
-d $dir and $! == 17
-d $dir
$! == 17
Truth table0%0/3
A and B
A= -d $dirB= $! == 17
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | _throw "smkdir:$dir:$! and is not a directory" if $! == 17; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | _throw "smkdir:$dir:$!"; | |||||||||||||||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | sub sopen(\*$) { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | _checkdef(open($_[0],$_[1]),"open:$_[0],$_[1]:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sopen: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | sub sopendir(\*$){ | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | _checkdef(opendir($_[0],$_[1]),"opendir:$_[0],$_[1]:$!\n"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sopendir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | sub spipe(\*\*){ | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 2046 | ▶ | _checkdef(pipe($_[0],$_[1]),"pipe:@_:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spipe: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | sub sreadlink($) { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | _checkdef(readlink($_[0]),"readlink:$_[0]:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sreadlink: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | sub srename($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my ($f,$t) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
srename: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | _checkdef(rename($f,$t),"rename:$f,$t:$!"); | |||||||||||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | sub srename_nc($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my ($f,$t) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
srename_nc: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | -e $t || -l $t && _throw "won't clobber '$t'"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
-e $t || -l $t && &_throw("won't clobber '${t}'")
-l $t and &_throw("won't clobber '${t}'")
MC/DC0%0/3
-e $t || -l $t && &_throw("won't clobber '${t}'")
-e $t
-l $t
&_throw("won't clobber '${t}'")
Truth table0%0/4
A || B and C
A= -e $tB= -l $tC= &_throw("won't clobber '${t}'")
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | srename($f,$t); | |||||||||||||||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | sub ssocketpair(\*\*$$$) { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | _checkdef(socketpair($_[0],$_[1],$_[2],$_[3],$_[4]),"socketpair:@_:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ssocketpair: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | sub ssuck(@); | ||||||||||||||||||||||||||||||||||||||||||
| 96 | sub ssuck(@){ | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | warn "useless ssuck in void context" unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ssuck: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return join("",ssuck(@_)) unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | map { local $_="<$_"; sopen(local *F,$_); $_=[<F>]; sclose(*F);@$_; } @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | sub ssymlink($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | ▶ | _checktrue(symlink($_[0],$_[1]),"symlink:$_[0],$_[1]:$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ssymlink: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | sub sunlink(@) { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | unlink(@_) == @_ && return scalar(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sunlink: called CC=6 SCAR=18.1
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | for ( @_ ) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | -l $_ || -e $_ || next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-l $_ or -e $_
MC/DC50%1/2
-l $_ or -e $_
-l $_
-e $_
Truth table66%2/3
A or B
A= -l $_B= -e $_
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | unlink($_) && next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | _throw "unlink:$_:$!"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | return scalar(@_); | |||||||||||||||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | ▶ | eval join("",<DATA>) unless caller; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 118 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||