blib/lib/Exception/ThrowUnless.pm

filter: Statementstmt 73.5% 64 / 87 Branchbran 56.6% 17 / 30 Conditioncond 16.6% 2 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 76.6% 23 / 30 Podpod 0.0% 0 / 18 totaltotal 58.1% 107 / 184 CC 19 SCAR 15.6
CC
19
Cov
64%
smkdir
14.9
srename_nc
12.0
ssuck
12.0
CRAP 4.8
↑ Summary
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.12";
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 7 ▶sub _throw(@) {
Subroutine _throw: called CC=1 SCAR=0.0
20 7 ▶ eval q[
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 13 ▶sub _checktrue($@) {
Subroutine _checktrue: called CC=2 SCAR=6.9
28 13 ▶ _throw splice(@_,1) unless $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 3 10 13
29 10 $_[0];
30 };
31 2054 ▶sub _checkdef($@) {
Subroutine _checkdef: called CC=2 SCAR=6.9
32 2054 ▶ _throw splice(@_,1) unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 2052 2054
33 2052 $_[0];
34 };
35 7 ▶sub schdir($){
Subroutine schdir: called CC=1 SCAR=0.0
Pod undocumented
36 7 _checktrue(chdir($_[0]),"chdir:$_[0]:$!");
37 };
38 3 ▶sub srmdir(;$) {
Subroutine srmdir: called CC=2 SCAR=6.9
Pod undocumented
39 3 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 2 3
40 3 _checktrue(rmdir($_),"rmdir:$_:$!\n");
41 };
42 3 ▶sub schmod(@) {
Subroutine schmod: called CC=2 SCAR=6.9
Pod undocumented
43 3 local $"=',';
44 3 ▶ return @_-1 if ( chmod(@_) == @_-1 );
Branch: 1 branch
BranchTrueFalseTotal
if chmod(@_) == @_ - 1 2 1 3
45 1 _throw("chmod:@_:$!");
46 };
47 2 ▶sub sclose(*){
Subroutine sclose: called CC=2 SCAR=6.9
Pod undocumented
48 2 local $_ = shift;
49 2 ▶ return 1 if close($_);
Branch: 1 branch
BranchTrueFalseTotal
if close $_ 1 1 2
50 1 die "close:$_:$!";
51 };
52 0 ▶sub sexec(@){
Subroutine sexec: not called CC=1 SCAR=6.9
Pod undocumented
53 0 exec @_;
54 0 die _throw "exec (@_):$!";
55 };
56 0 ▶sub sfork() {
Subroutine sfork: not called CC=1 SCAR=6.9
Pod undocumented
57 0 _checkdef(fork,"fork:$!");
58 };
59 0 ▶sub slink($$) {
Subroutine slink: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my ($f,$t) = @_;
61 0 _checkdef(link($f, $t),"link:$f,$t:$!");
62 };
63 5 ▶sub smkdir($$) {
Subroutine smkdir: called CC=5 SCAR=27.0
Pod undocumented
64 5 my ( $dir, $mode ) = @_;
65 5 my $res = mkdir $dir, $mode;
66 5 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 5 0 5
67 0 ▶ return $res if -d $dir && $! == 17;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir and $! == 17 0 0 0
Condition0%0/3
-d $dir and $! == 17
!ll&&!rl&&r
000
MC/DC0%0/2
-d $dir and $! == 17
-d $dir $! == 17
Truth table0%0/3
A and B
A= -d $dirB= $! == 17
ABresult
0X0
100
111
68 0 ▶ _throw "smkdir:$dir:$! and is not a directory" if $! == 17;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 17 0 0 0
69 0 _throw "smkdir:$dir:$!";
70 };
71 5 ▶sub sopen(\*$) {
Subroutine sopen: called CC=1 SCAR=0.0
Pod undocumented
72 5 _checkdef(open($_[0],$_[1]),"open:$_[0],$_[1]:$!");
73 };
74 0 ▶sub sopendir(\*$){
Subroutine sopendir: not called CC=1 SCAR=6.9
Pod undocumented
75 0 _checkdef(opendir($_[0],$_[1]),"opendir:$_[0],$_[1]:$!\n");
76 };
77 2046 ▶sub spipe(\*\*){
Subroutine spipe: called CC=1 SCAR=0.0
Pod undocumented
78 2046 _checkdef(pipe($_[0],$_[1]),"pipe:@_:$!");
79 };
80 1 ▶sub sreadlink($) {
Subroutine sreadlink: called CC=1 SCAR=0.0
Pod undocumented
81 1 _checkdef(readlink($_[0]),"readlink:$_[0]:$!");
82 };
83 0 ▶sub srename($$) {
Subroutine srename: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my ($f,$t) = @_;
85 0 _checkdef(rename($f,$t),"rename:$f,$t:$!");
86 };
87 0 ▶sub srename_nc($$) {
Subroutine srename_nc: not called CC=3 SCAR=24.8
Pod undocumented
88 0 my ($f,$t) = @_;
89 0 ▶ -e $t || -l $t && _throw "won't clobber '$t'";
Branch: 1 branch
BranchTrueFalseTotal
-e $t or -l $t and &_throw("won't clobber '${t}'") 0 0 0
Condition0%0/6
-e $t || -l $t && &_throw("won't clobber '${t}'")
l!l&&r!l&&!r
000
-l $t and &_throw("won't clobber '${t}'")
!ll&&!rl&&r
000
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}'")
ABCresult
1XX1
0111
00X0
0100
90 0 srename($f,$t);
91 };
92 2 ▶sub ssocketpair(\*\*$$$) {
Subroutine ssocketpair: called CC=1 SCAR=0.0
Pod undocumented
93 2 _checkdef(socketpair($_[0],$_[1],$_[2],$_[3],$_[4]),"socketpair:@_:$!");
94 };
95 sub ssuck(@);
96 0 ▶sub ssuck(@){
Subroutine ssuck: not called CC=3 SCAR=24.8
Pod undocumented
97 0 ▶ warn "useless ssuck in void context" unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
98 0 ▶ return join("",ssuck(@_)) unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
99 0 map { local $_="<$_"; sopen(local *F,$_); $_=[<F>]; sclose(*F);@$_; } @_;
100 };
101 3 ▶sub ssymlink($$) {
Subroutine ssymlink: called CC=1 SCAR=0.0
Pod undocumented
102 3 _checktrue(symlink($_[0],$_[1]),"symlink:$_[0],$_[1]:$!");
103 };
104 3 ▶sub sunlink(@) {
Subroutine sunlink: called CC=6 SCAR=18.1
Pod undocumented
105 3 ▶ unlink(@_) == @_ && return scalar(@_);
Branch: 1 branch
BranchTrueFalseTotal
unlink(@_) == @_ and return scalar @_ 1 2 3
106 2 for ( @_ ) {
107 2 ▶ -l $_ || -e $_ || next;
Branch: 1 branch
BranchTrueFalseTotal
-l $_ or -e $_ or next 1 1 2
Condition66%2/3
-l $_ or -e $_
l!l&&r!l&&!r
011
MC/DC50%1/2
-l $_ or -e $_
-l $_ -e $_
Truth table66%2/3
A or B
A= -l $_B= -e $_
ABresult
1X1
011
000
108 1 ▶ unlink($_) && next;
Branch: 1 branch
BranchTrueFalseTotal
unlink $_ and next 0 1 1
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
BranchTrueFalseTotal
unless caller 0 4 4
116 }
117 4 1;
118 __DATA__
↑ Summary