blib/lib/XML/Filter/Hekeln.pm

filter: Statementstmt 8.9% 12 / 134 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 17.6% 3 / 17 Podpod 0.0% 0 / 13 totaltotal 6.1% 15 / 243 CC 38 SCAR 50.2
CC
38
Cov
6%
script
306.0
style
156.0
new
110.0
CRAP 152.0
↑ Summary
1 # XML::Filter::Hekeln
2 # (c) 1999 GNU General Public License
3 # Michael Koehne Kraehe@Copyleft.de
4 # ---------------------------------------------------------------------------- #
5  
6 package XML::Filter::Hekeln;
7 1 ▶use UNIVERSAL;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use vars qw($VERSION $METHODS);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $VERSION = '0.06';
13 1 $METHODS = {
14 start_document => 1,
15 end_document => 1,
16 doctype_decl => 1,
17 processing_instruction => 1,
18 start_element => 1,
19 end_element => 1,
20 start_cdata => 1,
21 end_cdata => 1,
22 characters => 1
23 };
24  
25 # ---------------------------------------------------------------------------- #
26  
27 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod undocumented
28 0 my $proto = shift;
29 0 my $self = {};
30 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
31 0 bless($self, $class);
32  
33 0 ▶ my $args = ($#_ == 0) ? { %{ (shift) } } : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 0 ? : 0 0 0
34  
35 0 foreach (keys %$args) { $self->{$_}=$args->{$_}; }
36  
37 $self->{'Action'} = $self->script($self->{'Script'})
38 0 ▶ if $self->{'Script'} && !$self->{'Action'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Script"} and not $self->{"Action"} 0 0 0
Condition0%0/3
$self->{"Script"} and not $self->{"Action"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Script"} and not $self->{"Action"}
$self->{"Script"} not $self->{"Action"}
Truth table0%0/3
A and not(B)
A= $self->{"Script"}B= not $self->{"Action"}
ABresult
0X0
100
111
39  
40 0 ▶ $self->{'Action'} = {} unless ref($self->{'Action'}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"Action"} eq "HASH" 0 0 0
41 0 $self->{'Methods'} = {};
42 0 $self->{'Stack'} = [];
43  
44 0 ▶ if ($self->{'Handler'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Handler"}) 0 0 0
45 0 foreach (keys %$METHODS) {
46 $self->{'Methods'}{$_} =
47 0 ▶ $self->{'Handler'}->can($_) ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Handler'}->can($_) ? : 0 0 0
48 }
49 }
50  
51 0 return $self;
52 }
53  
54 0 ▶sub script {
Subroutine script: not called CC=17 SCAR=57.2
Pod undocumented
55 0 my ($self,$script) = @_;
56 0 my $hash = {};
57 0 my ($key,$val,$str);
58 0 my (@v, $o, $p);
59 0 my $action;
60  
61 0 ▶ local $SIG{__WARN__} = sub { die $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
62  
63 0 foreach (split /\n\n/, $script) {
64 0 ▶ if ($_ !~ /^#/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^#/) 0 0 0
65 0 ($key,$val) = split /\n/, $_, 2;
66 0 ▶ if ($key =~ /^[^:]+:[^:]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^[^:]+:[^:]+$/) 0 0 0
67  
68 0 $str = 'sub {'."\n\t";
69 0 $str .= 'my ($self,$param) = @_;'."\n\t";
70 0 $str .= 'my ($hash) = {};'."\n\t";
71  
72 0 $val =~ s/\~(\w+)\~/\$param->{$1}/g;
73  
74 0 SCRIPT_TO_SUB_SW: foreach (split /\n/, $val) {
75 0 @v = split /\t/, $_;
76 0 $o = shift @v;
77 0 $p = shift @v;
78  
79 0 ▶ if ($o eq '<') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "<") 0 0 0
80 0 $str .= '$hash->{Name}="'.$p.'"; ';
81 0 $str .= '$self->handle("start_element", $hash);';
82 0 $str .= "\n\t";
83 0 next SCRIPT_TO_SUB_SW;
84 }
85
86 0 ▶ if ($o eq '</') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "</") 0 0 0
87 0 $str .= '$hash->{Name}="'.$p.'"; ';
88 0 $str .= '$self->handle("end_element", $hash);';
89 0 $str .= "\n\t";
90 0 next SCRIPT_TO_SUB_SW;
91 }
92
93 0 ▶ if ($o eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "") 0 0 0
94 0 $str .= '$hash->{Data}="'.$p.'"; ';
95 0 $str .= '$self->handle("characters", $hash);';
96 0 $str .= "\n\t";
97 0 next SCRIPT_TO_SUB_SW;
98 }
99
100 0 ▶ if ($o eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "!") 0 0 0
101 0 $str .= $p;
102 0 $str .= "\n\t";
103 0 next SCRIPT_TO_SUB_SW;
104 }
105  
106 0 ▶ if ($o eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "+") 0 0 0
107 0 $str .= '$self->{Flag}{'.$p.'}=1;';
108 0 $str .= "\n\t";
109 0 next SCRIPT_TO_SUB_SW;
110 }
111 0 ▶ if ($o eq '++') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "++") 0 0 0
112 0 $str .= '$self->{Flag}{'.$p.'}=1;';
113 0 $str .= 'unshift @{$self->{Stack}}, "'.$p.'";';
114 0 $str .= "\n\t";
115 0 next SCRIPT_TO_SUB_SW;
116 }
117 0 ▶ if ($o eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "-") 0 0 0
118 0 $str .= '$self->{Flag}{'.$p.'}=0;';
119 0 $str .= "\n\t";
120 0 next SCRIPT_TO_SUB_SW;
121 }
122 0 ▶ if ($o eq '--') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "--") 0 0 0
123 0 $str .= '$self->{Flag}{'.$p.'}=0;';
124 0 $str .= 'shift @{$self->{Stack}} if $self->{Stack}[0] eq "'.$p.'";';
125 0 $str .= "\n\t";
126 0 next SCRIPT_TO_SUB_SW;
127 }
128 0 ▶ if ($o eq '?{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "?{") 0 0 0
129 0 $str .= 'if ($self->{Flag}{'.$p.'}) {';
130 0 $str .= "\n\t";
131 0 next SCRIPT_TO_SUB_SW;
132 }
133 0 ▶ if ($o eq '?}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "?}") 0 0 0
134 0 $str .= '}';
135 0 $str .= "\n\t";
136 0 next SCRIPT_TO_SUB_SW;
137 }
138 }
139 0 $str.= '}';
140 print STDERR '$hash->{'.$key.'}=eval "'.$str.'";'."\n\n"
141 0 ▶ if $self->{'Debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
142 0 $action = eval $str;
143 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
144 0 print STDERR "Error: $key: "; die $@
145 }
146 0 $hash->{$key}=$action;
147 }
148 }
149 }
150 0 return $hash;
151 }
152  
153 0 ▶sub start_document { my ($self, $param) = @_; $self->style('start_document',$param); }
Subroutine start_document: not called CC=1 SCAR=6.9
Pod undocumented
154 0 ▶sub end_document { my ($self, $param) = @_; $self->style('end_document',$param); }
Subroutine end_document: not called CC=1 SCAR=6.9
Pod undocumented
155 0 ▶sub doctype_decl { my ($self, $param) = @_; $self->style('doctype_decl',$param); }
Subroutine doctype_decl: not called CC=1 SCAR=6.9
Pod undocumented
156 0 ▶sub processing_instruction { my ($self, $param) = @_; $self->style('processing_instruction',$param); }
Subroutine processing_instruction: not called CC=1 SCAR=6.9
Pod undocumented
157 0 ▶sub start_element { my ($self, $param) = @_; $self->style('start_element',$param); }
Subroutine start_element: not called CC=1 SCAR=6.9
Pod undocumented
158 0 ▶sub end_element { my ($self, $param) = @_; $self->style('end_element',$param); }
Subroutine end_element: not called CC=1 SCAR=6.9
Pod undocumented
159 0 ▶sub start_cdata { my ($self, $param) = @_; $self->style('start_cdata',$param); }
Subroutine start_cdata: not called CC=1 SCAR=6.9
Pod undocumented
160 0 ▶sub end_cdata { my ($self, $param) = @_; $self->style('end_cdata',$param); }
Subroutine end_cdata: not called CC=1 SCAR=6.9
Pod undocumented
161 0 ▶sub characters { my ($self, $param) = @_; $self->style('characters',$param); }
Subroutine characters: not called CC=1 SCAR=6.9
Pod undocumented
162  
163 0 ▶sub style {
Subroutine style: not called CC=12 SCAR=50.5
Pod undocumented
164 0 my ($self,$event,$param) = @_;
165  
166 0 ▶ return unless $param;
Branch: 1 branch
BranchTrueFalseTotal
unless $param 0 0 0
167 0 ▶ return unless $event;
Branch: 1 branch
BranchTrueFalseTotal
unless $event 0 0 0
168 0 ▶ return unless $METHODS->{$event};
Branch: 1 branch
BranchTrueFalseTotal
unless $XML::Filter::Hekeln::METHODS->{$event} 0 0 0
169  
170 0 my $target = "*";
171 0 ▶ $target = $param->{'Name'} if $param->{'Name'};
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"Name"} 0 0 0
172 0 ▶ $target = $param->{'Target'} if $param->{'Target'};
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"Target"} 0 0 0
173 $target = $self->{Stack}[0] if ( $event eq 'characters' or
174 $event eq 'start_cdata' or
175 $event eq 'end_cdata' ) and
176 0 ▶ $self->{Flag}{$self->{Stack}[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $event eq "characters" || $event eq "start_cdata" || $event eq "end_cdata" and $self->{"Flag"}{$self->{"Stack"}[0]} 0 0 0
Condition0%0/9
$event eq "characters" || $event eq "start_cdata" || $event eq "end_cdata" and $self->{"Flag"}{$self->{"Stack"}[0]}
!ll&&!rl&&r
000
$event eq "characters" or $event eq "start_cdata" or $event eq "end_cdata"
l!l&&r!l&&!r
000
$event eq "characters" or $event eq "start_cdata"
l!l&&r!l&&!r
000
MC/DC0%0/4
$event eq "characters" || $event eq "start_cdata" || $event eq "end_cdata" and $self->{"Flag"}{$self->{"Stack"}[0]}
$event eq "characters" $event eq "start_cdata" $event eq "end_cdata" $self->{"Flag"}{$self->{"Stack"}[0]}
Truth table0%0/7
A or B or C and D
A= $event eq "characters"B= $event eq "start_cdata"C= $event eq "end_cdata"D= $self->{"Flag"}{$self->{"Stack"}[0]}
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
177  
178 0 my $action = $self->{'Action'}{$event.':'.$target};
179 0 ▶ return undef unless $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
180  
181 0 my $hash = $param;
182 0 ▶ $hash = $param->{'Attributes'} if $event eq 'start_element';
Branch: 1 branch
BranchTrueFalseTotal
if $event eq "start_element" 0 0 0
183  
184 0 return &$action($self,$hash);
185 }
186  
187 0 ▶sub handle {
Subroutine handle: not called CC=2 SCAR=17.9
Pod undocumented
188 0 my ($self,$event,$param) = @_;
189  
190 return $self->{'Handler'}->$event($param)
191 0 ▶ if ($self->{'Methods'}{$event}>1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Methods"}{$event} > 1 0 0 0
192 0 return undef;
193 }
194  
195 # ---------------------------------------------------------------------------- #
196  
197 1 1;
198 __END__
↑ Summary