EP/Processor/EmbPerl.pm

filter: Statementstmt 12.3% 10 / 81 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 5 totaltotal 7.9% 13 / 164 CC 29 SCAR 53.1
CC
29
Cov
7%
ProcessNode
342.0
Process
110.0
new
12.0
CRAP 202.8
↑ Summary EP/Test.pm »
1 # -*- perl -*-
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Fcntl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 package XML::EP::Processor::EmbPerl;
8
9 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
10 0 my $proto = shift;
11 0 ▶ my $self = (@_ == 1) ? \%{ shift() } : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
12 0 ▶ bless($self, (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
13 }
14
15 0 ▶sub Process {
Subroutine Process: not called CC=10 SCAR=47.0
Pod undocumented
16 0 my($self, $req, $xml) = @_;
17
18 die "Failed to create package: Producer did not set a path"
19 0 ▶ unless $req->{'path'};
Branch: 1 branch
BranchTrueFalseTotal
unless $req->{"path"} 0 0 0
20 0 my $package = $req->{'path'};
21 0 $package =~ s/\./_/g;
22 0 $package =~ s/[^\/\\a-zA-Z0-9_]//g;
23 0 $package =~ s/[\/\\]/\:\:/g;
24 0 $package = "XML::EP::Processor::EmbPerl::Compiled::$package";
25
26 my $basedir = $req->{'embperl_basedir'} ||
27 0 ▶ exists($ENV{'DOCUMENT_ROOT'}) ? $ENV{'DOCUMENT_ROOT'} : "/var/embperl";
Branch: 1 branch
BranchTrueFalseTotal
$req->{'embperl_basedir'} || exists $ENV{'DOCUMENT_ROOT'} ? : 0 0 0
Condition0%0/3
$req->{"embperl_basedir"} or exists $ENV{"DOCUMENT_ROOT"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{"embperl_basedir"} or exists $ENV{"DOCUMENT_ROOT"}
$req->{"embperl_basedir"} exists $ENV{"DOCUMENT_ROOT"}
Truth table0%0/3
A or B
A= $req->{"embperl_basedir"}B= exists $ENV{"DOCUMENT_ROOT"}
ABresult
1X1
011
000
28
29 0 my $basefile = "$req->{'path'}c";
30 0 my $exists = -f $basefile;
31 0 ▶ if ($exists && (stat _)[9] >= $req->{'path_mtime'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exists and (stat _)[9] >= $req->{'path_mtime'}) { } 0 0 0
Condition0%0/3
$exists and (stat _)[9] >= $req->{"path_mtime"}
!ll&&!rl&&r
000
MC/DC0%0/2
$exists and (stat _)[9] >= $req->{"path_mtime"}
$exists (stat _)[9] >= $req->{"path_mtime"}
Truth table0%0/3
A and B
A= $existsB= (stat _)[9] >= $req->{"path_mtime"}
ABresult
0X0
100
111
32 # Slurp in the cached file.
33 0 require $basefile;
34 } else {
35 # Compile the file and try to save it
36 0 my $source = $self->Compile($req, $xml, $package);
37
38 0 local *FH;
39 0 ▶ if (open(FH, ">$basefile~") && (print FH $source) && close(FH)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open FH, ">$basefile~" and print FH $source and close FH) 0 0 0
Condition0%0/6
open FH, ">$basefile~" and print FH $source and close FH
!ll&&!rl&&r
000
open FH, ">$basefile~" and print FH $source
!ll&&!rl&&r
000
MC/DC0%0/3
open FH, ">$basefile~" and print FH $source and close FH
open FH, ">$basefile~" print FH $source close FH
Truth table0%0/4
A and B and C
A= open FH, ">$basefile~"B= print FH $sourceC= close FH
ABCresult
0XX0
10X0
1100
1111
40 0 unlink $basefile;
41 0 rename "$basefile~", $basefile;
42 }
43 0 eval $source;
44 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
45 }
46
47 0 my $document = $package->Document();
48 }
49
50 0 ▶sub Compile {
Subroutine Compile: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my($self, $req, $xml, $package) = @_;
52
53 0 $self->{'init'} = '';
54 0 my $source = $self->ProcessNode($xml);
55
56 0 $self->{'init'} =~ s/^/ /mg;
57 0 $source =~ s/^/ /mg;
58
59 0 qq[use strict;
60 package $package;
61 sub Document {
62 my \$self = shift;
63 my \$document = XML::DOM::Document->new();
64 my \$node = \$document;
65 my \$current;
66 my \@nodes;
67 $self->{'init'}
68
69 $source
70 \$document;
71 }
72 ];
73 }
74
75 0 ▶sub ProcessNode {
Subroutine ProcessNode: not called CC=18 SCAR=58.3
Pod undocumented
76 0 my($self, $node) = @_;
77 0 my $type = $node->getNodeType();
78 0 ▶ if ($type == XML::DOM::ELEMENT_NODE()) {
Branch: 8 branches
BranchTrueFalseTotal
if ($type == XML::DOM::ELEMENT_NODE()) { } 0 0 0
elsif ($type == XML::DOM::TEXT_NODE()) { } 0 0 0
elsif ($type == XML::DOM::CDATA_SECTION_NODE()) { } 0 0 0
elsif ($type == XML::DOM::PROCESSING_INSTRUCTION_NODE()) { } 0 0 0
elsif ($type == XML::DOM::COMMENT_NODE()) { } 0 0 0
elsif ($type == XML::DOM::DOCUMENT_NODE()) { } 0 0 0
elsif ($type == XML::DOM::DOCUMENT_TYPE_NODE()) { } 0 0 0
elsif ($type == XML::DOM::NOTATION_NODE()) { } 0 0 0
79 0 my $source = "push(\@nodes, \$node);\n" .
80 "\$current = \$document->createElement(" .
81 $self->QuoteString($node->getTagName()) . ");\n" .
82 "\$node->appendChild(\$current);\n" .
83 "\$node = \$current;\n";
84 0 ▶ if (my $attr = $node->getAttributes()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attr = $node->getAttributes) 0 0 0
85 0 ▶ for (my $i = 0; $i < $attr->getLength(); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $attr->getLength) 0 0 0
86 0 my $a = $attr->item($i);
87 0 $source .= '$node->setAttribute(' .
88 $self->QuoteString($a->getName()) .
89 ', ' . $self->QuoteString($a->getValue()) . ");\n";
90 }
91 }
92 0 ▶ for (my $child = $node->getFirstChild(); $child;
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 0 0 0
93 $child = $child->getNextSibling()) {
94 0 $source .= $self->ProcessNode($child);
95 }
96 0 $source . "\$node = pop \@nodes;\n";
97 } elsif ($type == XML::DOM::TEXT_NODE()) {
98 0 my $subs = "";
99 0 my $num = 0;
100 0 my $source = "{ my \$__result = '';\n";
101
102 0 my $text = $node->getData();
103 0 ▶ while ($text =~ s/(.*?)\[(?:\+(.*?)\+|\-(.*?)\-)\]//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/(.*?)\[(?:\+(.*?)\+|\-(.*?)\-)\]//) 0 0 0
104 0 my $prefix = $1;
105 0 my $plus_text = $2;
106 0 my $minus_text = $3;
107 0 ▶ if ($prefix ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix ne "") 0 0 0
108 0 $source .= " \$__result .= " .
109 $self->QuoteString($prefix) . ";\n";
110 }
111 0 ▶ if ($plus_text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plus_text) { } 0 0 0
112 0 $source .= " \$__result .= &{sub { $plus_text }};\n";
113 } else {
114 0 $source .= " $minus_text;\n";
115 }
116 }
117 $source .
118 0 ▶ ($text eq "" ?
Branch: 1 branch
BranchTrueFalseTotal
$text eq '' ? : 0 0 0
119 "" : " \$__result .= " . $self->QuoteString($text). ";\n") .
120 " \$node->appendChild(\$document->createTextNode(\$__result));\n}\n";
121 } elsif ($type == XML::DOM::CDATA_SECTION_NODE()) {
122 0 '$node->appendChild($document->createCDATASection(' .
123 $self->QuoteString($node->getData()) . "));\n";
124 } elsif ($type == XML::DOM::PROCESSING_INSTRUCTION_NODE()) {
125 0 '$node->appendChild($document->createProcessingInstruction(' .
126 $self->QuoteString($node->getTarget()) . ', ' .
127 $self->QuoteString($node->getData()) . "));\n";
128 } elsif ($type == XML::DOM::COMMENT_NODE()) {
129 0 '$node->appendChild($document->createComment(' .
130 $self->QuoteString($node->getData()) . "));\n";
131 } elsif ($type == XML::DOM::DOCUMENT_NODE()) {
132 0 my $source = "";
133 0 ▶ for (my $child = $node->getFirstChild(); $child;
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 0 0 0
134 $child = $child->getNextSibling()) {
135 0 $source .= $self->ProcessNode($child);
136 }
137 0 $source;
138 } elsif ($type == XML::DOM::DOCUMENT_TYPE_NODE()) {
139 0 my $source = "";
140 0 ▶ for (my $child = $node->getFirstChild(); $child;
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 0 0 0
141 $child = $child->getNextSibling()) {
142 0 $source .= $self->ProcessNode($child);
143 }
144 0 $source;
145 } elsif ($type == XML::DOM::NOTATION_NODE()) {
146 0 '$document->addNotation(' .
147 $self->QuoteString($node->getName()) . ", " .
148 $self->QuoteString($node->getBase()) . ", " .
149 $self->QuoteString($node->getSysId()) . ", " .
150 $self->QuoteString($node->getPubId()) . ");\n";
151 } else {
152 0 die("Failed to compile document: Unknown node type $type (",
153 ref($node), ")");
154 }
155 }
156
157 0 ▶sub QuoteString {
Subroutine QuoteString: not called CC=1 SCAR=6.9
Pod undocumented
158 0 my $self = shift; my $str = shift;
159 0 "\"" . quotemeta($str) . "\"";
160 }
161
162 1 1;
↑ Summary EP/Test.pm »