File Coverage

blib/lib/Sman/Man/Cache/FileCache.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Sman::Man::Cache::FileCache;
2              
3             #$Id: FileCache.pm,v 1.7 2006/02/27 02:07:19 joshr Exp $
4              
5 1     1   10975 use Cache::FileCache;
  0            
  0            
6              
7             use base 'Sman::Man::Cache';
8             use fields qw( filecache );
9              
10             # pass a dir to store the cache data in
11             sub new {
12             my $class = shift;
13             my $dir = shift;
14             my $self = fields::new($class);
15              
16             $self->SUPER::new(); # init base fields
17              
18             if (defined($dir)) {
19             my %hash = ( 'namespace' => 'sman', 'default_expires_in' => "1 month" );
20             $^W=0; # avoid pseudo-hash warnings on perl 5.8.0
21             $self->{filecache} = new Cache::FileCache( \%hash );
22             }
23             return $self;
24             }
25              
26             sub get {
27             my $self = shift;
28             my $key = shift;
29             my $val;
30             #local $^W = 0; # hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
31             no warnings; # hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
32             if (defined($self->{filecache}) && ($val = $self->{filecache}->get($key) ) ) {
33             return $val;
34             }
35             return undef;
36             }
37             sub set {
38             my $self = shift;
39             my $key = shift;
40             # we handle rawdata right from $_[0]. Why not?
41             #local $^W = 0; # hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
42             no warnings; # hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
43             $self->{filecache}->set($key, $_[0]) if ($self->{filecache});
44             }
45             sub Clear {
46             my $self = shift;
47             my $cache = $self->{filecache};
48             defined($cache) && ($cache->Clear());
49             }
50              
51             1;
52              
53             =head1 NAME
54              
55             Sman::Man::Cache::FileCache - Cache converted manpages in a Cache::FileCache
56              
57             =head1 SYNOPSIS
58              
59             # this module is intended for internal use by sman-update
60             my $cache = new Sman::Man::Cache::FileCache();
61             $cache->set("/usr/man/man3/ls.3", "some stuff");
62            
63             # ..later...
64            
65             my $ret = $cache->get("/usr/man/man3/ps.3");
66             # $ret will be undef if data not found.
67            
68             =head1 DESCRIPTION
69              
70             Uses a Cache::FileCache to store raw data for use by Sman::Man::Convert.
71              
72             =head1 AUTHOR
73            
74             Josh Rabinowitz
75            
76             =head1 SEE ALSO
77            
78             L, L, L, L
79            
80             =cut