blib/lib/SWISH/API/Stat.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 87 CC 7 SCAR 19.5
CC
7
Cov
0%
check_stat
20.0
init
6.0
search
6.0
CRAP 7.1
1 package SWISH::API::Stat;
2  
3 use strict;
4 use warnings;
5 use base qw( SWISH::API::More );
6 use Path::Class::File::Stat;
7  
8 our $VERSION = '0.06';
9  
10 __PACKAGE__->mk_accessors(
11 qw(
12 paranoia_level
13 paranoia
14 )
15 );
16  
17 my %paranoia = (
18 Search => 1,
19 Execute => 2,
20 Results => 3,
21 Result => 4
22 );
23  
24 sub init {
25 my $self = shift;
26  
27 $self->{paranoia} ||= {%paranoia};
28 $self->paranoia_level(1) unless defined $self->paranoia_level;
29  
30 # new() will create our handle
31 # so we just have to stash our stat()s.
32  
33 my @i;
34 for my $f ( @{ $self->indexes } ) {
35 push( @i, Path::Class::File::Stat->new($f) );
36 }
37  
38 $self->indexes( \@i );
39 }
40  
41 sub DESTROY {
42 my $self = shift;
43 }
44  
45 sub reconnect {
46 my $self = shift;
47 $self->logger("re-connecting to swish-e index");
48 $self->handle( @{ $self->indexes } );
49 }
50  
51 sub check_stat {
52 my $self = shift;
53 my $reset = 0;
54 for my $i ( @{ $self->indexes } ) {
55  
56 $self->logger("stat'ing $i") if $self->debug;
57 $reset++ if $i->changed;
58 }
59 $self->reconnect if $reset;
60 }
61  
62 sub search {
63 my $self = shift;
64  
65 $self->check_stat
66 if $self->paranoia->{Search} <= $self->paranoia_level;
67  
68 $self->SUPER::search(@_);
69 }
70  
71 1;
72  
73 package SWISH::API::Stat::Search;
74 use strict;
75 use warnings;
76 use base qw( SWISH::API::More::Search );
77  
78 sub execute {
79 my $self = shift;
80 $self->base->check_stat
81 if $self->base->paranoia->{Execute} <= $self->base->paranoia_level;
82  
83 return $self->SUPER::execute(@_);
84 }
85  
86 1;
87  
88 __END__