WebSource/Filter/script.pm

filter: Statementstmt 33.3% 14 / 42 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 66.6% 2 / 3 totaltotal 32.2% 20 / 62 CC 6 SCAR 26.4
CC
6
Cov
27%
new
30.0
handle
6.0
keep
2.0
CRAP 14.0
« WebSource/Format.pm ↑ Summary WebSource/Filter.pm »
1 package WebSource::Filter::script;
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 File::Temp qw/tmpnam/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use WebSource::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our @ISA = ('WebSource::Filter');
9  
10 =head1 NAME
11  
12 WebSource::Filter::script - Use a script for filtering
13  
14 =head1 DESCRIPTION
15  
16 A filter operator of type script allows to determine what to do with
17 the input based on an inline or external script. The data of the input
18 is passed as an argument to the script.
19  
20 =head1 SYNOPSIS
21  
22 B<In wsd file...>
23  
24 <ws:filter name="somename" type="script" forward-to"somemodules">
25 <!-- put your script here -->
26 </ws:filter>
27  
28 or
29  
30 <ws:filter name="somename" type="script" script-file="somefile"
31 forward-to="somemodules" />
32  
33 =head1 METHODS
34  
35 =cut
36  
37  
38  
39 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
40 0 my $class = shift;
41 0 my %params = @_;
42 0 my $self = bless \%params, $class;
43 0 $self->SUPER::_init_;
44  
45 0 $self->{seen} = {};
46 0 my $wsd = $self->{wsdnode};
47 0 ▶ if($wsd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wsd) 0 0 0
48 0 ▶ if($wsd->hasAttribute("script-file")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wsd->hasAttribute('script-file')) { } 0 0 0
49 0 $self->{scriptfile} = $wsd->getAttribute("script-file");
50 } else {
51 0 my $sf;
52 0 ($sf,$self->{scriptfile}) = tmpnam();
53 0 my $content = $wsd->textContent;
54 0 $content =~ s/^[\s\n]+//;
55 0 print $sf $content;
56 0 close($sf);
57 0 system("chmod +x " . $self->{scriptfile});
58 }
59 }
60 0 ▶ $self->{scriptfile} or die "No script file set for ",$self->{name},"\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"scriptfile"} or die "No script file set for ", $self->{"name"}, "\n" 0 0 0
61 0 ▶ -x $self->{scriptfile} or die $self->{scriptfile}, " is not executable\n";
Branch: 1 branch
BranchTrueFalseTotal
-x $self->{"scriptfile"} or die $self->{"scriptfile"}, " is not executable\n" 0 0 0
62 0 return $self;
63 }
64  
65 0 ▶sub handle {
Subroutine handle: not called CC=2 SCAR=17.9
Pod documented
66 0 my $self = shift;
67 0 ▶ return map { $self->keep($_) ? $_ : () } @_;
Branch: 1 branch
BranchTrueFalseTotal
$self->keep($_) ? : 0 0 0
68 }
69  
70 0 ▶sub keep {
Subroutine keep: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my $self = shift;
72 0 my $env = shift;
73 0 my $val = $env->dataString;
74 0 my $script = $self->{scriptfile};
75 0 my $res = system($script,$val);
76 0 return $res == 0;
77 }
78  
79 =head1 SEE ALSO
80  
81 WebSource
82  
83 =cut
84  
85 1 1;
86  
« WebSource/Format.pm ↑ Summary WebSource/Filter.pm »