blib/lib/CopyTree/VendorProof/LocalFileOp.pm

filter: Statementstmt 99.1% 118 / 119 Branchbran 66.6% 36 / 54 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 17 / 17 Podpod 100% 9 / 9 totaltotal 87.3% 187 / 214 CC 34 SCAR 18.0
CC
34
Cov
87%
fdls
13.1
cust_rmdir
8.1
read_into_memory
4.1
CRAP 6.1
↑ Summary
1 package CopyTree::VendorProof::LocalFileOp;
2  
3 1 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 #our @ISA = qw(CopyTree::VendorProof); #if this weren't commented out, the use base below won't work
8  
9 1 our $VERSION = '0.0013';
10 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use base qw(CopyTree::VendorProof);#for the @ISAs
Subroutine BEGIN: called CC=1 SCAR=0.0
15 #use base happens at compile time, so we don't get the runtime error of our, saying that
16 #Can't locate package CopyTree::VendorProof for @SharePoint::SOAPHandler::ISA at (eval 8) line 2.
17  
18  
19 # Preloaded methods go here.
20  
21 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod documented
22 1 my $class =shift;
23 1 my $path = shift;
24 1 ▶ $path =~s/\/$// unless (!$path or $path eq '/');
Branch: 1 branch
BranchTrueFalseTotal
unless not $path or $path eq "/" 0 1 1
Condition33%1/3
not $path or $path eq "/"
l!l&&r!l&&!r
100
MC/DC0%0/2
not $path or $path eq "/"
not $path $path eq "/"
Truth table33%1/3
not(A) or B
A= not $pathB= $path eq "/"
ABresult
1X1
011
000
25 1 my $hashref;
26 1 $hashref = bless {path => $path}, $class;
27 1 return $hashref;
28 }
29  
30 #lists files and / or dirs of a dir
31 7 ▶sub fdls {
Subroutine fdls: called CC=12 SCAR=25.7
Pod documented
32 7 my $inst = shift;
33
34 7 ▶ unless (ref $inst ){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $inst) 0 7 7
35 0 Carp::croak("fdls item must be an instance, not a class\n");
36 }
37 7 my $lsoption =shift;
38 7 my $path =shift;
39 7 ▶ $path =~s/\/$// unless (!$path or $path eq '/'); #removes trailing /
Branch: 1 branch
BranchTrueFalseTotal
unless not $path or $path eq "/" 7 0 7
Condition33%1/3
not $path or $path eq "/"
l!l&&r!l&&!r
007
MC/DC0%0/2
not $path or $path eq "/"
not $path $path eq "/"
Truth table33%1/3
not(A) or B
A= not $pathB= $path eq "/"
ABresult
1X1
011
000
40  
41 7 ▶ $lsoption ='' if !($lsoption);
Branch: 1 branch
BranchTrueFalseTotal
unless $lsoption 0 7 7
42 7 ▶ $path = $inst ->SUPER::path if (!$path);
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 7 7
43 7 my $dirH;
44 7 ▶ opendir ($dirH, $path) or Carp::carp ("ERROR in local_ls cannot open dirH to $path $!\n");
Branch: 1 branch
BranchTrueFalseTotal
opendir $dirH, $path or Carp::carp("ERROR in local_ls cannot open dirH to $path $!\n") 7 0 7
45 7 my @itemsnoparent =readdir $dirH;
46 7 closedir $dirH;
47 7 my @results;
48 my @files;
49 7 my @dirs;
50 7 for (@itemsnoparent){
51 74 ▶ next if ($_ eq '.' or $_ eq '..');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "." or $_ eq ".." 14 60 74
Condition100%3/3
$_ eq "." or $_ eq ".."
l!l&&r!l&&!r
7760
MC/DC100%2/2
$_ eq "." or $_ eq ".."
$_ eq "." $_ eq ".."
Truth table100%3/3
A or B
A= $_ eq "."B= $_ eq ".."
ABresult
1X1
011
000
52 60 ▶ push @files, $path.'/'.$_ if (-f "$path/$_");
Branch: 1 branch
BranchTrueFalseTotal
if -f "$path/$_" 44 16 60
53 60 ▶ push @dirs, $path.'/'.$_ if (-d "$path/$_");
Branch: 1 branch
BranchTrueFalseTotal
if -d "$path/$_" 16 44 60
54 }
55 7 $inst ->SUPER::fdls_ret ($lsoption, \@files, \@dirs);
56 }
57  
58 26 ▶sub is_fd{
Subroutine is_fd: called CC=4 SCAR=13.9
Pod documented
59 26 my $class_inst=shift;
60 26 my $query = shift;
61 26 ▶ if (-d $query){
Branch: 2 branches
BranchTrueFalseTotal
if (-d $query) { } 6 20 26
elsif (-f $query) { } 12 8 20
62 6 return 'd';
63 }
64 elsif (-f $query){
65 12 return 'f';
66 }
67 else {
68 8 my $parent = File::Basename::dirname($query);
69 8 ▶ if (-d $parent){
Branch: 1 branch
BranchTrueFalseTotal
if (-d $parent) { } 7 1 8
70 7 return 'pd';
71 }
72 1 else{return 0}
73 }
74 }
75 #memory is a ref to a scalar, in bin mode
76 1 ▶sub read_into_memory{
Subroutine read_into_memory: called CC=4 SCAR=14.0
Pod documented
77 1 my $inst=shift;
78 1 my $sourcepath = shift;
79 1 ▶ $sourcepath =~s/\/$// unless $sourcepath eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless $sourcepath eq "/" 1 0 1
80 1 ▶ $sourcepath=$inst->SUPER::path if (!$sourcepath);
Branch: 1 branch
BranchTrueFalseTotal
unless $sourcepath 0 1 1
81 1 my $binfile;
82 1 ▶ open my $readFH, "<", $sourcepath or Carp::carp("cannot read sourcepath [$sourcepath] $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $readFH, "<", $sourcepath or Carp::carp("cannot read sourcepath [$sourcepath] $!\n") 1 0 1
83 1 binmode ($readFH);
84 {#slurp
85 1 local $/ =undef;
86 1 $binfile = <$readFH>;
87 }
88 1 close $readFH;
89 1 return \$binfile;
90  
91 }
92 #memory is a ref to a scalar, in bin mode
93 1 ▶sub write_from_memory{
Subroutine write_from_memory: called CC=3 SCAR=11.1
Pod documented
94 1 my $inst=shift;
95 1 my $bincontentref = shift;
96 1 my $dest = shift;
97 1 ▶ $dest = $inst ->SUPER::path if (!$dest);
Branch: 1 branch
BranchTrueFalseTotal
unless $dest 0 1 1
98 1 ▶ open my $outFH, ">","$dest" or Carp::carp("cannot write to dest [$dest] $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $outFH, ">", "$dest" or Carp::carp("cannot write to dest [$dest] $!\n") 1 0 1
99 1 binmode ($outFH);
100 1 print $outFH $$bincontentref ;
101 1 close $outFH;
102  
103  
104 }
105  
106 6 ▶sub copy_local_files {
Subroutine copy_local_files: called CC=3 SCAR=11.0
Pod documented
107 6 my $inst = shift;
108 6 my $source = shift;
109 6 my $dest = shift;
110 6 ▶ open my $inFH, "<", $source or Carp::carp( "cannot open source fh $source $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $inFH, "<", $source or Carp::carp("cannot open source fh $source $!\n") 6 0 6
111 6 ▶ open my $ouFH, ">", $dest or Carp::carp( "cannot open dest fh $dest $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $ouFH, ">", $dest or Carp::carp("cannot open dest fh $dest $!\n") 6 0 6
112 6 binmode ($inFH);
113 6 binmode ($ouFH);
114 {
115 6 local $/=undef; #slurp
116 6 my $content = <$inFH>;
117 6 print $ouFH $content;
118 }
119 6 close $inFH;
120 6 close $ouFH;
121 }
122  
123 4 ▶sub cust_mkdir{
Subroutine cust_mkdir: called CC=3 SCAR=11.0
Pod documented
124 4 my $inst = shift;
125 4 my $path = shift;
126 4 ▶ Carp::croak( "should not be mkdiring a root [/]\n" )unless $path ne '/';
Branch: 1 branch
BranchTrueFalseTotal
unless $path ne "/" 1 3 4
127 3 $path =~s/\/$// ; # purposefully disallow mkdir / unless $path eq '/';
128 3 ▶ mkdir $path or Carp::carp ("cannot mkdir $path $!\n");
Branch: 1 branch
BranchTrueFalseTotal
mkdir $path or Carp::carp("cannot mkdir $path $!\n") 3 0 3
129  
130 }
131 4 ▶sub cust_rmdir{
Subroutine cust_rmdir: called CC=8 SCAR=20.9
Pod documented
132 4 my $inst = shift;
133 4 my $path = shift;
134 4 ▶ Carp::croak( "should not be rmdiring a root [/]\n" )unless $path ne '/';
Branch: 1 branch
BranchTrueFalseTotal
unless $path ne "/" 1 3 4
135 3 $path =~s/\/$// ; # purposefully disallow rmdir / unless $path eq '/';
136 3 ▶ unless (rmdir $path){
Branch: 1 branch
BranchTrueFalseTotal
unless (rmdir $path) 3 0 3
137 3 Carp::carp( "the dir [$path] you want to remove is NOT EMPTY $!\n");
138 3 ▶ Carp::croak( "wait. you told me to delete something that's not a dir. I'll stop for your protection.\n") if (! -d $path);
Branch: 1 branch
BranchTrueFalseTotal
unless -d $path 1 2 3
139 2 my ($files, $dirs) = $inst ->ls_tree_fdret($path, $inst ->ls_tree($path) );
140 2 print Dumper $files;
141 2 print Dumper $dirs;
142 2 Carp::carp( "danger - going to take out the whole tree under [$path]\n");
143 2 Carp::carp( "going to wait 3 seconds. use Ctrl-c to escape this. Hold down the Ctrl key, and hit 'c'.\n");
144 2 sleep 3;
145 2 for (@$files){
146 6 ▶ unlink $_ or Carp::carp ("cannot unlink $_ $!\n");
Branch: 1 branch
BranchTrueFalseTotal
unlink $_ or Carp::carp("cannot unlink $_ $!\n") 6 0 6
147 }
148 2 for (@$dirs){
149 1 ▶ rmdir $_ or Carp::carp ("cannot rmdir $_ $!\n");
Branch: 1 branch
BranchTrueFalseTotal
rmdir $_ or Carp::carp("cannot rmdir $_ $!\n") 1 0 1
150 }
151 2 rmdir $path;
152 }
153 }
154 2 ▶sub cust_rmfile {
Subroutine cust_rmfile: called CC=2 SCAR=7.0
Pod documented
155 2 my $inst=shift;
156 2 my $filepath=shift;
157 2 ▶ Carp::croak("[$filepath] is not a file") if (! -f $filepath);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filepath 0 2 2
158 2 unlink $filepath;
159 }
160  
161  
162  
163 1 1;
164 __END__
↑ Summary