line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Dir::Hash; |
2
|
1
|
|
|
1
|
|
14166
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
3
|
use File::Path qw(mkpath); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
65
|
|
5
|
1
|
|
|
1
|
|
4
|
use Digest::MD5 qw(md5_hex); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
6
|
|
|
|
|
|
|
use Class::XSAccessor { |
7
|
1
|
|
|
|
|
5
|
constructor => '_real_new', |
8
|
|
|
|
|
|
|
accessors => [qw( |
9
|
|
|
|
|
|
|
pattern |
10
|
|
|
|
|
|
|
hash_func |
11
|
|
|
|
|
|
|
basedir |
12
|
|
|
|
|
|
|
)] |
13
|
1
|
|
|
1
|
|
428
|
}; |
|
1
|
|
|
|
|
2154
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01_0'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
1
|
|
my ($cls,%opts) = @_; |
19
|
0
|
|
|
|
|
|
my $hash_func = delete $opts{hash_func}; |
20
|
0
|
|
0
|
|
|
|
$hash_func ||= \&md5_hex; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $pattern = delete $opts{pattern}; |
23
|
0
|
|
0
|
|
|
|
$pattern ||= [1,2,2,4]; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $basedir = delete $opts{basedir}; |
26
|
0
|
|
0
|
|
|
|
$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
|
|
|
0
|
1
|
|
my ($self,$key,$mkdir) = @_; |
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}; |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
0
|
|
|
|
while (@templ && @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
|
0
|
|
|
|
|
if ($mkdir) { |
49
|
0
|
0
|
|
|
|
|
-d $tree or mkpath($tree); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
return join("/", $tree, $fname); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |