line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::MethodFixtures::Storage::File; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1586
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
197
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
90
|
|
10
|
2
|
|
|
2
|
|
1498
|
use Data::Dump qw( dump ); |
|
2
|
|
|
|
|
11646
|
|
|
2
|
|
|
|
|
148
|
|
11
|
2
|
|
|
2
|
|
12
|
use Digest::MD5 qw( md5_hex ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89
|
|
12
|
2
|
|
|
2
|
|
1144
|
use Path::Tiny qw( path ); |
|
2
|
|
|
|
|
10184
|
|
|
2
|
|
|
|
|
114
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
11
|
use base 'Test::MethodFixtures::Storage'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1178
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ dir /); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $DEFAULT_DIR = 't/.methodfixtures'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
2
|
|
|
2
|
1
|
5276
|
my ( $class, $args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
50
|
|
|
8
|
$args ||= {}; |
24
|
2
|
50
|
|
|
|
8
|
unless ( $args->{dir} ) { |
25
|
0
|
|
|
|
|
0
|
path($DEFAULT_DIR)->mkpath; |
26
|
0
|
|
|
|
|
0
|
$args->{dir} = $DEFAULT_DIR; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
croak "Unable to access " |
30
|
|
|
|
|
|
|
. $args->{dir} |
31
|
|
|
|
|
|
|
. " (do you need to create the storage directory?)" |
32
|
2
|
100
|
66
|
|
|
82
|
unless -d $args->{dir} && -w $args->{dir}; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
11
|
return $class->SUPER::new($args); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub store { |
38
|
5
|
|
|
5
|
1
|
3491
|
my ( $self, $args ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
12
|
my $method = delete $args->{method}; |
41
|
5
|
|
|
|
|
12
|
my $key = delete $args->{key}; |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
|
|
|
14
|
my $storage = $self->_directory($method); |
44
|
5
|
|
|
|
|
183
|
$storage->mkpath; |
45
|
5
|
|
|
|
|
447
|
$storage->child( $self->_filename($key) )->spew_utf8( dump $args ); |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
6367
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub retrieve { |
51
|
7
|
|
|
7
|
1
|
5025
|
my ( $self, $args ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
7
|
|
|
|
|
12
|
my $method = $args->{method}; |
54
|
7
|
|
|
|
|
12
|
my $key = $args->{key}; |
55
|
|
|
|
|
|
|
|
56
|
7
|
|
|
|
|
18
|
my $storage = $self->_directory($method)->child( $self->_filename($key) ); |
57
|
7
|
100
|
|
|
|
2408
|
return unless $storage->is_file; |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
|
|
156
|
my $data = eval $storage->slurp_utf8(); |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
33
|
return $data; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# TODO test (and escape?) invalid characters |
65
|
|
|
|
|
|
|
sub _directory { |
66
|
12
|
|
|
12
|
|
21
|
my ( $self, $method ) = @_; |
67
|
12
|
|
|
|
|
100
|
$method =~ s/(::|')/-/g; |
68
|
12
|
|
|
|
|
42
|
return path( $self->dir, $method ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _filename { |
72
|
22
|
|
|
22
|
|
10755
|
my $self = shift; |
73
|
22
|
|
|
|
|
61
|
return md5_hex dump shift; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |