blib/lib/File/Dir/Hash.pm

filter: Statementstmt 42.5% 17 / 40 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 34.7% 24 / 69 SCAR 33.7
CC
8
Cov
31%
genpath
30.0
new
20.0
BEGIN
1.0
CRAP 29.1
↑ Summary
1 package File::Dir::Hash;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use Class::XSAccessor {
7 2 constructor => '_real_new',
8 accessors => [qw(
9 pattern
10 hash_func
11 basedir
12 )]
13 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our $VERSION = '0.01_0';
16  
17 sub new {
18 0 ▶ my ($cls,%opts) = @_;
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
19 0 my $hash_func = delete $opts{hash_func};
20 0 ▶ $hash_func ||= \&md5_hex;
Condition0%0/2
$hash_func ||= \&File::Dir::Hash::md5_hex
l!l
00
MC/DC0%0/1
$hash_func ||= \&File::Dir::Hash::md5_hex
$hash_func
Truth table0%0/2
A
A= $hash_func
Aresult
11
00
21
22 0 my $pattern = delete $opts{pattern};
23 0 ▶ $pattern ||= [1,2,2,4];
Condition0%0/2
$pattern ||= [1, 2, 2, 4]
l!l
00
MC/DC0%0/1
$pattern ||= [1, 2, 2, 4]
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
24
25 0 my $basedir = delete $opts{basedir};
26 0 ▶ $basedir ||= "";
Condition0%0/2
$basedir ||= ""
l!l
00
MC/DC0%0/1
$basedir ||= ""
$basedir
Truth table0%0/2
A
A= $basedir
Aresult
11
00
27
28 0 my $self = __PACKAGE__->_real_new(
29 pattern => $pattern, hash_func => $hash_func,
30 basedir => $basedir);
31 0 return $self;
32 }
33  
34 sub genpath {
35 0 ▶ my ($self,$key,$mkdir) = @_;
Subroutine genpath: not called CC=5 SCAR=34.0
Pod documented
36 0 my $hashstr = $self->hash_func->($key);
37 0 my @chars = split(//, $hashstr);
38 0 my @components;
39 #Figure out our pattern..
40 0 my @templ = @{$self->pattern};
41 0 ▶ while (@templ && @chars) {
Branch: 1 branch
BranchTrueFalseTotal
if (@templ and @chars) 0 0 0
Condition0%0/3
@templ and @chars
!ll&&!rl&&r
000
MC/DC0%0/2
@templ and @chars
@templ @chars
Truth table0%0/3
A and B
A= @templB= @chars
ABresult
0X0
100
111
42 0 my $n_elem = shift @templ;
43 0 push @components, join("", splice(@chars, 0, $n_elem));
44 }
45 0 my $fname = $hashstr;
46
47 0 my $tree = join("/", $self->basedir, @components);
48 0 ▶ if ($mkdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mkdir) 0 0 0
49 0 ▶ -d $tree or mkpath($tree);
Branch: 1 branch
BranchTrueFalseTotal
-d $tree or mkpath($tree) 0 0 0
50 }
51 0 return join("/", $tree, $fname);
52 }
53  
54 2 1;
55  
56 __END__
↑ Summary