line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Role::Cache::Driver::File; |
2
|
3
|
|
|
3
|
|
21
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
465
|
use Mojo::File; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
160
|
|
5
|
3
|
|
|
3
|
|
23
|
use Mojo::Util; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1265
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has root_dir => sub { $ENV{MOJO_USERAGENT_CACHE_DIR} || Mojo::File::tempdir('mojo-useragent-cache-XXXXX') }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub get { |
10
|
5
|
|
|
5
|
1
|
18
|
my $self = shift; |
11
|
5
|
|
|
|
|
15
|
my $file = $self->_file($self->root_dir, shift); |
12
|
5
|
100
|
|
|
|
174
|
return -e $file ? $file->slurp : undef; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub remove { |
16
|
1
|
|
|
1
|
1
|
733
|
my $self = shift; |
17
|
1
|
|
|
|
|
4
|
my $file = $self->_file($self->root_dir, shift); |
18
|
1
|
50
|
50
|
|
|
34
|
unlink $file or die "unlink $file: $!" if -e $file; |
19
|
1
|
|
|
|
|
94
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub set { |
23
|
2
|
|
|
2
|
1
|
596
|
my $self = shift; |
24
|
2
|
|
|
|
|
10
|
my $file = $self->_file($self->root_dir, shift); |
25
|
2
|
|
|
|
|
84
|
my $dir = Mojo::File->new($file->dirname); |
26
|
2
|
50
|
|
|
|
197
|
$dir->make_path({mode => 0755}) unless -d $dir; |
27
|
2
|
|
|
|
|
83
|
$file->spurt(shift); |
28
|
2
|
|
|
|
|
440
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _file { |
32
|
8
|
|
|
8
|
|
1000
|
my $self = shift; |
33
|
8
|
|
|
|
|
27
|
local $_ = Mojo::Util::url_escape(shift, '^A-Za-z0-9_/.-'); |
34
|
8
|
|
|
|
|
829
|
s#//#/#g; |
35
|
8
|
|
|
|
|
84
|
s#%#+#g; |
36
|
8
|
|
|
|
|
100
|
return Mojo::File->new($self->root_dir, $_); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding utf8 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Mojo::UserAgent::Role::Cache::Driver::File - Default cache driver for Mojo::UserAgent::Role::Cache |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $driver = Mojo::UserAgent::Role::Cache::Driver::File->new; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$driver->set($key, $data); |
52
|
|
|
|
|
|
|
$data = $driver->get($key); |
53
|
|
|
|
|
|
|
$driver->remove($key); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
L is the default cache driver for |
58
|
|
|
|
|
|
|
L. It should provide the same interface as |
59
|
|
|
|
|
|
|
L. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 root_dir |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$str = $self->root_dir; |
66
|
|
|
|
|
|
|
$self = $self->root_dir("/path/to/mojo-useragent-cache"); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Where to store the cached files. Defaults to the C |
69
|
|
|
|
|
|
|
environment variable or a L. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 METHODS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 get |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$data = $self->get($key); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Retrive data from the cache. Returns C if the C<$key> is not L. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 remove |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self = $self->remove($key); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Removes data from the cache, by C<$key>. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 set |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self = $self->set($key => $data); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Stores new C<$data> in the cache. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
L. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |