| 1 | # Copyrights 2011-2014 by [Mark Overmeer]. | ||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.01. | ||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | package XML::Compile::C14N; | ||||||||||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.94'; | |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Log::Report 'xml-compile-c14n'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use XML::Compile::C14N::Util qw/:c14n :paths/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use XML::LibXML (); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Encode qw/_utf8_off/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 2 | my %versions = | |||||||||||||||||||||||||||||||||||
| 20 | ( '1.0' => {} | ||||||||||||||||||||||||||||||||||||
| 21 | , '1.1' => {} | ||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 2 | my %prefixes = | |||||||||||||||||||||||||||||||||||
| 25 | ( c14n => C14N_EXC_NS | ||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | 2 | my %features = #comment excl | |||||||||||||||||||||||||||||||||||
| 29 | ( &C14N_v10_NO_COMM => [ 0, 0 ] | ||||||||||||||||||||||||||||||||||||
| 30 | , &C14N_v10_COMMENTS => [ 1, 0 ] | ||||||||||||||||||||||||||||||||||||
| 31 | , &C14N_v11_NO_COMM => [ 0, 0 ] | ||||||||||||||||||||||||||||||||||||
| 32 | , &C14N_v11_COMMENTS => [ 1, 0 ] | ||||||||||||||||||||||||||||||||||||
| 33 | , &C14N_EXC_NO_COMM => [ 0, 1 ] | ||||||||||||||||||||||||||||||||||||
| 34 | , &C14N_EXC_COMMENTS => [ 1, 1 ] | ||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub new(@) { my $class = shift; (bless {}, $class)->init( {@_} ) } | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 39 | sub init($) | ||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $version = $args->{version}; | |||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if(my $c = $args->{for}) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | { $version ||= index($c, C14N10 )==0 ? '1.0' | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$version ||= index($c, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315") == 0 ? "1.0" : (index($c, "http://www.w3.org/2006/12/xml-c14n11") == 0 ? "1.1" : (index($c, "http://www.w3.org/2001/10/xml-exc-c14n") == 0 ? "1.1" : undef))
MC/DC0%0/2
$version ||= index($c, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315") == 0 ? "1.0" : (index($c, "http://www.w3.org/2006/12/xml-c14n11") == 0 ? "1.1" : (index($c, "http://www.w3.org/2001/10/xml-exc-c14n") == 0 ? "1.1" : undef))
$version
index($c, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315") == 0 ? "1.0" : (index($c, "http://www.w3.org/2006/12/xml-c14n11") == 0 ? "1.1" : (index($c, "http://www.w3.org/2001/10/xml-exc-c14n") == 0 ? "1.1" : undef))
Truth table0%0/3
A ||= B
A= $versionB= index($c, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315") == 0 ? "1.0" : (index($c, "http://www.w3.org/2006/12/xml-c14n11") == 0 ? "1.1" : (index($c, "http://www.w3.org/2001/10/xml-exc-c14n") == 0 ? "1.1" : undef))
| |||||||||||||||||||||||||||||||||||||
| 45 | : index($c, C14N11 )==0 ? '1.1' | ||||||||||||||||||||||||||||||||||||
| 46 | : index($c, C14NEXC)==0 ? '1.1' | ||||||||||||||||||||||||||||||||||||
| 47 | : undef; | ||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | $version ||= '1.1'; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$version ||= "1.1"
MC/DC0%0/1
$version ||= "1.1"
$version
Truth table50%1/2
A
A= $version
| |||||||||||||||||||||||||||||||||||||
| 50 | 1 | trace "initializing v14n $version"; | |||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | $versions{$version} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 53 | or error __x"unknown c14n version {v}, pick from {vs}" | ||||||||||||||||||||||||||||||||||||
| 54 | , v => $version, vs => [keys %versions]; | ||||||||||||||||||||||||||||||||||||
| 55 | 1 | $self->{XCC_version} = $version; | |||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | $self->loadSchemas($args->{schema}) | ||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if $args->{schema}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | 1 | $self; | |||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||
| 63 | #----------- | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub version() {shift->{XCC_version}} | ||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub schema() {shift->{XCC_schema}} | ||||||||||||||||||||||||||||||||||
|
Subroutine
schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | #----------- | ||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | sub normalize($$%) | ||||||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | { my ($self, $type, $node, %args) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
normalize: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | my $prefixes = $args{prefix_list} || []; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'prefix_list'} || []
MC/DC0%0/1
$args{'prefix_list'} || []
$args{'prefix_list'}
Truth table50%1/2
A
A= $args{'prefix_list'}
| |||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | 6 | ▶ | my $features = $features{$type} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 76 | or error __x"unsupported canonicalization method {name}", name => $type; | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 6 | my ($with_comments, $with_exc) = @$features; | |||||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | my $serialize = $with_exc ? 'toStringEC14N' : 'toStringC14N'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | 6 | my $xpath = $args{xpath}; | |||||||||||||||||||||||||||||||||||
| 82 | 6 | ▶ | my $context = $args{context} || XML::LibXML::XPathContext->new($node); | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{'context'} || 'XML::LibXML::XPathContext'->new($node)
MC/DC0%0/2
$args{'context'} || 'XML::LibXML::XPathContext'->new($node)
$args{'context'}
'XML::LibXML::XPathContext'->new($node)
Truth table33%1/3
A || B
A= $args{'context'}B= 'XML::LibXML::XPathContext'->new($node)
| |||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | my $canon = | ||||||||||||||||||||||||||||||||||||
| 85 | 6 | eval { $node->$serialize($with_comments, $xpath, $context, $prefixes) }; | |||||||||||||||||||||||||||||||||||
| 86 | #warn "--> $canon#\n"; | ||||||||||||||||||||||||||||||||||||
| 87 | 6 | _utf8_off $canon; | |||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | 6 | ▶ | if(my $err = $@) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 90 | { # $err =~ s/ at .*//s; | ||||||||||||||||||||||||||||||||||||
| 91 | 1 | panic $err; | |||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||
| 93 | 5 | $canon; | |||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | #----------- | ||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | sub loadSchemas($) | ||||||||||||||||||||||||||||||||||||
| 99 | 1 | ▶ | { my ($self, $schema) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
loadSchemas: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | $schema->isa('XML::Compile::Cache') | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 102 | or error __x"loadSchemas() requires a XML::Compile::Cache object"; | ||||||||||||||||||||||||||||||||||||
| 103 | 1 | $self->{XCC_schema} = $schema; | |||||||||||||||||||||||||||||||||||
| 104 | 1 | weaken $self->{XCC_schema}; | |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | 1 | my $version = $self->version; | |||||||||||||||||||||||||||||||||||
| 107 | 1 | my $def = $versions{$version}; | |||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||
| 109 | 1 | $schema->addPrefixes(\%prefixes); | |||||||||||||||||||||||||||||||||||
| 110 | 1 | my $rewrite = join ',', keys %prefixes; | |||||||||||||||||||||||||||||||||||
| 111 | 1 | $schema->addKeyRewrite("PREFIXED($rewrite)"); | |||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | 1 | (my $xsd = __FILE__) =~ s! \.pm$ !/exc-c14n.xsd!x; | |||||||||||||||||||||||||||||||||||
| 114 | 1 | trace "loading c14n for $version"; | |||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 1 | $schema->importDefinitions($xsd); | |||||||||||||||||||||||||||||||||||
| 117 | 1 | $self; | |||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | #----------------- | ||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | 2 | 1; | |||||||||||||||||||||||||||||||||||