| 1 | |||||||||||||||||||||
| 2 | package File::OldSlurp; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | # Copyright (C) 1994-1996, 1998, 2001-2002 David Muir Sharnoff | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | require Exporter; | |||||||||||||||||||
| 7 | 2 | @ISA = qw(Exporter); | |||||||||||||||||||
| 8 | 2 | @EXPORT = qw(read_file write_file overwrite_file append_file read_dir); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | $VERSION = 2004.0430; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub read_file | ||||||||||||||||||||
| 16 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
read_file: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||
| 17 | 6 | my ($file) = @_; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 6 | ▶ | local($/) = wantarray ? $/ : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 6 | local(*F); | |||||||||||||||||||
| 21 | 6 | my $r; | |||||||||||||||||||
| 22 | my (@r); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 6 | ▶ | open(F, "<$file") || croak "open $file: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 6 | @r = <F>; | |||||||||||||||||||
| 26 | 6 | ▶ | close(F) || croak "close $file: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 6 | ▶ | return $r[0] unless wantarray; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 1 | return @r; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub write_file | ||||||||||||||||||||
| 33 | 26 | ▶ | { | ||||||||||||||||||
|
Subroutine
write_file: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||
| 34 | 26 | my ($f, @data) = @_; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 26 | local(*F); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 26 | ▶ | open(F, ">$f") || croak "open >$f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 26 | ▶ | (print F @data) || croak "write $f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 26 | ▶ | close(F) || croak "close $f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 26 | return 1; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub overwrite_file | ||||||||||||||||||||
| 45 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
overwrite_file: called CC=8 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||
| 46 | 2 | my ($f, @data) = @_; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 2 | local(*F); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2 | ▶ | if (-e $f) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 1 | ▶ | open(F, "+<$f") || croak "open +<$f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||
| 53 | 1 | ▶ | open(F, "+>$f") || croak "open >$f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 2 | ▶ | (print F @data) || croak "write $f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 2 | my $where = tell(F); | |||||||||||||||||||
| 57 | 2 | ▶ | croak "could not tell($f): $!" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | unless defined $where; | ||||||||||||||||||||
| 59 | 2 | ▶ | truncate(F, $where) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | || croak "trucate $f at $where: $!"; | ||||||||||||||||||||
| 61 | 2 | ▶ | close(F) || croak "close $f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 2 | return 1; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub append_file | ||||||||||||||||||||
| 66 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
append_file: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||
| 67 | 2 | my ($f, @data) = @_; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 2 | local(*F); | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 2 | ▶ | open(F, ">>$f") || croak "open >>$f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 2 | ▶ | (print F @data) || croak "write $f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 2 | ▶ | close(F) || croak "close $f: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 2 | return 1; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | sub read_dir | ||||||||||||||||||||
| 78 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
read_dir: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||
| 79 | 3 | my ($d) = @_; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 3 | my (@r); | |||||||||||||||||||
| 82 | 3 | local(*D); | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 3 | ▶ | opendir(D,$d) || croak "opendir $d: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 3 | ▶ | @r = grep($_ ne "." && $_ ne "..", readdir(D)); | ||||||||||||||||||
|
Condition100%3/3
$_ ne '.' && $_ ne '..'
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||
| 86 | 3 | ▶ | closedir(D) || croak "closedir $d: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 3 | return @r; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||