File Coverage

blib/lib/Perlanet/Trait/Cache.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Perlanet::Trait::Cache;
2              
3 6     6   2466 use strict;
  6         10  
  6         146  
4 6     6   29 use warnings;
  6         12  
  6         174  
5              
6 6     6   22 use Moose::Role;
  6         6  
  6         54  
7 6     6   15281 use namespace::autoclean;
  6         44  
  6         47  
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;
64