EP/Processor/XSLT.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« EP.pm ↑ Summary EP/Config.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 1 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LWP::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use XML::DOM ();
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use XML::EP::Processor::XSLTParser ();
10
11 package XML::EP::Processor::XSLT;
12
13 sub new {
14 my $proto = shift;
15 my $self = (@_ == 1) ? \%{ shift() } : { @_ };
16 bless($self, (ref($proto) || $proto));
17
18 }
19
20 sub Process {
21 my($self, $req, $xml) = @_;
22
23 die "Missing href attribute in stylesheet declaration"
24 unless $self->{'pidata'} =~ /\bhref=\"(.*?)\"/;
25 my $url = $1;
26 my $base = $req->Request()->Uri();
27 $url = URI::URL->new($url, $base)->abs();
28 my $content = LWP::Simple::get($url)
29 || die "Failed to access stylesheet $url.\n";
30 my $parser = XML::DOM::Parser->new();
31 my $stylesheet = $parser->parse($content);
32
33 my $xslt = XML::EP::Processor::XSLTParser->new('xmlDocument' => $xml,
34 'xslDocument' => $stylesheet);
35
36 my $result = $xslt->process_project();
37
38 # The XSLT parser returns a document fragment. We have to replace
39 # the old document contents with the document fragments.
40 while (my $child = $xml->getFirstChild()) {
41 $xml->removeChild($child);
42 }
43 my $child = $result->getFirstChild();
44 while ($child) {
45 my $c = $child;
46 $child = $c->getNextSibling();
47 next if $c->getNodeType() == XML::DOM::TEXT_NODE; # Skip blanks
48 $result->removeChild($c);
49 $xml->appendChild($c);
50 }
51 $xml;
52 }
53
54 1;
« EP.pm ↑ Summary EP/Config.pm »