line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::WURFL::ScientiaMobile::Cache; |
2
|
1
|
|
|
1
|
|
8725
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
requires qw( |
5
|
|
|
|
|
|
|
getDevice |
6
|
|
|
|
|
|
|
getDeviceFromID |
7
|
|
|
|
|
|
|
setDevice |
8
|
|
|
|
|
|
|
setDeviceFromID |
9
|
|
|
|
|
|
|
getMtime |
10
|
|
|
|
|
|
|
setMtime |
11
|
|
|
|
|
|
|
purge |
12
|
|
|
|
|
|
|
incrementHit |
13
|
|
|
|
|
|
|
incrementMiss |
14
|
|
|
|
|
|
|
incrementError |
15
|
|
|
|
|
|
|
getCounters |
16
|
|
|
|
|
|
|
resetCounters |
17
|
|
|
|
|
|
|
getReportAge |
18
|
|
|
|
|
|
|
resetReportAge |
19
|
|
|
|
|
|
|
stats |
20
|
|
|
|
|
|
|
close |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Net::WURFL::ScientiaMobile::Cache - Role that all Cache providers must implement to be compatible with the WURFL Cloud Client |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Net::WURFL::ScientiaMobile::Cache::MyProvider; |
30
|
|
|
|
|
|
|
use Moo; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
with 'Net::WURFL::ScientiaMobile::Cache'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub getDevice { |
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
my ($user_agent) = @_; |
37
|
|
|
|
|
|
|
... |
38
|
|
|
|
|
|
|
return $capabilities; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
.... |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This L class defines the methods that all Cache providers must implement to be used with |
45
|
|
|
|
|
|
|
the L module. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
The following implementations are currently available, but you can write your own: |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over 4 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item L |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item L |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item L |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 getDevice |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $capabilities = $cache->getDevice($user_agent); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Get the device capabilities for the given user agent from the cache provider. |
66
|
|
|
|
|
|
|
It accepts the user agent name as a string and returns the capabilities as a hashref, or false |
67
|
|
|
|
|
|
|
if the device wasn't found in cache. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 getDeviceFromID |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $capabilities = $cache->getDeviceFromID($wurfl_device_id); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Get the device capabilities for the given user agent from the cache provider. |
74
|
|
|
|
|
|
|
It accepts the device ID as a string and returns the capabilities as a hashref, or false |
75
|
|
|
|
|
|
|
if the device wasn't found in cache. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 setDevice |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$cache->setDevice($user_agent, $capabilities); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Stores the given user agent with the given device capabilities in the cache provider for the given |
82
|
|
|
|
|
|
|
time period. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 setDeviceFromID |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$cache->setDeviceFromID($wurfl_device_id, $capabilities); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Stores the given user agent with the given device capabilities in the cache provider for the given |
89
|
|
|
|
|
|
|
time period. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 getMtime |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $time = $cache->getMtime; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Gets the last loaded WURFL timestamp from the cache provider - this is used to detect when a new |
96
|
|
|
|
|
|
|
WURFL has been loaded on the server. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 setMtime |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$cache->setMtime($time); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Sets the last loaded WURFL timestamp in the cache provider. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 purge |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$cache->purge; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Deletes all the cached devices and the mtime from the cache provider. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 incrementHit |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$cache->incrementHit; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Increments the count of cache hits. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 incrementMiss |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$cache->incrementMiss; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Increments the count of cache misses. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 incrementError |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$cache->incrementError; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Increments the count of errors. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 getCounters |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $counters = $cache->getCounters; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns an array of all the counters. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 resetCounters |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$cache->resetCounters; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Resets the counters to zero. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 getReportAge |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $seconds = $cache->getReportAge; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Returns the number of seconds since the counters report was last sent. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 resetReportAge |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$cache->resetReportAge; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Resets the report age to zero. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 stats |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $stats = $cache->stats; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Gets statistics from the cache provider like memory usage and number of cached devices. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 close |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$cache->close; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Close the connection to the cache provider. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SEE ALSO |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Alessandro Ranellucci C<< >> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2012, ScientiaMobile, Inc. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
177
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |