line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::MethodFixtures::Storage::File; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
727
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
57
|
|
5
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
168
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
44
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
97
|
|
10
|
2
|
|
|
2
|
|
1554
|
use Data::Dump qw( dump ); |
|
2
|
|
|
|
|
11444
|
|
|
2
|
|
|
|
|
131
|
|
11
|
2
|
|
|
2
|
|
13
|
use Digest::MD5 qw( md5_hex ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
86
|
|
12
|
2
|
|
|
2
|
|
2271
|
use Path::Tiny; |
|
2
|
|
|
|
|
20126
|
|
|
2
|
|
|
|
|
137
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
13
|
use base 'Test::MethodFixtures::Storage'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1102
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ dir /); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $DEFAULT_DIR = 't/.methodfixtures'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
4
|
|
|
4
|
1
|
4752
|
my ( $class, $args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
50
|
|
|
14
|
$args ||= {}; |
24
|
4
|
100
|
|
|
|
16
|
unless ($args->{dir}) { |
25
|
1
|
|
|
|
|
133
|
mkdir $DEFAULT_DIR; |
26
|
1
|
|
|
|
|
4
|
$args->{dir} = $DEFAULT_DIR; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
croak "Unable to access " . $args->{dir} |
30
|
4
|
100
|
66
|
|
|
131
|
unless -d $args->{dir} && -w $args->{dir}; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
26
|
return $class->SUPER::new($args); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub store { |
36
|
5
|
|
|
5
|
1
|
2634
|
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
|
|
|
|
|
18
|
my $storage = path( $self->dir, $method ); |
43
|
5
|
|
|
|
|
174
|
$storage->mkpath; |
44
|
5
|
|
|
|
|
410
|
$storage->child( $self->_filename($key) )->spew_utf8( dump $args ); |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
4609
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub retrieve { |
50
|
7
|
|
|
7
|
1
|
4740
|
my ( $self, $args ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
15
|
my $method = $args->{method}; |
53
|
7
|
|
|
|
|
29
|
my $key = $args->{key}; |
54
|
|
|
|
|
|
|
|
55
|
7
|
|
|
|
|
20
|
my $storage = path( $self->dir, $method )->child( $self->_filename($key) ); |
56
|
7
|
100
|
|
|
|
770
|
return unless $storage->is_file; |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
140
|
my $data = eval $storage->slurp_utf8();; |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
33
|
return $data; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _filename { |
64
|
22
|
|
|
22
|
|
9882
|
my $self = shift; |
65
|
22
|
|
|
|
|
60
|
return md5_hex dump shift; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |