line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::MethodFixtures::Storage::File; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
892
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
169
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
103
|
|
10
|
2
|
|
|
2
|
|
1541
|
use Data::Dump qw( dump ); |
|
2
|
|
|
|
|
11758
|
|
|
2
|
|
|
|
|
126
|
|
11
|
2
|
|
|
2
|
|
13
|
use Digest::MD5 qw( md5_hex ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
134
|
|
12
|
2
|
|
|
2
|
|
2282
|
use Path::Tiny; |
|
2
|
|
|
|
|
20202
|
|
|
2
|
|
|
|
|
118
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
13
|
use base 'Test::MethodFixtures::Storage'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1119
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ dir /); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $DEFAULT_DIR = 't/.methodfixtures'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
4
|
|
|
4
|
1
|
4142
|
my ( $class, $args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
50
|
|
|
13
|
$args ||= {}; |
24
|
4
|
100
|
|
|
|
13
|
unless ($args->{dir}) { |
25
|
1
|
|
|
|
|
130
|
mkdir $DEFAULT_DIR; |
26
|
1
|
|
|
|
|
4
|
$args->{dir} = $DEFAULT_DIR; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
croak "Unable to access " . $args->{dir} |
30
|
4
|
100
|
66
|
|
|
129
|
unless -d $args->{dir} && -w $args->{dir}; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
23
|
return $class->SUPER::new($args); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub store { |
36
|
5
|
|
|
5
|
1
|
2048
|
my ( $self, $args ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
10
|
my $method = delete $args->{method}; |
39
|
5
|
|
|
|
|
8
|
my $key = delete $args->{key}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# for now only store on disk |
42
|
5
|
|
|
|
|
17
|
my $storage = path( $self->dir, $method ); |
43
|
5
|
|
|
|
|
170
|
$storage->mkpath; |
44
|
5
|
|
|
|
|
411
|
$storage->child( $self->_filename($key) )->spew_utf8( dump $args ); |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
4663
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub retrieve { |
50
|
7
|
|
|
7
|
1
|
3978
|
my ( $self, $args ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
13
|
my $method = $args->{method}; |
53
|
7
|
|
|
|
|
25
|
my $key = $args->{key}; |
54
|
|
|
|
|
|
|
|
55
|
7
|
|
|
|
|
20
|
my $storage = path( $self->dir, $method )->child( $self->_filename($key) ); |
56
|
7
|
100
|
|
|
|
762
|
return unless $storage->is_file; |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
143
|
my $data = eval $storage->slurp_utf8();; |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
33
|
return $data; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _filename { |
64
|
22
|
|
|
22
|
|
8077
|
my $self = shift; |
65
|
22
|
|
|
|
|
57
|
return md5_hex dump shift; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |