WebSource/Filter.pm

filter: Statementstmt 29.7% 11 / 37 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 33.3% 1 / 3 totaltotal 26.3% 15 / 57 CC 7 SCAR 23.3
CC
7
Cov
23%
handle
20.0
keep
12.0
_init_
6.0
CRAP 10.2
« WebSource/Filter/script.pm ↑ Summary WebSource/Cache.pm »
1 package WebSource::Filter;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use WebSource::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our @ISA = ('WebSource::Module');
7  
8 =head1 NAME
9  
10 WebSource::Format - Format XML Nodes
11  
12 =head1 DESCRIPTION
13  
14 A filter operator allows to select which input elements will be returned
15 as output or not.
16  
17 The default filter operator is a uniquness operator. It keeps track of
18 items which it has had as input on only returns those which have never
19 been seen yet.
20  
21 It is declared as follows :
22  
23 <ws:filter name="opname" forward-to="ops" />
24  
25 The different current types of other operators are :
26  
27 =over 2
28  
29 =item B<tests> : Filters elements based on a series of tests
30  
31 =item B<distance> : Filters elements based on the number of times they or a
32 parent object passed thru the filter
33  
34 =item B<script> : Filters elements based on an external or inline script
35  
36 =item B<type> : Filters elements based on their MIME type
37  
38 =back
39  
40 For more details on each type of filter see the corresponding
41 WebSource::Filter::<type> man page.
42  
43 =head1 SYNOPSIS
44  
45 =head1 METHODS
46  
47 =cut
48  
49 0 ▶sub _init_ {
Subroutine _init_: not called CC=2 SCAR=17.9
50 0 my $self = shift;
51 0 $self->SUPER::_init_;
52 0 $self->{seen} = {};
53 0 ▶ if(my $wsd = $self->{wsdnode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $wsd = $self->{"wsdnode"}) 0 0 0
54 0 $self->{as} = $wsd->getAttribute("as");
55 }
56 }
57  
58 0 ▶sub handle {
Subroutine handle: not called CC=4 SCAR=30.0
Pod documented
59 0 my $self = shift;
60 0 my $env = shift;
61 0 my $keep = $self->keep($env);
62 0 foreach my $l (@{$self->{listeners}}) {
63 0 $self->log(4,"Sending feedback to ",$l->{name}," : ",$env->as_string);
64 0 $l->feedback($env,$keep);
65 }
66 0 ▶ $self->log(1,$keep ? "kept" : "filtered");
Branch: 1 branch
BranchTrueFalseTotal
$keep ? : 0 0 0
67 0 ▶ return $keep ? ($env) : ();
Branch: 1 branch
BranchTrueFalseTotal
$keep ? : 0 0 0
68 }
69  
70 0 ▶sub keep {
Subroutine keep: not called CC=3 SCAR=24.8
Pod undocumented
71 0 my $self = shift;
72 0 my $env = shift;
73 0 ▶ my $str = $self->{as} eq "uri" ? $env->dataAsURI : $env->dataString;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'as'} eq 'uri' ? : 0 0 0
74 0 ▶ if($self->{seen}->{$str}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'seen'}{$str}) { } 0 0 0
75 0 $self->log(4,"$str was already seen");
76 0 return 0;
77 } else {
78 0 $self->{seen}->{$str} = 1;
79 0 $self->log(4,"$str has never been seen");
80 0 return 1;
81 }
82 }
83  
84 0 ▶sub listeners {
Subroutine listeners: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my $self = shift;
86 0 push @{$self->{listeners}}, @_;
87 }
88  
89 =head1 SEE ALSO
90  
91 WebSource
92  
93 =cut
94  
95 1 1;
96  
« WebSource/Filter/script.pm ↑ Summary WebSource/Cache.pm »