blib/lib/PYX/SGML/Raw.pm

filter: Statementstmt 88.4% 69 / 78 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 82.3% 14 / 17 Podpod 100% 5 / 5 totaltotal 88.2% 90 / 102 SCAR 7.0
CC
2
Cov
89%
parse
2.0
parse_handler
2.0
finalize
2.0
CRAP 2.0
↑ Summary
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.03;
11  
12 # Constructor.
13 sub new {
14 8 ▶ my ($class, @params) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 8 my $self = bless {}, $class;
16  
17 # Output handler.
18 8 $self->{'output_handler'} = \*STDOUT;
19  
20 # Process params.
21 8 set_params($self, @params);
22  
23 # PYX::Parser object.
24 $self->{'pyx_parser'} = PYX::Parser->new(
25 'callbacks' => {
26 'start_element' => \&_start_element,
27 'end_element' => \&_end_element,
28 'data' => \&_data,
29 'instruction' => \&_instruction,
30 'attribute' => \&_attribute,
31 'comment' => \&_comment,
32 },
33 'non_parser_options' => {
34 'tag_open' => 0,
35 },
36 8 'output_handler' => $self->{'output_handler'},
37 );
38  
39 # Object.
40 8 return $self;
41 }
42  
43 # Parse pyx text or array of pyx text.
44 sub parse {
45 0 ▶ my ($self, $pyx, $out) = @_;
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
46 0 $self->{'pyx_parser'}->parse($pyx, $out);
47 0 return;
48 }
49  
50 # Parse file with pyx text.
51 sub parse_file {
52 13 ▶ my ($self, $file) = @_;
Subroutine parse_file: called CC=1 SCAR=0.0
Pod documented
53 13 $self->{'pyx_parser'}->parse_file($file);
54 13 return;
55 }
56  
57 # Parse from handler.
58 sub parse_handler {
59 0 ▶ my ($self, $input_file_handler, $out) = @_;
Subroutine parse_handler: not called CC=1 SCAR=6.9
Pod documented
60 0 $self->{'pyx_parser'}->parse_handler($input_file_handler, $out);
61 0 return;
62 }
63  
64 sub finalize {
65 0 ▶ my $self = shift;
Subroutine finalize: not called CC=1 SCAR=6.9
Pod documented
66 0 _end_of_start_tag($self->{'pyx_parser'});
67 0 return;
68 }
69  
70 # Process start of element.
71 sub _start_element {
72 6 ▶ my ($pyx_parser_obj, $elem) = @_;
Subroutine _start_element: called CC=1 SCAR=0.0
73 6 my $out = $pyx_parser_obj->{'output_handler'};
74 6 _end_of_start_tag($pyx_parser_obj);
75 6 print {$out} "<$elem";
76 6 $pyx_parser_obj->{'non_parser_options'}->{'tag_open'} = 1;
77 6 return;
78 }
79  
80 # Process end of element.
81 sub _end_element {
82 4 ▶ my ($pyx_parser_obj, $elem) = @_;
Subroutine _end_element: called CC=1 SCAR=0.0
83 4 my $out = $pyx_parser_obj->{'output_handler'};
84 4 _end_of_start_tag($pyx_parser_obj);
85 4 print {$out} "</$elem>";
86 4 return;
87 }
88  
89 # Process data.
90 sub _data {
91 2 ▶ my ($pyx_parser_obj, $decoded_data) = @_;
Subroutine _data: called CC=1 SCAR=0.0
92 2 my $out = $pyx_parser_obj->{'output_handler'};
93 2 my $data = encode($decoded_data);
94 2 _end_of_start_tag($pyx_parser_obj);
95 2 print {$out} entity_encode($data);
96 2 return;
97 }
98  
99 # Process attribute.
100 sub _attribute {
101 4 ▶ my ($pyx_parser_obj, $att, $attval) = @_;
Subroutine _attribute: called CC=1 SCAR=0.0
102 4 my $out = $pyx_parser_obj->{'output_handler'};
103 4 print {$out} " $att=\"", entity_encode($attval), '"';
104 4 return;
105 }
106  
107 # Process instruction.
108 sub _instruction {
109 2 ▶ my ($pyx_parser_obj, $target, $data) = @_;
Subroutine _instruction: called CC=1 SCAR=0.0
110 2 my $out = $pyx_parser_obj->{'output_handler'};
111 2 _end_of_start_tag($pyx_parser_obj);
112 2 print {$out} "<?$target ", encode($data), "?>";
113 2 return;
114 }
115  
116 # Ends start tag.
117 sub _end_of_start_tag {
118 14 ▶ my $pyx_parser_obj = shift;
Subroutine _end_of_start_tag: called CC=2 SCAR=6.9
119 14 my $out = $pyx_parser_obj->{'output_handler'};
120 14 ▶ if ($pyx_parser_obj->{'non_parser_options'}->{'tag_open'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pyx_parser_obj->{"non_parser_options"}{"tag_open"}) 3 11 14
121 3 print {$out} '>';
122 3 $pyx_parser_obj->{'non_parser_options'}->{'tag_open'} = 0;
123 }
124 14 return;
125 }
126  
127 # Process comment.
128 sub _comment {
129 2 ▶ my ($pyx_parser_obj, $comment) = @_;
Subroutine _comment: called CC=1 SCAR=0.0
130 2 my $out = $pyx_parser_obj->{'output_handler'};
131 2 print {$out} '<!--'.encode($comment).'-->';
132 2 return;
133 }
134  
135 8 1;
136  
137 __END__
↑ Summary