| 1 | package XML::GrammarBase::Role::RelaxNG; | ||||||||||||||||||||||||||||
| 2 | 4 | $XML::GrammarBase::Role::RelaxNG::VERSION = '0.2.10'; | |||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use MooX::Role 'late'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use File::ShareDir qw(dist_dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use XML::LibXML 2.0017; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | with('XML::GrammarBase::Role::DataDir'); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | has 'rng_schema_basename' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||
| 15 | has '_rng' => ( | ||||||||||||||||||||||||||||
| 16 | isa => 'XML::LibXML::RelaxNG', | ||||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | 6 | ▶ | default => sub { return shift->_calc_default_rng_schema; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 4 | lazy => 1, | |||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub _calc_default_rng_schema | ||||||||||||||||||||||||||||
| 23 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_calc_default_rng_schema: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | my $rngschema = | |||||||||||||||||||||||||||
| 27 | XML::LibXML::RelaxNG->new( | ||||||||||||||||||||||||||||
| 28 | location => $self->dist_path_slot('rng_schema_basename'), ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 6 | return $rngschema; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub rng_validate_dom | ||||||||||||||||||||||||||||
| 34 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rng_validate_dom: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 6 | my ( $self, $source_dom ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | my $ret_code; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 6 | eval { $ret_code = $self->_rng()->validate($source_dom); }; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | ▶ | if ( defined($ret_code) && ( $ret_code == 0 ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ret_code and $ret_code == 0
MC/DC50%1/2
defined $ret_code and $ret_code == 0
defined $ret_code
$ret_code == 0
Truth table66%2/3
A and B
A= defined $ret_codeB= $ret_code == 0
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | # It's OK. | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | else | ||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||
| 47 | 3 | confess "RelaxNG validation failed [\$ret_code == " | |||||||||||||||||||||||||||
| 48 | . $self->_undefize($ret_code) | ||||||||||||||||||||||||||||
| 49 | . " ; $@]"; | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub _calc_parser | ||||||||||||||||||||||||||||
| 56 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_calc_parser: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 4 | my $xml_parser = XML::LibXML->new(); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | $xml_parser->validation(0); | |||||||||||||||||||||||||||
| 62 | 4 | $xml_parser->load_ext_dtd(0); | |||||||||||||||||||||||||||
| 63 | 4 | $xml_parser->no_network(1); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | return $xml_parser; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub rng_validate_file | ||||||||||||||||||||||||||||
| 69 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rng_validate_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 2 | my ( $self, $filename ) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | my $dom = $self->_calc_parser()->parse_file($filename); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | return $self->rng_validate_dom($dom); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub rng_validate_string | ||||||||||||||||||||||||||||
| 78 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rng_validate_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 2 | my ( $self, $xml_string ) = @_; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | my $dom = $self->_calc_parser()->parse_string($xml_string); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | return $self->rng_validate_dom($dom); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 4 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||