| 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
| |||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | (Carp::cluck("$path already on disk") and return) if -e $path; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
-e $path && (Carp::cluck("$path already on disk") && (return))
Carp::cluck("$path already on disk") and return
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")
| |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | my $size = $size_arg ? arg2bytes($size_arg) : _randlength(); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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
Condition25%1/4
open(F, '>', $path) || Carp::Cluck("cant open for writing '${path}', $!") && (return)
Carp::Cluck("cant open for writing '${path}', $!") and return
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}', $!")
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 58 | 17 | ▶ | $_[0]=~/^\d+$/ and return $_[0]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$totalbytes and $totalbytes =~ /^\d+$/
MC/DC50%1/2
$totalbytes and $totalbytes =~ /^\d+$/
$totalbytes
$totalbytes =~ /^\d+$/
Truth table66%2/3
A and B
A= $totalbytesB= $totalbytes =~ /^\d+$/
| |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | 11 | $totalbytes; | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | 1 | 1; | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||||