| 1 | package PYX::XMLNorm; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use PYX qw(end_element); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use PYX::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | our $VERSION = 0.05; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Constructor. | ||||||||||||||||||||||||||||
| 14 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 7 | my ($class, @params) = @_; | |||||||||||||||||||||||||||
| 16 | 7 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Flush stack on finalization. | ||||||||||||||||||||||||||||
| 19 | 7 | $self->{'flush_stack'} = 0; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Output handler. | ||||||||||||||||||||||||||||
| 22 | 7 | $self->{'output_handler'} = \*STDOUT; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # XML normalization rules. | ||||||||||||||||||||||||||||
| 25 | 7 | $self->{'rules'} = {}; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Process params. | ||||||||||||||||||||||||||||
| 28 | 7 | set_params($self, @params); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Check to rules. | ||||||||||||||||||||||||||||
| 31 | 5 | ▶ | if (! keys %{$self->{'rules'}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | err 'Cannot exist XML normalization rules.'; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # PYX::Parser object. | ||||||||||||||||||||||||||||
| 36 | $self->{'pyx_parser'} = PYX::Parser->new( | ||||||||||||||||||||||||||||
| 37 | 'callbacks' => { | ||||||||||||||||||||||||||||
| 38 | 'data' => \&_end_element_simple, | ||||||||||||||||||||||||||||
| 39 | 'end_element' => \&_end_element, | ||||||||||||||||||||||||||||
| 40 | 'final' => \&_final, | ||||||||||||||||||||||||||||
| 41 | 'start_element' => \&_start_element, | ||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||
| 43 | 'non_parser_options' => { | ||||||||||||||||||||||||||||
| 44 | 'flush_stack' => $self->{'flush_stack'}, | ||||||||||||||||||||||||||||
| 45 | 'rules' => $self->{'rules'}, | ||||||||||||||||||||||||||||
| 46 | 'stack' => [], | ||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | 4 | 'output_handler' => $self->{'output_handler'}, | |||||||||||||||||||||||||||
| 49 | 'output_rewrite' => 1, | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # Object. | ||||||||||||||||||||||||||||
| 53 | 4 | return $self; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Parse pyx text or array of pyx text. | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 1 | my ($self, $pyx, $out) = @_; | |||||||||||||||||||||||||||
| 59 | 1 | $self->{'pyx_parser'}->parse($pyx, $out); | |||||||||||||||||||||||||||
| 60 | 1 | return; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Parse file with pyx text. | ||||||||||||||||||||||||||||
| 64 | 7 | ▶ | sub parse_file { | ||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 7 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 66 | 7 | $self->{'pyx_parser'}->parse_file($file); | |||||||||||||||||||||||||||
| 67 | 7 | return; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Parse from handler. | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub parse_handler { | ||||||||||||||||||||||||||
|
Subroutine
parse_handler: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 1 | my ($self, $input_file_handler, $out) = @_; | |||||||||||||||||||||||||||
| 73 | 1 | $self->{'pyx_parser'}->parse_handler($input_file_handler, $out); | |||||||||||||||||||||||||||
| 74 | 1 | return; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Process start of element. | ||||||||||||||||||||||||||||
| 78 | 55 | ▶ | sub _start_element { | ||||||||||||||||||||||||||
|
Subroutine
_start_element: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 79 | 55 | my ($pyx_parser, $tag) = @_; | |||||||||||||||||||||||||||
| 80 | 55 | my $out = $pyx_parser->{'output_handler'}; | |||||||||||||||||||||||||||
| 81 | 55 | my $rules = $pyx_parser->{'non_parser_options'}->{'rules'}; | |||||||||||||||||||||||||||
| 82 | 55 | my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; | |||||||||||||||||||||||||||
| 83 | 55 | ▶ | if (exists $rules->{'*'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 55 | foreach my $tmp (@{$rules->{'*'}}) { | |||||||||||||||||||||||||||
| 85 | 275 | ▶ | if (@{$stack} > 0 && lc($stack->[-1]) eq $tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$stack;} > 0 and lc $stack->[-1] eq $tmp
MC/DC100%2/2
@{$stack;} > 0 and lc $stack->[-1] eq $tmp
@{$stack;} > 0
lc $stack->[-1] eq $tmp
Truth table100%3/3
A and B
A= @{$stack;} > 0B= lc $stack->[-1] eq $tmp
| |||||||||||||||||||||||||||||
| 86 | 15 | print {$out} end_element(pop @{$stack}), "\n"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 55 | ▶ | if (exists $rules->{lc($tag)}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 21 | foreach my $tmp (@{$rules->{lc($tag)}}) { | |||||||||||||||||||||||||||
| 92 | 34 | ▶ | if (@{$stack} > 0 && lc($stack->[-1]) eq $tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$stack;} > 0 and lc $stack->[-1] eq $tmp
MC/DC100%2/2
@{$stack;} > 0 and lc $stack->[-1] eq $tmp
@{$stack;} > 0
lc $stack->[-1] eq $tmp
Truth table100%3/3
A and B
A= @{$stack;} > 0B= lc $stack->[-1] eq $tmp
| |||||||||||||||||||||||||||||
| 93 | 7 | print {$out} end_element(pop @{$stack}), "\n"; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 55 | push @{$stack}, $tag; | |||||||||||||||||||||||||||
| 98 | 55 | print {$out} $pyx_parser->line, "\n"; | |||||||||||||||||||||||||||
| 99 | 55 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Add implicit end_element. | ||||||||||||||||||||||||||||
| 103 | 11 | ▶ | sub _end_element_simple { | ||||||||||||||||||||||||||
|
Subroutine
_end_element_simple: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 104 | 11 | my $pyx_parser = shift; | |||||||||||||||||||||||||||
| 105 | 11 | my $rules = $pyx_parser->{'non_parser_options'}->{'rules'}; | |||||||||||||||||||||||||||
| 106 | 11 | my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; | |||||||||||||||||||||||||||
| 107 | 11 | my $out = $pyx_parser->{'output_handler'}; | |||||||||||||||||||||||||||
| 108 | 11 | ▶ | if (exists $rules->{'*'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 11 | foreach my $tmp (@{$rules->{'*'}}) { | |||||||||||||||||||||||||||
| 110 | 55 | ▶ | if (@{$stack} && lc $stack->[-1] eq $tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$stack;} and lc $stack->[-1] eq $tmp
MC/DC100%2/2
@{$stack;} and lc $stack->[-1] eq $tmp
@{$stack;}
lc $stack->[-1] eq $tmp
Truth table100%3/3
A and B
A= @{$stack;}B= lc $stack->[-1] eq $tmp
| |||||||||||||||||||||||||||||
| 111 | 2 | print {$out} end_element(pop @{$stack}), "\n"; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 11 | print {$out} $pyx_parser->line, "\n"; | |||||||||||||||||||||||||||
| 116 | 11 | return; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Process end of element | ||||||||||||||||||||||||||||
| 120 | 14 | ▶ | sub _end_element { | ||||||||||||||||||||||||||
|
Subroutine
_end_element: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||
| 121 | 14 | my ($pyx_parser, $tag) = @_; | |||||||||||||||||||||||||||
| 122 | 14 | my $out = $pyx_parser->{'output_handler'}; | |||||||||||||||||||||||||||
| 123 | 14 | my $rules = $pyx_parser->{'non_parser_options'}->{'rules'}; | |||||||||||||||||||||||||||
| 124 | 14 | my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; | |||||||||||||||||||||||||||
| 125 | 14 | ▶ | if (exists $rules->{'*'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 14 | foreach my $tmp (@{$rules->{'*'}}) { | |||||||||||||||||||||||||||
| 127 | 70 | ▶ | if (lc($tag) ne $tmp && lc($stack->[-1]) eq $tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $tag ne $tmp and lc $stack->[-1] eq $tmp
MC/DC100%2/2
lc $tag ne $tmp and lc $stack->[-1] eq $tmp
lc $tag ne $tmp
lc $stack->[-1] eq $tmp
Truth table100%3/3
A and B
A= lc $tag ne $tmpB= lc $stack->[-1] eq $tmp
| |||||||||||||||||||||||||||||
| 128 | 7 | print {$out} end_element(pop @{$stack}), "\n"; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | # XXX Myslim, ze tenhle blok je spatne. | ||||||||||||||||||||||||||||
| 133 | 14 | ▶ | if (exists $rules->{$tag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 8 | foreach my $tmp (@{$rules->{$tag}}) { | |||||||||||||||||||||||||||
| 135 | 11 | ▶ | if (lc($tag) ne $tmp && lc($stack->[-1]) eq $tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
lc $tag ne $tmp and lc $stack->[-1] eq $tmp
MC/DC50%1/2
lc $tag ne $tmp and lc $stack->[-1] eq $tmp
lc $tag ne $tmp
lc $stack->[-1] eq $tmp
Truth table66%2/3
A and B
A= lc $tag ne $tmpB= lc $stack->[-1] eq $tmp
| |||||||||||||||||||||||||||||
| 136 | 10 | print {$out} end_element(pop @{$stack}), "\n"; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 14 | ▶ | if (lc($stack->[-1]) eq lc($tag)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 14 | pop @{$stack}; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 14 | print {$out} $pyx_parser->line, "\n"; | |||||||||||||||||||||||||||
| 144 | 14 | return; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # Process final. | ||||||||||||||||||||||||||||
| 148 | 9 | ▶ | sub _final { | ||||||||||||||||||||||||||
|
Subroutine
_final: called CC=4 SCAR=18.6
| |||||||||||||||||||||||||||||
| 149 | 9 | my $pyx_parser = shift; | |||||||||||||||||||||||||||
| 150 | 9 | my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; | |||||||||||||||||||||||||||
| 151 | 9 | my $out = $pyx_parser->{'output_handler'}; | |||||||||||||||||||||||||||
| 152 | 9 | ▶ | if (@{$stack} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # If set, than flush stack. | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($pyx_parser->{'non_parser_options'}->{'flush_stack'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | foreach my $tmp (reverse @{$stack}) { | |||||||||||||||||||||||||||
| 157 | 0 | print {$out} end_element($tmp), "\n"; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | 9 | return; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 6 | 1; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||