lib/LEOCHARRE/BogusFile.pm

filter: Statementstmt 100% 45 / 45 Branchbran 75.0% 15 / 20 Conditioncond 35.7% 5 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 78.3% 76 / 97 CC 16 SCAR 19.2
CC
16
Cov
82%
make_bogus_file
11.6
arg2bytes
7.0
_randstring
3.1
CRAP 6.8
↑ Summary
1 package LEOCHARRE::BogusFile;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS @ISA @CHARS $CHARLAST $MAXLENGTH);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)/g;
7 1 @ISA = qw/Exporter/;
8 1 @EXPORT_OK = qw(make_bogus_file arg2bytes);
9 1 %EXPORT_TAGS = ( all => \@EXPORT_OK );
10 1 @CHARS = (0 .. 9);
11 1 $CHARLAST = scalar @CHARS;
12 1 $MAXLENGTH = 100000;
13  
14  
15  
16  
17 4 ▶sub make_bogus_file {
Subroutine make_bogus_file: called CC=8 SCAR=24.5
Pod documented
18 4 my ($path, $size_arg) = @_;
19 4 ▶ $path or confess("missing path argument");
Branch: 1 branch
BranchTrueFalseTotal
$path or confess("missing path argument") 4 0 4
20 4 ▶ (Carp::cluck("$path already on disk") and return) if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 4 4
Condition25%1/4
-e $path && (Carp::cluck("$path already on disk") && (return))
!ll
40
Carp::cluck("$path already on disk") and return
!ll
00
MC/DC0%0/2
-e $path && (Carp::cluck("$path already on disk") && (return))
-e $path Carp::cluck("$path already on disk")
Truth table33%1/3
A && B
A= -e $pathB= Carp::cluck("$path already on disk")
ABresult
0X0
100
111
21
22
23 4 ▶ my $size = $size_arg ? arg2bytes($size_arg) : _randlength();
Branch: 1 branch
BranchTrueFalseTotal
$size_arg ? : 3 1 4
24
25
26 # size should be in k?
27
28 4 ▶ open(F,'>',$path) or Carp::Cluck("cant open for writing '$path', $!") and return;
Branch: 1 branch
BranchTrueFalseTotal
open F, ">", $path or Carp::Cluck("cant open for writing '${path}', $!") and return 4 0 4
Condition25%1/4
open(F, '>', $path) || Carp::Cluck("cant open for writing '${path}', $!") && (return)
l!l
40
Carp::Cluck("cant open for writing '${path}', $!") and return
!ll
00
MC/DC0%0/2
open(F, '>', $path) || Carp::Cluck("cant open for writing '${path}', $!") && (return)
open(F, '>', $path) Carp::Cluck("cant open for writing '${path}', $!")
Truth table33%1/3
A || B
A= open(F, '>', $path)B= Carp::Cluck("cant open for writing '${path}', $!")
ABresult
1X1
011
000
29 4 print F _randstring($size);
30 4 close F;
31  
32 # cant return size here so simply..
33 # it may not have been defined..
34 4 ▶ $size || (stat($path))[7];
Branch: 1 branch
BranchTrueFalseTotal
$size or (stat $path)[7] 4 0 4
35 }
36  
37  
38 1 ▶sub _randlength { int( rand($MAXLENGTH) + 1 ) }
Subroutine _randlength: called CC=1 SCAR=0.0
39  
40 4 ▶sub _randstring {
Subroutine _randstring: called CC=3 SCAR=11.3
41 4 my $length = shift;
42 4 ▶ $length ||= int( rand($MAXLENGTH) + 1 );
Condition33%1/3
$length ||= int rand($LEOCHARRE::BogusFile::MAXLENGTH) + 1
l!l&&r!l&&!r
400
MC/DC0%0/2
$length ||= int rand($LEOCHARRE::BogusFile::MAXLENGTH) + 1
$length int rand($LEOCHARRE::BogusFile::MAXLENGTH) + 1
Truth table33%1/3
A ||= B
A= $lengthB= int rand($LEOCHARRE::BogusFile::MAXLENGTH) + 1
ABresult
1X1
011
000
43
44 #print STDERR "randstring() length: $length\n" if $DEBUG;
45
46 4 my $string;
47
48 4 for ( 0 .. ($length - 1)){
49 100472 $string.=$CHARS[int(rand($CHARLAST))];
50 }
51
52 4 $string;
53 }
54  
55  
56 17 ▶sub arg2bytes {
Subroutine arg2bytes: called CC=7 SCAR=19.5
Pod documented
57 17 ▶ defined $_[0] or confess("missing arg");
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or confess("missing arg") 17 0 17
58 17 ▶ $_[0]=~/^\d+$/ and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ and return $_[0] 4 13 17
59
60 13 my $totalbytes = $_[0];
61
62  
63 #print STDERR "\n\ninitial bytes arg at $totalbytes\n" if $DEBUG;
64 13 ▶ $totalbytes=~/^\d/ or confess("invalid size ammount spec $totalbytes");
Branch: 1 branch
BranchTrueFalseTotal
$totalbytes =~ /^\d/ or confess("invalid size ammount spec $totalbytes") 12 1 13
65  
66 12 my %unit = (
67 B => 1, # in bytes
68 K => 1024, # kilobytes
69 M => ( 1024 * 1024 ), # megabytes
70 G => ( 1024 * 1024 * 1024 ), # gigabytes - too big.. ??
71 );
72 12 ▶ if($totalbytes=~s/([BKMG]{1}).*$//i){
Branch: 1 branch
BranchTrueFalseTotal
if ($totalbytes =~ s/([BKMG]{1}).*$//i) 11 1 12
73 11 my $unit = $unit{uc($1)};
74 #print STDERR " [$totalbytes] ";
75 11 $totalbytes = int ($totalbytes * $unit);
76  
77 #printf STDERR "totalbytes [unit %s] resolved to total bytes: $totalbytes\n", $unit{uc($1)};
78 }
79
80 12 ▶ $totalbytes and $totalbytes=~/^\d+$/ or die("invalid size resolved: $totalbytes");
Branch: 1 branch
BranchTrueFalseTotal
$totalbytes and $totalbytes =~ /^\d+$/ or die "invalid size resolved: $totalbytes" 11 1 12
Condition66%2/3
$totalbytes and $totalbytes =~ /^\d+$/
!ll&&!rl&&r
0111
MC/DC50%1/2
$totalbytes and $totalbytes =~ /^\d+$/
$totalbytes $totalbytes =~ /^\d+$/
Truth table66%2/3
A and B
A= $totalbytesB= $totalbytes =~ /^\d+$/
ABresult
0X0
100
111
81  
82 11 $totalbytes;
83 }
84  
85  
86  
87  
88  
89  
90  
91  
92  
93 1 1;
94  
95 __END__
↑ Summary