blib/lib/Cache/Repository/Filesys.pm

filter: Statementstmt 86.1% 193 / 224 Branchbran 60.7% 51 / 84 Conditioncond 53.3% 16 / 30 MC/DCmcdc 23.5% 4 / 17 Subroutinesub 90.3% 28 / 31 Podpod 100% 10 / 10 totaltotal 76.2% 302 / 396 CC 56 SCAR 19.8
CC
56
Cov
77%
new
18.3
retrieve_with_callback
13.5
add_symlink
12.0
CRAP 7.3
« blib/lib/Cache/Repository.pm ↑ Summary Build »
1 package Cache::Repository::Filesys;
2  
3 1 ▶use base 'Cache::Repository';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '0.04';
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Fcntl qw(:flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Cache::Repository::Filesys - Filesystem driver for Cache::Repository
20  
21 =head1 SYNOPSIS
22  
23 my $rep = Cache::Repository->new(
24 style => 'Filesys',
25 # options for the F::R driver
26 );
27 $rep->add_files(tag => 'groupname',
28 files => \@filenames,
29 basedir => '/tmp',
30 move => 1,
31 );
32 $rep->add_filehandle(tag => 'anothergroup',
33 filename => 'blah',
34 filehandle => $fh,
35 mode => 0755);
36 $rep->set_meta(tag => 'groupname',
37 meta => {
38 title => 'blah',
39 author => 'foo',
40 });
41  
42 $rep->retrieve(tag => 'groupname', dest => '/newdir');
43 my $data = $rep->get_meta(tag => 'groupname');
44  
45 =head1 DESCRIPTION
46  
47 Caching in a locally-mounted filesystem. Eventually, this will include
48 NFS-level locking, but for now, this module assuming only a single process
49 accessing the repository in write mode at a time.
50  
51 =head1 FUNCTIONS
52  
53 =over 4
54  
55 =item new
56  
57 Cache::Repository::Filesys constructor.
58  
59 my $r = Cache::Repository::Filesys->new(
60 path => '/some/path/with/enough/space',
61 );
62  
63 or
64  
65 my $r = Cache::Repository->new(
66 style => 'Filesys',
67 path => '/some/path/with/enough/space',
68 );
69  
70 Parameters:
71  
72 =over 4
73  
74 =item path
75  
76 The path in which to store the repository.
77  
78 =item clear
79  
80 If true, clear the repository (if it exists) to start anew. Existing files
81 and meta information will all be removed.
82  
83 =item compress
84  
85 The compress option is ignored in the current version.
86  
87 =item dir_mapping
88  
89 This is a code ref which is given a tag name, and maps it to a relative
90 directory that should contain the tag. The default is to use an MD5 hash of
91 the tag, and use that to create a directory hierarchy for the tag's contents.
92 You can override this to, for example, provide a more-easily-debuggable
93 path such as:
94  
95 dir_mapping => sub {
96 my $tag = shift;
97 $tag =~ s:/:_:;
98 $tag;
99 },
100  
101 =item sector_size
102  
103 =item symlink_size
104  
105 Options for L<Filesys::DiskUsage>. Defaults to the blocksize of the
106 directory holding the repository if L<Filesys::Statvfs> is installed,
107 or just simply 1024 if L<Filesys::Statvfs> is not installed.
108  
109 Use 1 to get exact numbers for total file size, but this is rarely what
110 you really want (unless you're planning to put it in a tarball).
111  
112 =back
113  
114 Returns: The Cache::Repository::Filesys object, or undef if the driver failed
115 to initialise.
116  
117 =cut
118  
119 sub new
120 {
121 2 ▶ my $class = shift;
Subroutine new: called CC=10 SCAR=29.1
Pod documented
122 2 ▶ $class = ref $class || $class || __PACKAGE__;
Condition40%2/5
ref $class || $class || __PACKAGE__
l!l
20
ref $class or $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class || __PACKAGE__
ref $class $class
Truth table33%1/3
A or B
A= ref $classB= $class
ABresult
1X1
011
000
123 2 my %opts = @_;
124  
125 2 my $self = \%opts;
126 2 bless $self, $class;
127  
128 2 ▶ if (exists $self->{sector_size} and $self->{sector_size} < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"sector_size"} and $self->{"sector_size"} < 1) 0 2 2
Condition33%1/3
exists $self->{"sector_size"} and $self->{"sector_size"} < 1
!ll&&!rl&&r
200
MC/DC0%0/2
exists $self->{"sector_size"} and $self->{"sector_size"} < 1
exists $self->{"sector_size"} $self->{"sector_size"} < 1
Truth table33%1/3
A and B
A= exists $self->{"sector_size"}B= $self->{"sector_size"} < 1
ABresult
0X0
100
111
129 {
130 0 require Carp;
131 0 croak "sector_size must be > 0";
132 }
133 2 ▶ if (exists $self->{symlink_size} and $self->{symlink_size} < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"symlink_size"} and $self->{"symlink_size"} < 1) 0 2 2
Condition33%1/3
exists $self->{"symlink_size"} and $self->{"symlink_size"} < 1
!ll&&!rl&&r
200
MC/DC0%0/2
exists $self->{"symlink_size"} and $self->{"symlink_size"} < 1
exists $self->{"symlink_size"} $self->{"symlink_size"} < 1
Truth table33%1/3
A and B
A= exists $self->{"symlink_size"}B= $self->{"symlink_size"} < 1
ABresult
0X0
100
111
134 {
135 0 require Carp;
136 0 croak "symlink_size must be > 0";
137 }
138  
139 2 ▶ $self->{sector_size} ||= $self->_default_blocksize();
Condition33%1/3
$self->{"sector_size"} ||= $self->_default_blocksize
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"sector_size"} ||= $self->_default_blocksize
$self->{"sector_size"} $self->_default_blocksize
Truth table33%1/3
A ||= B
A= $self->{"sector_size"}B= $self->_default_blocksize
ABresult
1X1
011
000
140 2 ▶ $self->{symlink_size} ||= $self->_default_blocksize();
Condition33%1/3
$self->{"symlink_size"} ||= $self->_default_blocksize
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"symlink_size"} ||= $self->_default_blocksize
$self->{"symlink_size"} $self->_default_blocksize
Truth table33%1/3
A ||= B
A= $self->{"symlink_size"}B= $self->_default_blocksize
ABresult
1X1
011
000
141  
142 2 ▶ if (delete $self->{clear})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"clear"}) 1 1 2
143 {
144 1 $self->_clear_repository();
145 }
146 2 $self;
147 }
148  
149 1 my $_has_statvfs = -1;
150 sub _default_blocksize
151 {
152 4 ▶ my $self = shift;
Subroutine _default_blocksize: called CC=2 SCAR=6.9
153 4 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
if $_has_statvfs 1 3 4
154 1 require Filesys::Statvfs;
155 1 $_has_statvfs = 1;
156 1 my ($bsize) = Filesys::Statvfs::statvfs($self->{path});
157 1 return $bsize;
158 } if $_has_statvfs;
159 4 $_has_statvfs = 0;
160 4 1024;
161 }
162  
163 sub _clear_repository
164 {
165 1 ▶ my $self = shift;
Subroutine _clear_repository: called CC=2 SCAR=7.2
166 1 my $path = $self->{path};
167  
168 # since $path could be a symlink, we can't blow it away. Thus,
169 # we must find everything under it, and blow those away.
170 1 require File::Path;
171  
172 1 ▶ if (-d $path)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) { } 1 0 1
173 {
174 1 rmtree([glob File::Spec->catfile($path, '*')]);
175 }
176 else
177 {
178 0 mkpath([$path]);
179 }
180 }
181  
182 # figuring out the dir from the tag - that's something we would like to
183 # be able to change - so we'll put all such constructs here to keep it
184 # malleable.
185 sub _dir
186 {
187 13 ▶ my $self = shift;
Subroutine _dir: called CC=3 SCAR=11.3
188 13 my $tag = shift;
189  
190 13 ▶ croak "No tag given" unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 13 13
191  
192 13 my $subdir;
193 13 ▶ if ($self->{dir_mapping})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dir_mapping'}) { } 0 13 13
194 {
195 0 $subdir = $self->{dir_mapping}->($tag);
196 }
197 else
198 {
199 13 require Digest::MD5;
200 13 $tag = Digest::MD5::md5_hex($tag);
201 13 $subdir = File::Spec->catdir(
202 substr($tag,0,2),
203 substr($tag,2,2),
204 $tag
205 );
206 }
207 File::Spec->catdir(
208 $self->{path},
209 13 $subdir,
210 );
211 }
212  
213 # when we add a file to a tag, we may want to store meta-info about it.
214 # filter all completed requests through here.
215 sub _add_file
216 {
217 3 ▶ my $self = shift;
Subroutine _add_file: called CC=1 SCAR=0.0
218 3 my %opts = @_;
219  
220 #$self->{r}{$opts{tag}}{$opts{filename}} = undef;
221 $self->set_meta(tag => '_r',
222 meta => {
223 $opts{tag} => {
224 $opts{filename} => {
225 3 dir => $self->_dir(%opts),
226 },
227 },
228 },
229 );
230 }
231  
232 sub _remove_tag
233 {
234 0 ▶ my $self = shift;
Subroutine _remove_tag: not called CC=1 SCAR=6.9
235 0 my %opts = @_;
236  
237 0 my $data = $self->get_meta(tag => '_r');
238 0 delete $data->{$opts{tag}};
239 0 $self->set_meta(tag => '_r',
240 reset => 1,
241 meta => $data);
242 }
243  
244 sub _lock_meta
245 {
246 10 ▶ my $self = shift;
Subroutine _lock_meta: called CC=5 SCAR=16.1
247 10 ▶ my $mode = shift || 'r';
Condition100%2/2
shift() || 'r'
l!l
46
MC/DC100%1/1
shift() || 'r'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
248  
249 10 my $meta_name = do {
250 10 ▶ unless (exists $self->{metaname})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"metaname"}) 1 9 10
251 {
252 1 $self->{metaname} = File::Spec->catfile($self->{path}, 'meta.info');
253 }
254 10 $self->{metaname};
255 };
256  
257 10 my $fh = IO::File->new($meta_name, $mode);
258 10 ▶ if ($fh)
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 9 1 10
259 {
260 9 ▶ flock($fh, $mode eq 'r' ? LOCK_SH : LOCK_EX);
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'r' ? : 5 4 9
261 }
262 10 $fh;
263 }
264  
265 sub _load_meta
266 {
267 6 ▶ my $self = shift;
Subroutine _load_meta: called CC=5 SCAR=16.2
268 6 my $fh = $self->_lock_meta();
269  
270 # only load it if it's been changed since the last load.
271 6 my $s = stat($self->{metaname});
272 6 ▶ if ($s and
Branch: 1 branch
BranchTrueFalseTotal
if ($s and $s->mtime >= ($self->{"metastamp"} || 0) and $fh) 5 1 6
Condition75%6/8
$s and $s->mtime >= ($self->{"metastamp"} || 0) and $fh
!ll&&!rl&&r
105
$s and $s->mtime >= ($self->{"metastamp"} || 0)
!ll&&!rl&&r
105
$self->{'metastamp'} || 0
l!l
41
MC/DC33%1/3
$s and $s->mtime >= ($self->{"metastamp"} || 0) and $fh
$s $s->mtime >= ($self->{"metastamp"} || 0) $fh
MC/DC100%1/1
$self->{'metastamp'} || 0
$self->{'metastamp'}
Truth table50%2/4
A and B and C
A= $sB= $s->mtime >= ($self->{"metastamp"} || 0)C= $fh
ABCresult
0XX0
10X0
1100
1111
Truth table100%2/2
A
A= $self->{'metastamp'}
Aresult
11
00
273 $s->mtime() >= ($self->{metastamp} || 0) and
274 $fh)
275 {
276 5 local $/;
277 5 my $data = join '', $fh->getlines();
278 5 $self->{metastamp} = time();
279 5 $fh->close(); # release lock
280  
281 5 $self->{meta} = $self->_thaw($data);
282 }
283 }
284  
285 sub _save_meta
286 {
287 4 ▶ my $self = shift;
Subroutine _save_meta: called CC=1 SCAR=0.0
288 4 my $fh = $self->_lock_meta('w');
289  
290 4 $fh->print($self->_freeze($self->{meta}));
291 4 $fh->close();
292 }
293  
294 sub _thaw
295 {
296 5 ▶ my $self = shift;
Subroutine _thaw: called CC=1 SCAR=0.0
297 5 my $data = shift;
298 5 eval 'my ' . $data;
299 }
300  
301 sub _freeze
302 {
303 4 ▶ my $self = shift;
Subroutine _freeze: called CC=1 SCAR=0.0
304 4 my $data = shift;
305 4 require Data::Dumper;
306 4 local $Data::Dumper::Indent = 0;
307 4 local $Data::Dumper::Purity = 1;
308 4 join '', Data::Dumper::Dumper($data);
309 }
310  
311 =item get_meta
312  
313 Overrides L<Cache::Repository>'s get_meta function
314  
315 =cut
316  
317 sub get_meta
318 {
319 2 ▶ my $self = shift;
Subroutine get_meta: called CC=2 SCAR=7.2
Pod documented
320 2 my %opts = @_;
321  
322 2 $self->_load_meta();
323 2 ▶ unless (exists $self->{meta}{$opts{tag}})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"meta"}{$opts{"tag"}}) 0 2 2
324 {
325 $self->{meta}{$opts{tag}} = {}
326 0 }
327 2 $self->{meta}{$opts{tag}};
328 }
329  
330 =item set_meta
331  
332 Overrides L<Cache::Repository>'s set_meta function
333  
334 =cut
335  
336 sub set_meta
337 {
338 4 ▶ my $self = shift;
Subroutine set_meta: called CC=4 SCAR=14.2
Pod documented
339 4 my %opts = @_;
340  
341 #my $fh = $self->_lock_meta('w');
342  
343 4 $self->_load_meta();
344 4 ▶ if ($opts{'reset'})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"reset"}) 0 4 4
345 {
346 0 $self->{meta}{$opts{tag}} = {};
347 }
348  
349 $self->{meta}{$opts{tag}} = {
350 2 ▶ $self->{meta}{$opts{tag}} ? %{$self->{meta}{$opts{tag}}} : (),
Branch: 1 branch
BranchTrueFalseTotal
$opts{'meta'} ? : 4 0 4
351 4 ▶ $opts{meta} ? %{$opts{meta}} : (),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'meta'}{$opts{'tag'}} ? : 2 2 4
352 };
353 4 $self->_save_meta();
354 }
355  
356 =item clear_tag
357  
358 =cut
359  
360 sub clear_tag
361 {
362 0 ▶ my $self = shift;
Subroutine clear_tag: not called CC=1 SCAR=6.9
Pod documented
363 0 my %opts = @_;
364  
365 0 my $path = $self->_dir($opts{tag});
366  
367 0 rmtree([glob ($path . '*')]);
368 }
369  
370 =item add_symlink
371  
372 =cut
373  
374 sub add_symlink
375 {
376 0 ▶ my $self = shift;
Subroutine add_symlink: not called CC=3 SCAR=24.8
Pod documented
377 0 my %opts = @_;
378  
379 0 ▶ return 0 unless $self->_is_filename_ok($opts{filename});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_filename_ok($opts{"filename"}) 0 0 0
380  
381 0 my $dir = $self->_dir($opts{tag});
382 0 my $dstfile = File::Spec->catdir($dir, $opts{filename});
383 0 mkpath(dirname($dstfile));
384  
385 0 ▶ if (symlink($opts{target}, $dstfile))
Branch: 1 branch
BranchTrueFalseTotal
if (symlink $opts{"target"}, $dstfile) 0 0 0
386 {
387 0 $self->_add_file(%opts);
388 0 return 1;
389 }
390 0 undef;
391 }
392  
393 =item add_files
394 =item add_filehandle
395  
396 =cut
397  
398 sub add_filehandle
399 {
400 3 ▶ my $self = shift;
Subroutine add_filehandle: called CC=8 SCAR=20.9
Pod documented
401 3 my %opts = @_;
402 3 my $dir = $self->_dir($opts{tag});
403  
404 3 ▶ return 0 unless $self->_is_filename_ok($opts{filename});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_filename_ok($opts{"filename"}) 0 3 3
405  
406 3 my $dstfile = File::Spec->catdir($dir, $opts{filename});
407  
408 3 mkpath(dirname($dstfile));
409 #my $rc = copy($opts{filehandle}, $dstfile);
410 3 my $rc = 0;
411 {
412 3 local $/ = \32768;
413 3 local $_;
414  
415 3 ▶ if (open my $dst_h, '>', $dstfile)
Branch: 1 branch
BranchTrueFalseTotal
if (open my $dst_h, ">", $dstfile) 3 0 3
416 {
417 3 binmode $dst_h;
418 3 my $in_h = $opts{filehandle};
419 3 ▶ print $dst_h $_ while <$in_h>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $in_h) and do { print $dst_h $_ } 3 3 6
420 3 $rc = 1;
421 }
422 }
423  
424 3 ▶ chmod $opts{mode}, $dstfile if exists $opts{mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"mode"} 2 1 3
425 chown $opts{owner}, $opts{group}, $dstfile
426 3 ▶ if exists $opts{owner} and exists $opts{group};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"owner"} and exists $opts{"group"} 2 1 3
Condition66%2/3
exists $opts{"owner"} and exists $opts{"group"}
!ll&&!rl&&r
102
MC/DC50%1/2
exists $opts{"owner"} and exists $opts{"group"}
exists $opts{"owner"} exists $opts{"group"}
Truth table66%2/3
A and B
A= exists $opts{"owner"}B= exists $opts{"group"}
ABresult
0X0
100
111
427 3 ▶ if ($rc)
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 3 0 3
428 {
429 3 $self->_add_file(%opts);
430 }
431 3 $rc;
432 }
433  
434 =item retrieve_with_callback
435  
436 =cut
437  
438 sub retrieve_with_callback
439 {
440 2 ▶ my $self = shift;
Subroutine retrieve_with_callback: called CC=12 SCAR=26.0
Pod documented
441 2 my %opts = @_;
442  
443 2 my $callback = $opts{callback};
444 2 my @files_to_extract;
445  
446 2 my $repos_dir = $self->_dir($opts{tag});
447 2 ▶ return undef unless -d $repos_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $repos_dir 0 2 2
448  
449 2 ▶ if (exists $opts{files})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{'files'}) { } 1 1 2
450 {
451 1 ▶ @files_to_extract = ref $opts{files} ? @{$opts{files}} : ($opts{files});
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'files'} ? : 1 0 1
452 }
453 else
454 {
455 1 @files_to_extract = $self->list_files(%opts);
456 }
457  
458 2 foreach my $file (@files_to_extract)
459 {
460 3 my $srcname = File::Spec->catfile($repos_dir, $file);
461 3 my $s = stat($srcname);
462  
463 3 ▶ return 0 unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 3 3
464  
465 3 my %cb_opts = (
466 mode => $s->mode(),
467 owner => $s->uid(),
468 group => $s->gid(),
469 filename => $file,
470 start => 1,
471 );
472 3 ▶ if (-l $srcname)
Branch: 1 branch
BranchTrueFalseTotal
if (-l $srcname) { } 0 3 3
473 {
474 0 ▶ $callback->(%cb_opts, target => readlink($srcname)) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$callback(%cb_opts, "target", readlink $srcname) or return 0 0 0 0
475 }
476 else
477 {
478 3 ▶ my $fh = IO::File->new($srcname, 'r') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($srcname, "r") or return 0 0 3 3
479 3 binmode $fh;
480  
481 3 my $buf;
482 3 ▶ while (my $r = sysread($fh, $buf, 32 * 1024))
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = sysread($fh, $buf, 32768)) 3 3 6
483 {
484 3 ▶ $callback->(%cb_opts, data => $buf) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$callback(%cb_opts, "data", $buf) or return 0 0 3 3
485 3 delete $cb_opts{start};
486 }
487 3 $buf = undef;
488 3 ▶ $callback->(%cb_opts, data => undef, end => 1) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$callback(%cb_opts, "data", undef, "end", 1) or return 0 0 3 3
489 }
490 }
491 2 return 1;
492 }
493  
494 =item get_size
495  
496 =cut
497  
498 sub get_size
499 {
500 1 ▶ my $self = shift;
Subroutine get_size: called CC=7 SCAR=20.9
Pod documented
501 1 my %opts = @_;
502  
503 1 my $repos_dir = $self->_dir($opts{tag});
504 1 ▶ return 0 unless -d $repos_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $repos_dir 0 1 1
505  
506 1 my @files;
507  
508 1 ▶ if (exists $opts{files})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{'files'}) { } 0 1 1
509 {
510 0 ▶ @files = ref $opts{files} ? @{$opts{files}} : ($opts{files});
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'files'} ? : 0 0 0
511 }
512 else
513 {
514 1 @files = $self->list_files(%opts);
515 }
516  
517 1 my $size;
518 1 my $dir = $self->_dir($opts{tag});
519 1 foreach my $f (@files)
520 {
521 2 my $s;
522 2 my $fullname = File::Spec->catdir($dir, $f);
523 2 ▶ if (-l $fullname)
Branch: 1 branch
BranchTrueFalseTotal
if (-l $fullname) { } 0 2 2
524 {
525 0 $s = 1024;
526 }
527 else
528 {
529 2 $s = -s _;
530 2 ▶ if ($s % 1024)
Branch: 1 branch
BranchTrueFalseTotal
if ($s % 1024) 2 0 2
531 {
532 2 $s -= $s % 1024;
533 2 $s += 1024;
534 }
535 }
536 2 $size += $s;
537 }
538 1 $size;
539 }
540  
541 =item list_files
542  
543 =cut
544  
545 sub list_files
546 {
547 3 ▶ my $self = shift;
Subroutine list_files: called CC=3 SCAR=11.1
Pod documented
548 3 my %opts = @_;
549  
550 3 my $dir = $self->_dir($opts{tag});
551 3 my @files;
552  
553 find(
554 {
555 wanted => sub {
556 10 ▶ return unless -f $File::Find::name;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless -f $File::Find::name 5 5 10
557 5 my $name = substr(
558 $File::Find::name,
559 length($dir) + 1
560 );
561 5 push @files, $name;
562 },
563 3 ▶ no_chdir => 1,
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 3 0 3
564 },
565 $dir
566 ) if -d $dir;
567 3 ▶ wantarray ? @files : \@files;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
568 }
569  
570 =item list_tags
571  
572 See L<Cache::Repository> for documentation on these.
573  
574 =cut
575  
576 sub list_tags
577 {
578 1 ▶ my $self = shift;
Subroutine list_tags: called CC=2 SCAR=7.0
Pod documented
579 1 my %opts = @_;
580  
581 1 my $r = $self->get_meta(tag=>'_r');
582 1 my @t = keys %$r;
583 1 ▶ wantarray ? @t : \@t;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
584 }
585  
586 =back
587  
588 =head1 AUTHOR
589  
590 Darin McBride - dmcbride@cpan.org
591  
592 =head1 COPYRIGHT
593  
594 Copyright 2005 Darin McBride.
595  
596 You may distribute under the terms of either the GNU General Public
597 License or the Artistic License, as specified in the Perl README file.
598  
599 =head1 BUGS
600  
601 See TODO file.
602  
603 =cut
604  
605 1 1;
606  
« blib/lib/Cache/Repository.pm ↑ Summary Build »