blib/lib/File/Dir/Hash.pm

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