| 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
MC/DC0%0/1
$hash_func ||= \&File::Dir::Hash::md5_hex
$hash_func
Truth table50%1/2
A
A= $hash_func
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | my $pattern = delete $opts{pattern}; | |||||||||||||||||||||||||||
| 26 | 1 | ▶ | $pattern ||= [1,2,2,4]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$pattern ||= [1, 2, 2, 4]
MC/DC0%0/1
$pattern ||= [1, 2, 2, 4]
$pattern
Truth table50%1/2
A
A= $pattern
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | my $basedir = delete $opts{basedir}; | |||||||||||||||||||||||||||
| 29 | 1 | ▶ | $basedir ||= ""; | ||||||||||||||||||||||||||
|
Condition50%1/2
$basedir ||= ""
MC/DC0%0/1
$basedir ||= ""
$basedir
Truth table50%1/2
A
A= $basedir
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
@templ and @chars
MC/DC50%1/2
@templ and @chars
@templ
@chars
Truth table66%2/3
A and B
A= @templB= @chars
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | -d $tree or mkpath($tree); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 2 | return File::Spec->catdir($tree, $fname); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | 1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||