| 1 | package PYX::SGML::Raw; | ||||||||||
| 2 | |||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use Class::Utils qw(set_params); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use PYX::Parser; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use PYX::Utils qw(encode entity_encode); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | our $VERSION = 0.05; | |||||||||
| 11 | |||||||||||
| 12 | # Constructor. | ||||||||||
| 13 | 8 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 14 | 8 | my ($class, @params) = @_; | |||||||||
| 15 | |||||||||||
| 16 | 8 | my $self = bless {}, $class; | |||||||||
| 17 | |||||||||||
| 18 | # Output handler. | ||||||||||
| 19 | 8 | $self->{'output_handler'} = \*STDOUT; | |||||||||
| 20 | |||||||||||
| 21 | # Process params. | ||||||||||
| 22 | 8 | set_params($self, @params); | |||||||||
| 23 | |||||||||||
| 24 | # PYX::Parser object. | ||||||||||
| 25 | $self->{'pyx_parser'} = PYX::Parser->new( | ||||||||||
| 26 | 'callbacks' => { | ||||||||||
| 27 | 'start_element' => \&_start_element, | ||||||||||
| 28 | 'end_element' => \&_end_element, | ||||||||||
| 29 | 'data' => \&_data, | ||||||||||
| 30 | 'instruction' => \&_instruction, | ||||||||||
| 31 | 'attribute' => \&_attribute, | ||||||||||
| 32 | 'comment' => \&_comment, | ||||||||||
| 33 | }, | ||||||||||
| 34 | 'non_parser_options' => { | ||||||||||
| 35 | 'tag_open' => 0, | ||||||||||
| 36 | }, | ||||||||||
| 37 | 8 | 'output_handler' => $self->{'output_handler'}, | |||||||||
| 38 | ); | ||||||||||
| 39 | |||||||||||
| 40 | # Object. | ||||||||||
| 41 | 8 | return $self; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # Parse pyx text or array of pyx text. | ||||||||||
| 45 | 0 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | 0 | my ($self, $pyx, $out) = @_; | |||||||||
| 47 | 0 | $self->{'pyx_parser'}->parse($pyx, $out); | |||||||||
| 48 | 0 | return; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | # Parse file with pyx text. | ||||||||||
| 52 | 13 | ▶ | sub parse_file { | ||||||||
|
Subroutine
parse_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 53 | 13 | my ($self, $file) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 13 | $self->{'pyx_parser'}->parse_file($file); | |||||||||
| 56 | |||||||||||
| 57 | 13 | return; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # Parse from handler. | ||||||||||
| 61 | 0 | ▶ | sub parse_handler { | ||||||||
|
Subroutine
parse_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 62 | 0 | my ($self, $input_file_handler, $out) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 0 | $self->{'pyx_parser'}->parse_handler($input_file_handler, $out); | |||||||||
| 65 | |||||||||||
| 66 | 0 | return; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub finalize { | ||||||||
|
Subroutine
finalize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 70 | 0 | my $self = shift; | |||||||||
| 71 | |||||||||||
| 72 | 0 | _end_of_start_tag($self->{'pyx_parser'}); | |||||||||
| 73 | |||||||||||
| 74 | 0 | return; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # Process start of element. | ||||||||||
| 78 | 6 | ▶ | sub _start_element { | ||||||||
|
Subroutine
_start_element: called CC=1 SCAR=0.0
| |||||||||||
| 79 | 6 | my ($pyx_parser_obj, $elem) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 6 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 82 | 6 | _end_of_start_tag($pyx_parser_obj); | |||||||||
| 83 | 6 | print {$out} "<$elem"; | |||||||||
| 84 | 6 | $pyx_parser_obj->{'non_parser_options'}->{'tag_open'} = 1; | |||||||||
| 85 | |||||||||||
| 86 | 6 | return; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | # Process end of element. | ||||||||||
| 90 | 4 | ▶ | sub _end_element { | ||||||||
|
Subroutine
_end_element: called CC=1 SCAR=0.0
| |||||||||||
| 91 | 4 | my ($pyx_parser_obj, $elem) = @_; | |||||||||
| 92 | |||||||||||
| 93 | 4 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 94 | 4 | _end_of_start_tag($pyx_parser_obj); | |||||||||
| 95 | 4 | print {$out} "</$elem>"; | |||||||||
| 96 | |||||||||||
| 97 | 4 | return; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | # Process data. | ||||||||||
| 101 | 2 | ▶ | sub _data { | ||||||||
|
Subroutine
_data: called CC=1 SCAR=0.0
| |||||||||||
| 102 | 2 | my ($pyx_parser_obj, $decoded_data) = @_; | |||||||||
| 103 | |||||||||||
| 104 | 2 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 105 | 2 | my $data = encode($decoded_data); | |||||||||
| 106 | 2 | _end_of_start_tag($pyx_parser_obj); | |||||||||
| 107 | 2 | print {$out} entity_encode($data); | |||||||||
| 108 | |||||||||||
| 109 | 2 | return; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | # Process attribute. | ||||||||||
| 113 | 4 | ▶ | sub _attribute { | ||||||||
|
Subroutine
_attribute: called CC=1 SCAR=0.0
| |||||||||||
| 114 | 4 | my ($pyx_parser_obj, $att, $attval) = @_; | |||||||||
| 115 | |||||||||||
| 116 | 4 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 117 | 4 | print {$out} " $att=\"", entity_encode($attval), '"'; | |||||||||
| 118 | |||||||||||
| 119 | 4 | return; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | # Process instruction. | ||||||||||
| 123 | 2 | ▶ | sub _instruction { | ||||||||
|
Subroutine
_instruction: called CC=1 SCAR=0.0
| |||||||||||
| 124 | 2 | my ($pyx_parser_obj, $target, $data) = @_; | |||||||||
| 125 | |||||||||||
| 126 | 2 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 127 | 2 | _end_of_start_tag($pyx_parser_obj); | |||||||||
| 128 | 2 | print {$out} "<?$target ", encode($data), "?>"; | |||||||||
| 129 | |||||||||||
| 130 | 2 | return; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | # Ends start tag. | ||||||||||
| 134 | 14 | ▶ | sub _end_of_start_tag { | ||||||||
|
Subroutine
_end_of_start_tag: called CC=2 SCAR=6.9
| |||||||||||
| 135 | 14 | my $pyx_parser_obj = shift; | |||||||||
| 136 | |||||||||||
| 137 | 14 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 138 | 14 | ▶ | if ($pyx_parser_obj->{'non_parser_options'}->{'tag_open'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | 3 | print {$out} '>'; | |||||||||
| 140 | 3 | $pyx_parser_obj->{'non_parser_options'}->{'tag_open'} = 0; | |||||||||
| 141 | } | ||||||||||
| 142 | |||||||||||
| 143 | 14 | return; | |||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | # Process comment. | ||||||||||
| 147 | 2 | ▶ | sub _comment { | ||||||||
|
Subroutine
_comment: called CC=1 SCAR=0.0
| |||||||||||
| 148 | 2 | my ($pyx_parser_obj, $comment) = @_; | |||||||||
| 149 | |||||||||||
| 150 | 2 | my $out = $pyx_parser_obj->{'output_handler'}; | |||||||||
| 151 | 2 | print {$out} '<!--'.encode($comment).'-->'; | |||||||||
| 152 | |||||||||||
| 153 | 2 | return; | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | 8 | 1; | |||||||||
| 157 | |||||||||||
| 158 | __END__ | ||||||||||