blib/lib/File/Scan.pm

filter: Statementstmt 23.1% 19 / 82 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 26.6% 4 / 15 Podpod 87.5% 7 / 8 totaltotal 14.7% 30 / 204 CC 36 SCAR 60.2
CC
36
Cov
12%
scan
756.0
set_callback
30.0
new
6.0
CRAP 412.7
↑ Summary
1 #
2 # Scan.pm
3 # Last Modification: Wed May 4 16:31:36 WEST 2005
4 #
5 # Copyright (c) 2005 Henrique Dias <hdias@aesbuc.pt>. All rights reserved.
6 # This module is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
8 #
9 #
10 package File::Scan;
11  
12 1 require 5;
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 require Exporter;
16 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use SelfLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use vars qw($VERSION @ISA @EXPORT $ERROR $SKIPPED $SUSPICIOUS $CALLBACK);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 @ISA = qw(Exporter);
22 1 $VERSION = '1.43';
23  
24 1 ($ERROR, $SKIPPED, $SUSPICIOUS, $CALLBACK) = ("", 0, 0, "");
25  
26 1 SelfLoader->load_stubs();
27  
28 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
29 0 my $proto = shift;
30 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
31 0 my $self = {
32 extension => "",
33 delete => 0,
34 move => "",
35 copy => "",
36 mkdir => 0,
37 max_txt_size => 5120,
38 max_bin_size => 10240,
39 @_,
40 };
41 0 bless ($self, $class);
42 0 return($self);
43 }
44  
45 0 ▶sub scan {
Subroutine scan: not called CC=27 SCAR=66.3
Pod documented
46 0 my $self = shift;
47 0 my $file = shift;
48  
49 0 &_set_error();
50 0 &_set_skip();
51 0 &_set_suspicious();
52 0 &ret_callback();
53  
54 0 ▶ (-e $file) or return(&_set_error("No such file or directory: $file"));
Branch: 1 branch
BranchTrueFalseTotal
-e $file or return &_set_error("No such file or directory: $file") 0 0 0
55 0 my $fsize = -s $file;
56 0 ▶ $fsize or return(&_set_skip(2));
Branch: 1 branch
BranchTrueFalseTotal
$fsize or return &_set_skip(2) 0 0 0
57 0 my $res = "";
58 0 ▶ if(-f $file && -T $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file and -T $file) { } 0 0 0
Condition0%0/3
-f $file and -T $file
!ll&&!rl&&r
000
MC/DC0%0/2
-f $file and -T $file
-f $file -T $file
Truth table0%0/3
A and B
A= -f $fileB= -T $file
ABresult
0X0
100
111
59 0 ▶ return(&_set_skip(3)) if($fsize < 23);
Branch: 1 branch
BranchTrueFalseTotal
if $fsize < 23 0 0 0
60 return(&_set_skip(4))
61 0 ▶ if($self->{'max_txt_size'} && ($fsize > $self->{'max_txt_size'} * 1024));
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"max_txt_size"} and $fsize > $self->{"max_txt_size"} * 1024 0 0 0
Condition0%0/3
$self->{"max_txt_size"} and $fsize > $self->{"max_txt_size"} * 1024
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"max_txt_size"} and $fsize > $self->{"max_txt_size"} * 1024
$self->{"max_txt_size"} $fsize > $self->{"max_txt_size"} * 1024
Truth table0%0/3
A and B
A= $self->{"max_txt_size"}B= $fsize > $self->{"max_txt_size"} * 1024
ABresult
0X0
100
111
62 0 $res = &scan_text($self, $file);
63 } else {
64 return(&_set_skip(5))
65 0 ▶ if($self->{'max_bin_size'} && ($fsize > $self->{'max_bin_size'} * 1024));
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"max_bin_size"} and $fsize > $self->{"max_bin_size"} * 1024 0 0 0
Condition0%0/3
$self->{"max_bin_size"} and $fsize > $self->{"max_bin_size"} * 1024
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"max_bin_size"} and $fsize > $self->{"max_bin_size"} * 1024
$self->{"max_bin_size"} $fsize > $self->{"max_bin_size"} * 1024
Truth table0%0/3
A and B
A= $self->{"max_bin_size"}B= $fsize > $self->{"max_bin_size"} * 1024
ABresult
0X0
100
111
66 0 $res = &scan_binary($self, $file);
67 }
68 0 ▶ if($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
69 0 ▶ if($self->{'extension'} && $file !~ /\.$self->{'extension'}$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extension"} and not $file =~ /\.$self->{"extension"}$/o) 0 0 0
Condition0%0/3
$self->{"extension"} and not $file =~ /\.$self->{"extension"}$/o
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"extension"} and not $file =~ /\.$self->{"extension"}$/o
$self->{"extension"} not $file =~ /\.$self->{"extension"}$/o
Truth table0%0/3
A and not(B)
A= $self->{"extension"}B= not $file =~ /\.$self->{"extension"}$/o
ABresult
0X0
100
111
70 0 my $newname = join("\.", $file, $self->{'extension'});
71 0 ▶ if(move($file, $newname)) { $file = $newname; }
Branch: 1 branch
BranchTrueFalseTotal
if (move($file, $newname)) { } 0 0 0
72 0 else { &_set_error("Failed to move '$file' to '$newname'"); }
73 }
74 0 ▶ if($self->{'copy'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"copy"}) 0 0 0
75 0 ▶ if(!(-d $self->{'copy'}) && $self->{'mkdir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -d $self->{"copy"} and $self->{"mkdir"}) 0 0 0
Condition0%0/3
not -d $self->{"copy"} and $self->{"mkdir"}
!ll&&!rl&&r
000
MC/DC0%0/2
not -d $self->{"copy"} and $self->{"mkdir"}
not -d $self->{"copy"} $self->{"mkdir"}
Truth table0%0/3
not(A) and B
A= not -d $self->{"copy"}B= $self->{"mkdir"}
ABresult
0X0
100
111
76 0 ▶ mkdir($self->{'copy'}, $self->{'mkdir'}) or &_set_error(join("", "Failed to create directory '", $self->{'copy'}, "' $!"));
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->{"copy"}, $self->{"mkdir"} or &_set_error(join("", "Failed to create directory '", $self->{"copy"}, "' $!")) 0 0 0
77 }
78 0 my ($f) = ($file =~ /([^\/]+)$/o);
79 0 my $cpdir = join("/", $self->{'copy'}, $f);
80 0 ▶ copy($file, $cpdir) or &_set_error("Failed to copy '$file' to $cpdir");
Branch: 1 branch
BranchTrueFalseTotal
copy($file, $cpdir) or &_set_error("Failed to copy '${file}' to $cpdir") 0 0 0
81 }
82 0 ▶ if($self->{'move'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"move"}) 0 0 0
83 0 ▶ if(!(-d $self->{'move'}) && $self->{'mkdir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -d $self->{"move"} and $self->{"mkdir"}) 0 0 0
Condition0%0/3
not -d $self->{"move"} and $self->{"mkdir"}
!ll&&!rl&&r
000
MC/DC0%0/2
not -d $self->{"move"} and $self->{"mkdir"}
not -d $self->{"move"} $self->{"mkdir"}
Truth table0%0/3
not(A) and B
A= not -d $self->{"move"}B= $self->{"mkdir"}
ABresult
0X0
100
111
84 0 ▶ mkdir($self->{'move'}, $self->{'mkdir'}) or &_set_error(join("", "Failed to create directory '", $self->{'move'}, "' $!"));
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->{"move"}, $self->{"mkdir"} or &_set_error(join("", "Failed to create directory '", $self->{"move"}, "' $!")) 0 0 0
85 }
86 0 my ($f) = ($file =~ /([^\/]+)$/o);
87 0 my $mvfile = join("/", $self->{'move'}, $f);
88 0 ▶ if(move($file, $mvfile)) { $file = $mvfile; }
Branch: 1 branch
BranchTrueFalseTotal
if (move($file, $mvfile)) { } 0 0 0
89 0 else { &_set_error("Failed to move '$file' to '$mvfile'"); }
90 }
91 0 ▶ if($self->{'delete'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"delete"}) 0 0 0
92 0 ▶ if($file =~ /^(.+)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /^(.+)$/s) 0 0 0
93 0 ▶ unlink($1) or &_set_error("Could not delete $1: $!");
Branch: 1 branch
BranchTrueFalseTotal
unlink $1 or &_set_error("Could not delete $1: $!") 0 0 0
94 }
95 }
96 }
97 0 return($res);
98 }
99  
100 0 ▶sub set_callback {
Subroutine set_callback: not called CC=5 SCAR=34.0
Pod documented
101 0 my $self = shift;
102 0 ▶ my $subref = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
103  
104 0 ▶ if(defined($subref) && ref($subref) eq "CODE") {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $subref and ref $subref eq 'CODE') { } 0 0 0
elsif (exists $self->{'callback'}) { } 0 0 0
Condition0%0/3
defined $subref and ref $subref eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $subref and ref $subref eq "CODE"
defined $subref ref $subref eq "CODE"
Truth table0%0/3
A and B
A= defined $subrefB= ref $subref eq "CODE"
ABresult
0X0
100
111
105 0 $self->{'callback'} = $subref;
106 } elsif(exists($self->{'callback'})) {
107 0 delete($self->{'callback'});
108 }
109 0 return();
110 }
111  
112 0 ▶sub _set_error {
Subroutine _set_error: not called CC=2 SCAR=17.9
113 0 ▶ $ERROR = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
114 0 return();
115 }
116  
117 0 ▶sub _set_skip {
Subroutine _set_skip: not called CC=2 SCAR=17.9
118 0 ▶ $SKIPPED = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
119 0 return();
120 }
121  
122 0 ▶sub _set_suspicious {
Subroutine _set_suspicious: not called CC=2 SCAR=17.9
123 0 ▶ $SUSPICIOUS = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
124 0 return();
125 }
126  
127 0 ▶sub ret_callback {
Subroutine ret_callback: not called CC=2 SCAR=17.9
Pod undocumented
128 0 ▶ $CALLBACK = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
129 0 return();
130 }
131  
132 0 ▶sub error { $ERROR; }
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
133 0 ▶sub skipped { $SKIPPED; }
Subroutine skipped: not called CC=1 SCAR=6.9
Pod documented
134 0 ▶sub suspicious { $SUSPICIOUS; }
Subroutine suspicious: not called CC=1 SCAR=6.9
Pod documented
135 0 ▶sub callback { $CALLBACK; }
Subroutine callback: not called CC=1 SCAR=6.9
Pod documented
136  
137 1 1;
138  
139 __DATA__
↑ Summary