| 1 | package XML::MinWriter; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | $XML::MinWriter::VERSION = '0.08'; | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use XML::Writer; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | our @ISA = qw(Exporter XML::Writer); | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 1 | our @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 1 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 18 | 15 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 19 | 15 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 15 | $self->{PYX_TYPE} = ''; | |||||||||||||||||||||||||||||||||
| 22 | 15 | $self->{PYX_TAG} = ''; | |||||||||||||||||||||||||||||||||
| 23 | 15 | $self->{PYX_ATTR} = []; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 15 | bless $self, $class; # reconsecrate | |||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | sub xmlDecl { my $self = shift; $self->flush_pyx; $self->SUPER::xmlDecl(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
xmlDecl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | sub doctype { my $self = shift; $self->flush_pyx; $self->SUPER::doctype(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
doctype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | sub comment { my $self = shift; $self->flush_pyx; $self->SUPER::comment(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
comment: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub pi { my $self = shift; $self->flush_pyx; $self->SUPER::pi(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
pi: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | sub startTag { my $self = shift; $self->flush_pyx; $self->SUPER::startTag(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
startTag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub emptyTag { my $self = shift; $self->flush_pyx; $self->SUPER::emptyTag(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
emptyTag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 34 | 62 | ▶ | sub endTag { my $self = shift; $self->flush_pyx; $self->SUPER::endTag(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
endTag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 35 | 22 | ▶ | sub characters { my $self = shift; $self->flush_pyx; $self->SUPER::characters(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
characters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub raw { my $self = shift; $self->flush_pyx; $self->SUPER::raw(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
raw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub cdata { my $self = shift; $self->flush_pyx; $self->SUPER::cdata(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
cdata: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub dataElement { my $self = shift; $self->flush_pyx; $self->SUPER::dataElement(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
dataElement: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 39 | 14 | ▶ | sub end { my $self = shift; $self->flush_pyx; $self->SUPER::end(@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 148 | ▶ | sub write_pyx { | ||||||||||||||||||||||||||||||||
|
Subroutine
write_pyx: called CC=33 SCAR=35.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 42 | 148 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 148 | my @inlist; | |||||||||||||||||||||||||||||||||
| 45 | 148 | for (@_) { | |||||||||||||||||||||||||||||||||
| 46 | 185 | push @inlist, split m{\n}xms; | |||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 148 | LOOP1: for my $instr (@inlist) { | |||||||||||||||||||||||||||||||||
| 50 | 191 | ▶ | if ($instr eq '') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | 2 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 189 | my $code = substr($instr, 0, 1); | |||||||||||||||||||||||||||||||||
| 55 | 189 | my $text = substr($instr, 1); | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 189 | $text =~ s{\\(.)}{ | |||||||||||||||||||||||||||||||||
| 58 | 30 | ▶ | $1 eq '\\' ? "\\" : | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 59 | $1 eq 'n' ? "\n" : | ||||||||||||||||||||||||||||||||||
| 60 | $1 eq 't' ? "\t" : | ||||||||||||||||||||||||||||||||||
| 61 | "\\".$1}xmsge; | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 189 | ▶ | if ($code eq '(') { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 64 | 59 | $self->flush_pyx; | |||||||||||||||||||||||||||||||||
| 65 | 59 | $self->{PYX_TYPE} = '('; | |||||||||||||||||||||||||||||||||
| 66 | 59 | $self->{PYX_TAG} = $text; | |||||||||||||||||||||||||||||||||
| 67 | 59 | $self->{PYX_ATTR} = []; | |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | elsif ($code eq 'A') { | ||||||||||||||||||||||||||||||||||
| 70 | 27 | my ($key, $val) = $text =~ m{\A (\S+) \s+ (.*) \z}xms; | |||||||||||||||||||||||||||||||||
| 71 | 27 | ▶ | unless (defined($key) and defined($val)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $key and defined $val
MC/DC50%1/2
defined $key and defined $val
defined $key
defined $val
Truth table66%2/3
A and B
A= defined $keyB= defined $val
| |||||||||||||||||||||||||||||||||||
| 72 | 1 | carp "Can't parse (key, val) [code = 'A'] in '$text' in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 73 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||
| 75 | 26 | push @{$self->{PYX_ATTR}}, $key, $val; | |||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||
| 77 | elsif ($code eq '?') { | ||||||||||||||||||||||||||||||||||
| 78 | 10 | my ($intro, $def) = $text =~ m{\A (\S+) \s+ (.*) \z}xms; | |||||||||||||||||||||||||||||||||
| 79 | 10 | ▶ | unless (defined($intro) and defined($def)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $intro and defined $def
MC/DC50%1/2
defined $intro and defined $def
defined $intro
defined $def
Truth table66%2/3
A and B
A= defined $introB= defined $def
| |||||||||||||||||||||||||||||||||||
| 80 | 1 | carp "Can't parse (intro, def) [code = '?'] in '$text' in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 81 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 9 | ▶ | if ($intro =~ m{\A xml}xmsi and $intro !~ m{\A xml-stylesheet \z}xmsi) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$intro =~ /\A xml/imsx and not $intro =~ /\A xml-stylesheet \z/imsx
MC/DC50%1/2
$intro =~ /\A xml/imsx and not $intro =~ /\A xml-stylesheet \z/imsx
$intro =~ /\A xml/imsx
not $intro =~ /\A xml-stylesheet \z/imsx
Truth table66%2/3
A and not(B)
A= $intro =~ /\A xml/imsxB= not $intro =~ /\A xml-stylesheet \z/imsx
| |||||||||||||||||||||||||||||||||||
| 85 | 6 | my ($version, $encoding, $standalone); | |||||||||||||||||||||||||||||||||
| 86 | 6 | my $data = $def; | |||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | while (my ($key, $val, $rest) = $data =~ m{\A (\S+) \s* = \s* ["']([^"']+)["'] \s* (.*) \z}xms) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | 7 | ▶ | if ($key =~ m{\A version \z}xmsi) { $version = $val; } | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 89 | 4 | elsif ($key =~ m{\A encoding \z}xmsi) { $encoding = $val; } | |||||||||||||||||||||||||||||||||
| 90 | 0 | elsif ($key =~ m{\A standalone \z}xmsi) { $standalone = $val; } | |||||||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||||||||
| 92 | 1 | carp "Found invalid XML-Declaration (key = '$key') in (intro = '$intro', def = '$def') in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 93 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||
| 95 | 6 | ▶ | unless (defined $version) { $version = '1.0'; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | unless ($version eq '1.0') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 97 | 1 | carp "Found version other than 1.0 ('$version') in (intro = '$intro', def = '$def') in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 98 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | 5 | $data = $rest; | |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | 4 | $self->xmlDecl($encoding, $standalone); | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | else { | ||||||||||||||||||||||||||||||||||
| 105 | 3 | $self->pi($intro, $def); | |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | elsif ($code eq '!') { | ||||||||||||||||||||||||||||||||||
| 109 | 7 | my ($intro, $def) = $text =~ m{\A (\S+) \s+ (.*) \z}xms; | |||||||||||||||||||||||||||||||||
| 110 | 7 | ▶ | unless (defined($intro) and defined($def)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $intro and defined $def
MC/DC50%1/2
defined $intro and defined $def
defined $intro
defined $def
Truth table66%2/3
A and B
A= defined $introB= defined $def
| |||||||||||||||||||||||||||||||||||
| 111 | 1 | carp "Can't parse (intro, def) [code = '!'] in '$text' in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 112 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 6 | ▶ | if ($def =~ m{\A PUBLIC}xmsi) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 116 | 4 | my ($public, $system) = $def =~ m{\A PUBLIC \s+ ["']([^"']+)["'] \s+ ["']([^"']+)["'] \s* \z}xmsi; | |||||||||||||||||||||||||||||||||
| 117 | 4 | ▶ | unless (defined($public) and defined($system)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $public and defined $system
MC/DC50%1/2
defined $public and defined $system
defined $public
defined $system
Truth table66%2/3
A and B
A= defined $publicB= defined $system
| |||||||||||||||||||||||||||||||||||
| 118 | 1 | carp "Can't parse DOCTYPE PUBLIC in (intro = '$intro', def = '$def') in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 119 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||
| 121 | 3 | $self->doctype($intro, $public, $system); | |||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||
| 123 | elsif ($def =~ m{\A SYSTEM}xmsi) { | ||||||||||||||||||||||||||||||||||
| 124 | 1 | my ($system) = $def =~ m{\A SYSTEM \s+ ["']([^"']+)["'] \s* \z}xmsi; | |||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | unless (defined($system)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 126 | 1 | carp "Can't parse DOCTYPE SYSTEM in (intro = '$intro', def = '$def') in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 127 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->doctype($intro, undef, $system); | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | else { | ||||||||||||||||||||||||||||||||||
| 132 | 1 | carp "Can't find neither PUBLIC nor SYSTEM in DOCTYPE (intro = '$intro', def = '$def') in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 133 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | 59 | elsif ($code eq ')') { $self->endTag($text); } | |||||||||||||||||||||||||||||||||
| 137 | 22 | elsif ($code eq '-') { $self->characters($text); } | |||||||||||||||||||||||||||||||||
| 138 | 4 | elsif ($code eq '#') { $self->comment($text); } | |||||||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||||||||
| 140 | 1 | carp "Invalid code = '$code' in write_pyx()"; | |||||||||||||||||||||||||||||||||
| 141 | 1 | next LOOP1; | |||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 174 | ▶ | sub flush_pyx { | ||||||||||||||||||||||||||||||||
|
Subroutine
flush_pyx: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 147 | 174 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 174 | ▶ | if ($self->{PYX_TYPE} eq '(') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 150 | 59 | $self->SUPER::startTag($self->{PYX_TAG}, @{$self->{PYX_ATTR}}); | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 174 | $self->{PYX_TYPE} = ''; | |||||||||||||||||||||||||||||||||
| 154 | 174 | $self->{PYX_TAG} = ''; | |||||||||||||||||||||||||||||||||
| 155 | 174 | $self->{PYX_ATTR} = []; | |||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | __END__ | ||||||||||||||||||||||||||||||||||