line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Dir::Hash; |
2
|
1
|
|
|
1
|
|
516
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
4
|
use File::Path qw(mkpath); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
7
|
1
|
|
|
1
|
|
4
|
use Digest::MD5 qw(md5_hex); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Class::XSAccessor { |
10
|
1
|
|
|
|
|
10
|
constructor => '_real_new', |
11
|
|
|
|
|
|
|
accessors => [qw( |
12
|
|
|
|
|
|
|
pattern |
13
|
|
|
|
|
|
|
hash_func |
14
|
|
|
|
|
|
|
basedir |
15
|
|
|
|
|
|
|
)] |
16
|
1
|
|
|
1
|
|
764757
|
}; |
|
1
|
|
|
|
|
9446
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
1
|
|
|
1
|
1
|
1113
|
my ($cls,%opts) = @_; |
22
|
1
|
|
|
|
|
4
|
my $hash_func = delete $opts{hash_func}; |
23
|
1
|
|
50
|
|
|
5
|
$hash_func ||= \&md5_hex; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
3
|
my $pattern = delete $opts{pattern}; |
26
|
1
|
|
50
|
|
|
4
|
$pattern ||= [1,2,2,4]; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
2
|
my $basedir = delete $opts{basedir}; |
29
|
1
|
|
50
|
|
|
5
|
$basedir ||= ""; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
10
|
my $self = __PACKAGE__->_real_new( |
32
|
|
|
|
|
|
|
pattern => $pattern, hash_func => $hash_func, |
33
|
|
|
|
|
|
|
basedir => $basedir); |
34
|
1
|
|
|
|
|
4
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub genpath { |
38
|
2
|
|
|
2
|
1
|
2474
|
my ($self,$key,$mkdir) = @_; |
39
|
2
|
|
|
|
|
12
|
my $hashstr = $self->hash_func->($key); |
40
|
2
|
|
|
|
|
20
|
my @chars = split(//, $hashstr); |
41
|
2
|
|
|
|
|
5
|
my @components; |
42
|
|
|
|
|
|
|
#Figure out our pattern.. |
43
|
2
|
|
|
|
|
4
|
my @templ = @{$self->pattern}; |
|
2
|
|
|
|
|
10
|
|
44
|
2
|
|
66
|
|
|
16
|
while (@templ && @chars) { |
45
|
6
|
|
|
|
|
11
|
my $n_elem = shift @templ; |
46
|
6
|
|
|
|
|
34
|
push @components, join("", splice(@chars, 0, $n_elem)); |
47
|
|
|
|
|
|
|
} |
48
|
2
|
|
|
|
|
4
|
my $fname = $hashstr; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
36
|
my $tree = File::Spec->catdir($self->basedir, @components); |
51
|
2
|
100
|
|
|
|
9
|
if ($mkdir) { |
52
|
1
|
50
|
|
|
|
1537
|
-d $tree or mkpath($tree); |
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
27
|
return File::Spec->catdir($tree, $fname); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |