| 1 | package SVG::XML; | ||||||||||||||||||||||||||||
| 2 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 30 | our $VERSION = '2.89'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =pod | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | SVG::XML - Handle the XML generation bits for SVG.pm | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Ronan Oger, cpan@roitsystems.com | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | L<SVG>, | ||||||||||||||||||||||||||||
| 20 | L<SVG::DOM>, | ||||||||||||||||||||||||||||
| 21 | L<SVG::Element>, | ||||||||||||||||||||||||||||
| 22 | L<SVG::Parser>, | ||||||||||||||||||||||||||||
| 23 | L<SVG::Extension> | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 30 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 30 | our @ISA = ('Exporter'); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 30 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 32 | xmlesc | ||||||||||||||||||||||||||||
| 33 | xmlescape | ||||||||||||||||||||||||||||
| 34 | xmlescp | ||||||||||||||||||||||||||||
| 35 | cssstyle | ||||||||||||||||||||||||||||
| 36 | xmlattrib | ||||||||||||||||||||||||||||
| 37 | xmlcomment | ||||||||||||||||||||||||||||
| 38 | xmlpi | ||||||||||||||||||||||||||||
| 39 | xmltag | ||||||||||||||||||||||||||||
| 40 | xmltagopen | ||||||||||||||||||||||||||||
| 41 | xmltagclose | ||||||||||||||||||||||||||||
| 42 | xmltag_ln | ||||||||||||||||||||||||||||
| 43 | xmltagopen_ln | ||||||||||||||||||||||||||||
| 44 | xmltagclose_ln | ||||||||||||||||||||||||||||
| 45 | processtag | ||||||||||||||||||||||||||||
| 46 | xmldecl | ||||||||||||||||||||||||||||
| 47 | dtddecl | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 14 | ▶ | sub xmlescp { | ||||||||||||||||||||||||||
|
Subroutine
xmlescp: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 14 | my ( $self, $s ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 14 | ▶ | $s = '0' unless defined $s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $s = join( ', ', @{$s} ) if ( ref($s) eq 'ARRAY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Special XML entities are escaped | ||||||||||||||||||||||||||||
| 57 | 14 | $s =~ s/&(?!#(x\w\w|\d+?);)/&/g; | |||||||||||||||||||||||||||
| 58 | 14 | $s =~ s/>/>/g; | |||||||||||||||||||||||||||
| 59 | 14 | $s =~ s/</</g; | |||||||||||||||||||||||||||
| 60 | 14 | $s =~ s/\"/"/g; | |||||||||||||||||||||||||||
| 61 | 14 | $s =~ s/\'/'/g; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Backtick is just a regular XML citizen | ||||||||||||||||||||||||||||
| 64 | #$s=~s/\`/'/g; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Invalid XML characters are removed, not just escaped: \x00-\x08\x0b\x1f | ||||||||||||||||||||||||||||
| 67 | # Tabs (\x09) and newlines (\x0a) are valid. | ||||||||||||||||||||||||||||
| 68 | 14 | ▶ | while ( $s =~ s/([\x00-\x08\x0b\x1f])/''/e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 10 | my $char = q{'\\x} . sprintf( '%02X', ord($1) ) . q{'}; | |||||||||||||||||||||||||||
| 70 | 10 | $self->error( $char => 'This forbidden XML character was removed' ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Per suggestion from Adam Schneider | ||||||||||||||||||||||||||||
| 74 | 0 | $s =~ s/([\200-\377])/'&#'.ord($1).';'/ge; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 14 | return $s; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 30 | *xmlesc = \&xmlescp; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 30 | *xmlescape = \&xmlescp; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 5 | ▶ | sub cssstyle { | ||||||||||||||||||||||||||
|
Subroutine
cssstyle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 5 | my %attrs = @_; | |||||||||||||||||||||||||||
| 85 | 5 | return ( join( '; ', map { qq($_: ) . $attrs{$_} } sort keys(%attrs) ) ); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # Per suggestion from Adam Schneider | ||||||||||||||||||||||||||||
| 89 | 93 | ▶ | sub xmlattrib { | ||||||||||||||||||||||||||
|
Subroutine
xmlattrib: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 93 | my %attrs = @_; | |||||||||||||||||||||||||||
| 91 | 93 | ▶ | return '' unless ( scalar( keys %attrs ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | return ( | ||||||||||||||||||||||||||||
| 93 | ' ' | ||||||||||||||||||||||||||||
| 94 | . join( ' ', | ||||||||||||||||||||||||||||
| 95 | 69 | map { qq($_=") . $attrs{$_} . q(") } sort keys(%attrs) ) | |||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 39 | ▶ | sub xmltag { | ||||||||||||||||||||||||||
|
Subroutine
xmltag: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 39 | my ( $name, $ns, %attrs ) = @_; | |||||||||||||||||||||||||||
| 101 | 39 | ▶ | $ns = $ns ? "$ns:" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 39 | ▶ | my $at = xmlattrib(%attrs) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
xmlattrib(%attrs) || ''
MC/DC100%1/1
xmlattrib(%attrs) || ''
xmlattrib(%attrs)
Truth table100%2/2
A
A= xmlattrib(%attrs)
| |||||||||||||||||||||||||||||
| 103 | 39 | return qq(<$ns$name$at />); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 39 | ▶ | sub xmltag_ln { | ||||||||||||||||||||||||||
|
Subroutine
xmltag_ln: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | 39 | my ( $name, $ns, %attrs ) = @_; | |||||||||||||||||||||||||||
| 108 | 39 | return xmltag( $name, $ns, %attrs ); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 54 | ▶ | sub xmltagopen { | ||||||||||||||||||||||||||
|
Subroutine
xmltagopen: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 54 | my ( $name, $ns, %attrs ) = @_; | |||||||||||||||||||||||||||
| 113 | 54 | ▶ | $ns = $ns ? "$ns:" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 54 | ▶ | my $at = xmlattrib(%attrs) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
xmlattrib(%attrs) || ''
MC/DC100%1/1
xmlattrib(%attrs) || ''
xmlattrib(%attrs)
Truth table100%2/2
A
A= xmlattrib(%attrs)
| |||||||||||||||||||||||||||||
| 115 | 54 | return qq(<$ns$name$at>); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 54 | ▶ | sub xmltagopen_ln { | ||||||||||||||||||||||||||
|
Subroutine
xmltagopen_ln: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 54 | my ( $name, $ns, %attrs ) = @_; | |||||||||||||||||||||||||||
| 120 | 54 | return xmltagopen( $name, $ns, %attrs ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 27 | ▶ | sub xmlcomment { | ||||||||||||||||||||||||||
|
Subroutine
xmlcomment: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 27 | my ( $self, $r_comment ) = @_; | |||||||||||||||||||||||||||
| 125 | my $ind = $self->{-docref}->{-elsep} | ||||||||||||||||||||||||||||
| 126 | 27 | . $self->{-docref}->{-indent} x $self->{-docref}->{-level}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # If the comment starts with newline character then do not prefix | ||||||||||||||||||||||||||||
| 129 | # with space (RT #123896). | ||||||||||||||||||||||||||||
| 130 | return ( | ||||||||||||||||||||||||||||
| 131 | $ind . join( | ||||||||||||||||||||||||||||
| 132 | $ind, | ||||||||||||||||||||||||||||
| 133 | map { | ||||||||||||||||||||||||||||
| 134 | 27 | ▶ | ( (/^\n/) ? (q(<!--)) : (q(<!-- )) ) . qq($_) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 135 | . ( (/\n[\t]?$/) ? (q(-->)) : (q( -->)) ); | ||||||||||||||||||||||||||||
| 136 | } @$r_comment | ||||||||||||||||||||||||||||
| 137 | ) | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | ▶ | sub xmlpi { | ||||||||||||||||||||||||||
|
Subroutine
xmlpi: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 2 | my ( $self, $r_pi ) = @_; | |||||||||||||||||||||||||||
| 143 | my $ind = $self->{-docref}->{-elsep} | ||||||||||||||||||||||||||||
| 144 | 2 | . $self->{-docref}->{-indent} x $self->{-docref}->{-level}; | |||||||||||||||||||||||||||
| 145 | 2 | return ( join( $ind, map {qq(<?$_?>)} @$r_pi ) ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 30 | *processinginstruction = \&xmlpi; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 54 | ▶ | sub xmltagclose { | ||||||||||||||||||||||||||
|
Subroutine
xmltagclose: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | 54 | my ( $name, $ns ) = @_; | |||||||||||||||||||||||||||
| 152 | 54 | ▶ | $ns = $ns ? "$ns:" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 54 | return qq(</$ns$name>); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 54 | ▶ | sub xmltagclose_ln { | ||||||||||||||||||||||||||
|
Subroutine
xmltagclose_ln: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 54 | my ( $name, $ns ) = @_; | |||||||||||||||||||||||||||
| 158 | 54 | return xmltagclose( $name, $ns ); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 32 | ▶ | sub dtddecl { | ||||||||||||||||||||||||||
|
Subroutine
dtddecl: called CC=9 SCAR=22.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 32 | my $self = shift; | |||||||||||||||||||||||||||
| 163 | 32 | ▶ | my $docroot = $self->{-docroot} || 'svg'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-docroot'} || 'svg'
MC/DC0%0/1
$self->{'-docroot'} || 'svg'
$self->{'-docroot'}
Truth table50%1/2
A
A= $self->{'-docroot'}
| |||||||||||||||||||||||||||||
| 164 | 32 | my $id; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 32 | ▶ | if ( $self->{-pubid} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 167 | 31 | $id = 'PUBLIC "' . $self->{-pubid} . '"'; | |||||||||||||||||||||||||||
| 168 | 31 | ▶ | $id .= ' "' . $self->{-sysid} . '"' if ( $self->{-sysid} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | elsif ( $self->{-sysid} ) { | ||||||||||||||||||||||||||||
| 171 | 1 | $id = 'SYSTEM "' . $self->{-sysid} . '"'; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||
| 174 | $id | ||||||||||||||||||||||||||||
| 175 | = 'PUBLIC "-//W3C//DTD SVG 1.0//EN"' | ||||||||||||||||||||||||||||
| 176 | . $self->{-docref}->{-elsep} | ||||||||||||||||||||||||||||
| 177 | 0 | . "\"$self->{-docref}->{-dtd}\""; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 32 | my $at = join( ' ', ( $docroot, $id ) ); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | #>>>TBD: add internal() method to return this | ||||||||||||||||||||||||||||
| 183 | my $extension | ||||||||||||||||||||||||||||
| 184 | = ( exists $self->{-internal} ) | ||||||||||||||||||||||||||||
| 185 | ? $self->{-internal}->render() | ||||||||||||||||||||||||||||
| 186 | 32 | ▶ | : q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 32 | ▶ | if ( exists $self->{-extension} and $self->{-extension} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"-extension"} and $self->{"-extension"}
MC/DC50%1/2
exists $self->{"-extension"} and $self->{"-extension"}
exists $self->{"-extension"}
$self->{"-extension"}
Truth table66%2/3
A and B
A= exists $self->{"-extension"}B= $self->{"-extension"}
| |||||||||||||||||||||||||||||
| 188 | $extension | ||||||||||||||||||||||||||||
| 189 | .= $self->{-docref}{-elsep} | ||||||||||||||||||||||||||||
| 190 | . $self->{-extension} | ||||||||||||||||||||||||||||
| 191 | 1 | . $self->{-docref}{-elsep}; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 32 | ▶ | $extension = ' [' . $self->{-docref}{-elsep} . $extension . ']' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | if $extension; | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 32 | return qq[$self->{-docref}{-elsep}<!DOCTYPE $at$extension>]; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 27 | ▶ | sub xmldecl { | ||||||||||||||||||||||||||
|
Subroutine
xmldecl: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 200 | 27 | my $self = shift; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 27 | ▶ | my $version = $self->{-version} || '1.0'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-version'} || '1.0'
MC/DC0%0/1
$self->{'-version'} || '1.0'
$self->{'-version'}
Truth table50%1/2
A
A= $self->{'-version'}
| |||||||||||||||||||||||||||||
| 203 | 27 | ▶ | my $encoding = $self->{-encoding} || 'UTF-8'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-encoding'} || 'UTF-8'
MC/DC0%0/1
$self->{'-encoding'} || 'UTF-8'
$self->{'-encoding'}
Truth table50%1/2
A
A= $self->{'-encoding'}
| |||||||||||||||||||||||||||||
| 204 | 27 | ▶ | my $standalone = $self->{-standalone} || 'yes'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-standalone'} || 'yes'
MC/DC0%0/1
$self->{'-standalone'} || 'yes'
$self->{'-standalone'}
Truth table50%1/2
A
A= $self->{'-standalone'}
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | return | ||||||||||||||||||||||||||||
| 207 | 27 | qq{<?xml version="$version" encoding="$encoding" standalone="$standalone"?>}; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 30 | 1; | |||||||||||||||||||||||||||