File Coverage

blib/lib/WebSource/Filter/distance.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package WebSource::Filter::distance;
2 1     1   2064 use strict;
  1         2  
  1         37  
3 1     1   6 use Carp;
  1         2  
  1         65  
4              
5 1     1   40 use WebSource::Filter;
  0            
  0            
6             our @ISA = ('WebSource::Filter');
7              
8             =head1 NAME
9              
10             WebSource::Filter::script - Use a script for filtering
11              
12             =head1 DESCRIPTION
13              
14             Each time an object passes thru this filter a meta-information named distance
15             is incremented by 1. Once this meta-information has reached the maximum
16             the item is filtered.
17              
18             =head1 SYNOPSIS
19              
20             B
21              
22            
23            
24            
25            
26            
27              
28              
29             =head1 METHODS
30              
31             =cut
32              
33              
34              
35             sub new {
36             my $class = shift;
37             my %params = @_;
38             my $self = bless \%params, $class;
39             $self->SUPER::_init_;
40              
41             $self->{maximum} or $self->{maximum} = 5;
42             $self->log(2,"Maximum set to ",$self->{maximum});
43             return $self;
44             }
45              
46             sub keep {
47             my $self = shift;
48             my $env = shift;
49             $self->log(6,"Distance was '",$env->{distance},"'");
50             if($env->{distance}) {
51             $env->{distance} += 1;
52             } else {
53             $env->{distance} = 1;
54             }
55             $self->log(6,"Distance is now '",$env->{distance},"'");
56             $self->log(5,"Distance updated env is now : ",$env->as_string);
57             return (! $self->{maximum}) || ($env->{distance} <= $self->{maximum});
58             }
59              
60             =head1 SEE ALSO
61              
62             WebSource
63              
64             =cut
65              
66             1;
67