EP/Control.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« EP/Error.pm ↑ Summary EP/Processor/XSLTParser.pm »
1 # -*- perl -*-
2
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 0 ▶use XML::DOM ();
Subroutine BEGIN: called CC=1 SCAR=2.6
5
6 package XML::EP::Control;
7
8 $XML::EP::Control::VERSION = '0.01';
9
10
11 sub new {
12 my $proto = shift;
13 my $self = (@_ == 1) ? \%{ shift() } : { @_ };
14 bless($self, (ref($proto) || $proto));
15 }
16
17 sub CreatePipe {
18 my $self = shift; my $ep = shift;
19 my $class = $ep->{cfg}->{Producer} || "XML::EP::Producer::File";
20 $ep->Require($class);
21 my $producer = $class->new();
22 my $xml = $producer->Produce($ep);
23 my $processors = $ep->{cfg}->{Processors} || [];
24 my $formatter = $ep->{cfg}->{Formatter} || "XML::EP::Formatter::HTML";
25 my $elem = $xml->getFirstChild();
26 while ($elem) {
27 my $pi = $elem;
28 $elem = $pi->getNextSibling();
29 next unless $pi->getNodeType() ==
30 XML::DOM::PROCESSING_INSTRUCTION_NODE();
31 if ($pi->getTarget() eq "xmlep:processor") {
32 my $data = $pi->getData();
33 if ($data =~ /^\s*(\S+)\s*(.*)/) {
34 $ep->Require($1);
35 push(@$processors, $1->new('pidata' => $2));
36 $xml->removeChild($pi);
37 } else {
38 die "Failed to parse processor instruction: $data";
39 }
40 } elsif ($pi->getTarget() eq "xml-stylesheet") {
41 my $data = $pi->getData();
42 require XML::EP::Processor::XSLT;
43 push(@$processors,
44 XML::EP::Processor::XSLT->new('pidata' => $data));
45 $xml->removeChild($pi);
46 } elsif ($pi->getTarget() eq "xmlep:formatter") {
47 my $data = $pi->getData();
48 if ($data =~ /^\s*(\S+)\s*(.*)/) {
49 $ep->Require($1);
50 $formatter = $1->new('pidata' => $2);
51 $xml->removeChild($pi);
52 } else {
53 die "Failed to parse formatter instruction: $data";
54 }
55 }
56 }
57 $ep->Formatter($formatter);
58 $ep->Processors($processors);
59 $xml;
60 }
61
62
63 __END__
« EP/Error.pm ↑ Summary EP/Processor/XSLTParser.pm »