line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PYX::SGML::Tags; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
411688
|
use strict; |
|
18
|
|
|
|
|
160
|
|
|
18
|
|
|
|
|
537
|
|
4
|
18
|
|
|
18
|
|
97
|
use warnings; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
560
|
|
5
|
|
|
|
|
|
|
|
6
|
18
|
|
|
18
|
|
4511
|
use Class::Utils qw(set_params); |
|
18
|
|
|
|
|
251542
|
|
|
18
|
|
|
|
|
614
|
|
7
|
18
|
|
|
18
|
|
757
|
use Error::Pure qw(err); |
|
18
|
|
|
|
|
45
|
|
|
18
|
|
|
|
|
715
|
|
8
|
18
|
|
|
18
|
|
8569
|
use PYX::Parser; |
|
18
|
|
|
|
|
223613
|
|
|
18
|
|
|
|
|
652
|
|
9
|
18
|
|
|
18
|
|
8008
|
use PYX::Utils qw(encode); |
|
18
|
|
|
|
|
127787
|
|
|
18
|
|
|
|
|
341
|
|
10
|
18
|
|
|
18
|
|
10457
|
use Tags::Output::Raw; |
|
18
|
|
|
|
|
145090
|
|
|
18
|
|
|
|
|
13321
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.06; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constructor. |
15
|
|
|
|
|
|
|
sub new { |
16
|
16
|
|
|
16
|
1
|
8959
|
my ($class, @params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
16
|
|
|
|
|
49
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Input encoding. |
21
|
16
|
|
|
|
|
69
|
$self->{'input_encoding'} = 'utf-8'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Input 'Tags' item callback. |
24
|
16
|
|
|
|
|
37
|
$self->{'input_tags_item_callback'} = undef; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Tags object. |
27
|
16
|
|
|
|
|
42
|
$self->{'tags'} = undef; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Process params. |
30
|
16
|
|
|
|
|
87
|
set_params($self, @params); |
31
|
|
|
|
|
|
|
|
32
|
16
|
100
|
|
|
|
281
|
if (! defined $self->{'tags'}) { |
33
|
|
|
|
|
|
|
$self->{'tags'} = Tags::Output::Raw->new( |
34
|
|
|
|
|
|
|
'input_tags_item_callback' |
35
|
1
|
|
|
|
|
11
|
=> $self->{'input_tags_item_callback'}, |
36
|
|
|
|
|
|
|
'output_handler' => \*STDOUT, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Check for Tags::Output object. |
41
|
16
|
100
|
|
|
|
264
|
if (! $self->{'tags'}->isa('Tags::Output')) { |
42
|
2
|
|
|
|
|
6
|
err "Bad 'Tags::Output::*' object."; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# PYX::Parser object. |
46
|
|
|
|
|
|
|
$self->{'pyx_parser'} = PYX::Parser->new( |
47
|
|
|
|
|
|
|
'callbacks' => { |
48
|
|
|
|
|
|
|
'attribute' => \&_attribute, |
49
|
|
|
|
|
|
|
'comment' => \&_comment, |
50
|
|
|
|
|
|
|
'data' => \&_data, |
51
|
|
|
|
|
|
|
'end_element' => \&_end_element, |
52
|
|
|
|
|
|
|
'instruction' => \&_instruction, |
53
|
|
|
|
|
|
|
'start_element' => \&_start_element, |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
'input_encoding' => $self->{'input_encoding'}, |
56
|
|
|
|
|
|
|
'non_parser_options' => { |
57
|
14
|
|
|
|
|
234
|
'tags' => $self->{'tags'}, |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Object. |
62
|
14
|
|
|
|
|
872
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Parse pyx text or array of pyx text. |
66
|
|
|
|
|
|
|
sub parse { |
67
|
16
|
|
|
16
|
1
|
7935
|
my ($self, $pyx, $out) = @_; |
68
|
|
|
|
|
|
|
|
69
|
16
|
|
|
|
|
72
|
$self->{'pyx_parser'}->parse($pyx, $out); |
70
|
16
|
|
|
|
|
185
|
$self->{'tags'}->flush; |
71
|
|
|
|
|
|
|
|
72
|
16
|
|
|
|
|
356
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Parse file with pyx text. |
76
|
|
|
|
|
|
|
sub parse_file { |
77
|
15
|
|
|
15
|
1
|
8810
|
my ($self, $file, $out) = @_; |
78
|
|
|
|
|
|
|
|
79
|
15
|
|
|
|
|
65
|
$self->{'pyx_parser'}->parse_file($file, $out); |
80
|
15
|
|
|
|
|
608
|
$self->{'tags'}->flush; |
81
|
|
|
|
|
|
|
|
82
|
15
|
|
|
|
|
335
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Parse from handler. |
86
|
|
|
|
|
|
|
sub parse_handler { |
87
|
0
|
|
|
0
|
1
|
0
|
my ($self, $input_file_handler, $out) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
$self->{'pyx_parser'}->parse_handler($input_file_handler, $out); |
90
|
0
|
|
|
|
|
0
|
$self->{'tags'}->flush; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub finalize { |
96
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
4
|
$self->{'tags'}->finalize; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
118
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Process start of element. |
104
|
|
|
|
|
|
|
sub _start_element { |
105
|
17
|
|
|
17
|
|
3017
|
my ($self, $elem) = @_; |
106
|
|
|
|
|
|
|
|
107
|
17
|
|
|
|
|
33
|
my $tags = $self->{'non_parser_options'}->{'tags'}; |
108
|
17
|
|
|
|
|
169
|
$tags->put(['b', $elem]); |
109
|
|
|
|
|
|
|
|
110
|
17
|
|
|
|
|
999
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Process end of element. |
114
|
|
|
|
|
|
|
sub _end_element { |
115
|
16
|
|
|
16
|
|
1276
|
my ($self, $elem) = @_; |
116
|
|
|
|
|
|
|
|
117
|
16
|
|
|
|
|
31
|
my $tags = $self->{'non_parser_options'}->{'tags'}; |
118
|
16
|
|
|
|
|
59
|
$tags->put(['e', $elem]); |
119
|
|
|
|
|
|
|
|
120
|
16
|
|
|
|
|
1348
|
return; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Process data. |
124
|
|
|
|
|
|
|
sub _data { |
125
|
8
|
|
|
8
|
|
1372
|
my ($self, $data) = @_; |
126
|
|
|
|
|
|
|
|
127
|
8
|
|
|
|
|
19
|
my $tags = $self->{'non_parser_options'}->{'tags'}; |
128
|
8
|
|
|
|
|
51
|
$tags->put(['d', encode($data)]); |
129
|
|
|
|
|
|
|
|
130
|
8
|
|
|
|
|
1277
|
return; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Process attribute. |
134
|
|
|
|
|
|
|
sub _attribute { |
135
|
12
|
|
|
12
|
|
906
|
my ($self, $attr, $value) = @_; |
136
|
|
|
|
|
|
|
|
137
|
12
|
|
|
|
|
30
|
my $tags = $self->{'non_parser_options'}->{'tags'}; |
138
|
12
|
|
|
|
|
46
|
$tags->put(['a', $attr, $value]); |
139
|
|
|
|
|
|
|
|
140
|
12
|
|
|
|
|
2863
|
return; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Process instruction tag. |
144
|
|
|
|
|
|
|
sub _instruction { |
145
|
4
|
|
|
4
|
|
931
|
my ($self, $target, $code) = @_; |
146
|
|
|
|
|
|
|
|
147
|
4
|
|
|
|
|
10
|
my $tags = $self->{'non_parser_options'}->{'tags'}; |
148
|
4
|
|
|
|
|
66
|
$tags->put(['i', $target, $code]); |
149
|
|
|
|
|
|
|
|
150
|
4
|
|
|
|
|
223
|
return; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Process comments. |
154
|
|
|
|
|
|
|
sub _comment { |
155
|
4
|
|
|
4
|
|
924
|
my ($self, $comment) = @_; |
156
|
|
|
|
|
|
|
|
157
|
4
|
|
|
|
|
10
|
my $tags = $self->{'non_parser_options'}->{'tags'}; |
158
|
4
|
|
|
|
|
44
|
$tags->put(['c', encode($comment)]); |
159
|
|
|
|
|
|
|
|
160
|
4
|
|
|
|
|
250
|
return; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |