line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perlanet::Trait::Cache; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
5023
|
use strict; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
249
|
|
4
|
6
|
|
|
6
|
|
36
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
195
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
45
|
use Moose::Role; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
58
|
|
7
|
6
|
|
|
6
|
|
35116
|
use namespace::autoclean; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
216
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Perlanet::Trait::Cache - cache feeds with CHI |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $perlanet = Perlanet->new_with_traits( |
16
|
|
|
|
|
|
|
traits => [ 'Perlanet::Trait::Cache' ] |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$perlanet->run; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Everytime a page is fetched it is cached first through CHI. This allows you |
24
|
|
|
|
|
|
|
to cache pages to a local disk for example, if the feed has not changed. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 cache |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
The L<Chi> cache object |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'cache'=> ( |
35
|
|
|
|
|
|
|
is => 'rw' |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around 'fetch_page' => sub { |
39
|
|
|
|
|
|
|
my $orig = shift; |
40
|
|
|
|
|
|
|
my ($self, $url) = @_; |
41
|
|
|
|
|
|
|
return URI::Fetch->fetch( |
42
|
|
|
|
|
|
|
$url, |
43
|
|
|
|
|
|
|
UserAgent => $self->ua, |
44
|
|
|
|
|
|
|
Cache => $self->cache || undef, |
45
|
|
|
|
|
|
|
ForceResponse => 1, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 AUTHOR |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Dave Cross, <dave@mag-sol.com> |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Copyright (c) 2010 by Magnum Solutions Ltd. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
58
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or, |
59
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |