File Coverage

blib/lib/Perlanet/Trait/Cache.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


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