blib/lib/IO/Dir.pm

filter: Statementstmt 82.1% 78 / 95 Branchbran 38.2% 13 / 34 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 84.0% 21 / 25 Podpod 100% 7 / 7 totaltotal 71.2% 124 / 174 CC 21 SCAR 15.3
CC
21
Cov
69%
STORE
20.0
seek
6.0
tell
6.0
CRAP 4.6
« blib/lib/IO/File.pm ↑ Summary blib/lib/IO.pm »
1 # IO::Dir.pm
2 #
3 # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
6  
7 package IO::Dir;
8  
9 2 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Tie::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 our @ISA = qw(Tie::Hash Exporter);
21 2 our $VERSION = "1.55";
22  
23 2 our @EXPORT_OK = qw(DIR_UNLINK);
24  
25 sub DIR_UNLINK () { 1 }
26  
27 3 ▶sub new {
Subroutine new: called CC=5 SCAR=17.8
Pod documented
28 3 ▶ @_ >= 1 && @_ <= 2 or croak 'usage: IO::Dir->new([DIRNAME])';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 2 or croak("usage: IO::Dir->new([DIRNAME])") 3 0 3
Condition33%1/3
@_ >= 1 and @_ <= 2
!ll&&!rl&&r
003
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1 @_ <= 2
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 2
ABresult
0X0
100
111
29 3 my $class = shift;
30 3 my $dh = gensym;
31 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 0 3
32 3 ▶ IO::Dir::open($dh, $_[0])
Branch: 1 branch
BranchTrueFalseTotal
IO::Dir::open($dh, $_[0]) or return undef 3 0 3
33 or return undef;
34 }
35 3 bless $dh, $class;
36 }
37  
38 3 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
39 3 my ($dh) = @_;
40 3 local($., $@, $!, $^E, $?);
41 2 ▶ no warnings 'io';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 closedir($dh);
43 }
44  
45 3 ▶sub open {
Subroutine open: called CC=5 SCAR=17.5
Pod documented
46 3 ▶ @_ == 2 or croak 'usage: $dh->open(DIRNAME)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$dh->open(DIRNAME)") 3 0 3
47 3 my ($dh, $dirname) = @_;
48 return undef
49 3 ▶ unless opendir($dh, $dirname);
Branch: 1 branch
BranchTrueFalseTotal
unless opendir $dh, $dirname 0 3 3
50 # a dir name should always have a ":" in it; assume dirname is
51 # in current directory
52 3 ▶ $dirname = ':' . $dirname if ( ($^O eq 'MacOS') && ($dirname !~ /:/) );
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MacOS" and not $dirname =~ /:/ 0 3 3
Condition33%1/3
$^O eq "MacOS" and not $dirname =~ /:/
!ll&&!rl&&r
300
MC/DC0%0/2
$^O eq "MacOS" and not $dirname =~ /:/
$^O eq "MacOS" not $dirname =~ /:/
Truth table33%1/3
A and not(B)
A= $^O eq "MacOS"B= not $dirname =~ /:/
ABresult
0X0
100
111
53 3 ${*$dh}{io_dir_path} = $dirname;
54 3 1;
55 }
56  
57 1 ▶sub close {
Subroutine close: called CC=2 SCAR=7.1
Pod documented
58 1 ▶ @_ == 1 or croak 'usage: $dh->close()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$dh->close()") 1 0 1
59 1 my ($dh) = @_;
60 1 closedir($dh);
61 }
62  
63 20 ▶sub read {
Subroutine read: called CC=2 SCAR=7.1
Pod documented
64 20 ▶ @_ == 1 or croak 'usage: $dh->read()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$dh->read()") 20 0 20
65 20 my ($dh) = @_;
66 20 readdir($dh);
67 }
68  
69 0 ▶sub seek {
Subroutine seek: not called CC=2 SCAR=17.9
Pod documented
70 0 ▶ @_ == 2 or croak 'usage: $dh->seek(POS)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$dh->seek(POS)") 0 0 0
71 0 my ($dh,$pos) = @_;
72 0 seekdir($dh,$pos);
73 }
74  
75 0 ▶sub tell {
Subroutine tell: not called CC=2 SCAR=17.9
Pod documented
76 0 ▶ @_ == 1 or croak 'usage: $dh->tell()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$dh->tell()") 0 0 0
77 0 my ($dh) = @_;
78 0 telldir($dh);
79 }
80  
81 3 ▶sub rewind {
Subroutine rewind: called CC=2 SCAR=7.1
Pod documented
82 3 ▶ @_ == 1 or croak 'usage: $dh->rewind()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$dh->rewind()") 3 0 3
83 3 my ($dh) = @_;
84 3 rewinddir($dh);
85 }
86  
87 2 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=3 SCAR=11.0
88 2 my($class,$dir,$options) = @_;
89  
90 2 ▶ my $dh = $class->new($dir)
Branch: 1 branch
BranchTrueFalseTotal
my $dh = $class->new($dir) or return undef 2 0 2
91 or return undef;
92  
93 2 ▶ $options ||= 0;
Condition100%2/2
$options ||= 0
l!l
11
MC/DC100%1/1
$options ||= 0
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
94  
95 2 ${*$dh}{io_dir_unlink} = $options & DIR_UNLINK;
96 2 $dh;
97 }
98  
99 1 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
100 1 my($dh) = @_;
101 1 $dh->rewind;
102 1 scalar $dh->read;
103 }
104  
105 13 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
106 13 my($dh) = @_;
107 13 scalar $dh->read;
108 }
109  
110 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
111 0 my($dh,$key) = @_;
112 0 -e File::Spec->catfile(${*$dh}{io_dir_path}, $key);
113 }
114  
115 2 ▶sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
116 2 my($dh,$key) = @_;
117 2 &lstat(File::Spec->catfile(${*$dh}{io_dir_path}, $key));
118 }
119  
120 0 ▶sub STORE {
Subroutine STORE: not called CC=4 SCAR=30.0
121 0 my($dh,$key,$data) = @_;
122 0 ▶ my($atime,$mtime) = ref($data) ? @$data : ($data,$data);
Branch: 1 branch
BranchTrueFalseTotal
ref $data ? : 0 0 0
123 0 my $file = File::Spec->catfile(${*$dh}{io_dir_path}, $key);
124 0 ▶ unless(-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
125 0 my $io = IO::File->new($file,O_CREAT | O_RDWR);
126 0 ▶ $io->close if $io;
Branch: 1 branch
BranchTrueFalseTotal
if $io 0 0 0
127 }
128 0 utime($atime,$mtime, $file);
129 }
130  
131 2 ▶sub DELETE {
Subroutine DELETE: called CC=3 SCAR=11.0
132 2 my($dh,$key) = @_;
133  
134 # Only unlink if unlink-ing is enabled
135 return 0
136 2 ▶ unless ${*$dh}{io_dir_unlink};
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$dh }->{"io_dir_unlink"} 1 1 2
137  
138 1 my $file = File::Spec->catfile(${*$dh}{io_dir_path}, $key);
139  
140 1 ▶ -d $file
Branch: 1 branch
BranchTrueFalseTotal
-d $file ? : 0 1 1
141 ? rmdir($file)
142 : unlink($file);
143 }
144  
145 2 1;
146  
147 __END__
« blib/lib/IO/File.pm ↑ Summary blib/lib/IO.pm »