Schematron/LibXSLT.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 46 CC 4 SCAR 24.0
CC
4
Cov
0%
verify
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
1 package XML::Schematron::LibXSLT;
2
3 use Moose::Role;
4 use namespace::autoclean;
5
6 use XML::LibXSLT;
7 use XML::LibXML;
8
9
10 has xml_parser => (
11 is => 'ro',
12 isa => 'XML::LibXML',
13 required => 1,
14 default => sub { XML::LibXML->new(); },
15 );
16
17 has xslt_processor => (
18 is => 'ro',
19 isa => 'XML::LibXSLT',
20 required => 1,
21 default => sub { XML::LibXSLT->new(); },
22 );
23
24 sub verify {
25 my $self = shift;
26 my $xml = shift;
27
28 $self->parse_schema if $self->has_schema;
29
30 my $template = $self->dump_xsl;
31 my $xml_doc;
32
33 if ( $xml =~ /^\s*<\?\s*(xml|XML)\b/ ) {
34 $xml_doc = $self->xml_parser->parse_string($xml);
35 }
36 else {
37 $xml_doc = $self->xml_parser->parse_file($xml);
38 }
39
40 my $style_doc = $self->xml_parser->parse_string($template);
41
42 my $stylesheet = $self->xslt_processor->parse_stylesheet($style_doc);
43 my $result = $stylesheet->transform($xml_doc);
44 my $ret_string = $stylesheet->output_as_bytes($result);
45
46 if (wantarray) {
47 my @ret_array = split "\n", $ret_string;
48 return @ret_array;
49 }
50
51 return $ret_string;
52 }
53
54 with 'XML::Schematron::XSLTProcessor';
55
56 1;
57
58 __END__