| 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
MC/DC0%0/1
$hash_func ||= \&File::Dir::Hash::md5_hex
$hash_func
Truth table0%0/2
A
A= $hash_func
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $pattern = delete $opts{pattern}; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | $pattern ||= [1,2,2,4]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$pattern ||= [1, 2, 2, 4]
MC/DC0%0/1
$pattern ||= [1, 2, 2, 4]
$pattern
Truth table0%0/2
A
A= $pattern
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $basedir = delete $opts{basedir}; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | $basedir ||= ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
$basedir ||= ""
MC/DC0%0/1
$basedir ||= ""
$basedir
Truth table0%0/2
A
A= $basedir
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
@templ and @chars
MC/DC0%0/2
@templ and @chars
@templ
@chars
Truth table0%0/3
A and B
A= @templB= @chars
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | -d $tree or mkpath($tree); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | return join("/", $tree, $fname); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||