| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#==== HTML::TocUpdator ======================================================== |
|
2
|
|
|
|
|
|
|
# function: Update 'HTML::Toc' table of contents. |
|
3
|
|
|
|
|
|
|
# note: - 'TUT' is an abbreviation of 'Toc Update Token'. |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package HTML::TocUpdator; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
6125
|
use strict; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
190
|
|
|
10
|
5
|
|
|
5
|
|
596
|
use HTML::TocInsertor; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
110
|
|
|
11
|
5
|
|
|
5
|
|
5126
|
use Data::Dumper; |
|
|
5
|
|
|
|
|
51839
|
|
|
|
5
|
|
|
|
|
551
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
|
15
|
5
|
|
|
5
|
|
46
|
use vars qw(@ISA $VERSION); |
|
|
5
|
|
|
|
|
47
|
|
|
|
5
|
|
|
|
|
341
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
11
|
$VERSION = '1.12'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
218
|
@ISA = qw(HTML::TocInsertor); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
5
|
|
|
5
|
|
44
|
use constant TUT_TOKENTYPE_START => 0; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
344
|
|
|
24
|
5
|
|
|
5
|
|
30
|
use constant TUT_TOKENTYPE_END => 1; |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
222
|
|
|
25
|
5
|
|
|
5
|
|
32
|
use constant TUT_TOKENTYPE_TEXT => 2; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
209
|
|
|
26
|
5
|
|
|
5
|
|
25
|
use constant TUT_TOKENTYPE_COMMENT => 3; |
|
|
5
|
|
|
|
|
19
|
|
|
|
5
|
|
|
|
|
236
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
5
|
|
|
5
|
|
27
|
use constant MODE_DO_NOTHING => 0; # 0b00 |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
216
|
|
|
29
|
5
|
|
|
5
|
|
26
|
use constant MODE_DO_INSERT => 1; # 0b01 |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
215
|
|
|
30
|
5
|
|
|
5
|
|
24
|
use constant MODE_DO_UPDATE => 3; # 0b11 |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
11008
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
5
|
|
|
5
|
|
27
|
END {} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#--- HTML::TocUpdator::new() -------------------------------------------------- |
|
37
|
|
|
|
|
|
|
# function: Constructor. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
|
40
|
|
|
|
|
|
|
# Get arguments |
|
41
|
6
|
|
|
6
|
1
|
56
|
my ($aType) = @_; |
|
42
|
6
|
|
|
|
|
53
|
my $self = $aType->SUPER::new; |
|
43
|
|
|
|
|
|
|
# Bias to not update ToC |
|
44
|
6
|
|
|
|
|
19
|
$self->{htu__Mode} = MODE_DO_NOTHING; |
|
45
|
|
|
|
|
|
|
# Bias to not delete tokens |
|
46
|
6
|
|
|
|
|
13
|
$self->{_doDeleteTokens} = 0; |
|
47
|
|
|
|
|
|
|
# Reset batch variables |
|
48
|
|
|
|
|
|
|
#$self->_resetBatchVariables; |
|
49
|
|
|
|
|
|
|
|
|
50
|
6
|
|
|
|
|
17
|
$self->{options} = {}; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# TODO: Initialize output |
|
53
|
|
|
|
|
|
|
|
|
54
|
6
|
|
|
|
|
18
|
return $self; |
|
55
|
|
|
|
|
|
|
} # new() |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_deinitializeUpdatorBatch() -------------------------- |
|
59
|
|
|
|
|
|
|
# function: Deinitialize updator batch. |
|
60
|
|
|
|
|
|
|
# args: - $aTocs: Reference to array of tocs. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _deinitializeUpdatorBatch { |
|
63
|
|
|
|
|
|
|
# Get arguments |
|
64
|
12
|
|
|
12
|
|
21
|
my ($self, $aTocs) = @_; |
|
65
|
|
|
|
|
|
|
# Indicate end of ToC updating |
|
66
|
12
|
|
|
|
|
24
|
$self->{htu__Mode} = MODE_DO_NOTHING; |
|
67
|
|
|
|
|
|
|
# Deinitialize insertor batch |
|
68
|
12
|
|
|
|
|
49
|
$self->_deinitializeInsertorBatch(); |
|
69
|
|
|
|
|
|
|
} # _deinitializeUpdatorBatch() |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#--- HTML::TokenUpdator::_doesHashEqualHash() --------------------------------- |
|
73
|
|
|
|
|
|
|
# function: Determines whether hash1 equals hash2. |
|
74
|
|
|
|
|
|
|
# args: - $aHash1 |
|
75
|
|
|
|
|
|
|
# - $aHash2 |
|
76
|
|
|
|
|
|
|
# returns: True (1) if hash1 equals hash2, 0 if not. For example, with the |
|
77
|
|
|
|
|
|
|
# following hashes: |
|
78
|
|
|
|
|
|
|
# |
|
79
|
|
|
|
|
|
|
# %hash1 = { %hash2 = { |
|
80
|
|
|
|
|
|
|
# 'class' => 'header', 'class' => 'header', |
|
81
|
|
|
|
|
|
|
# 'id' => 'intro1' 'id' => 'intro2' |
|
82
|
|
|
|
|
|
|
# } } |
|
83
|
|
|
|
|
|
|
# |
|
84
|
|
|
|
|
|
|
# the routine will return 0, cause the hash fields 'id' differ. |
|
85
|
|
|
|
|
|
|
# note: Class function. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _doesHashEqualHash { |
|
88
|
|
|
|
|
|
|
# Get arguments |
|
89
|
0
|
|
|
0
|
|
0
|
my ($aHash1, $aHash2) = @_; |
|
90
|
|
|
|
|
|
|
# Local variables |
|
91
|
0
|
|
|
|
|
0
|
my ($key1, $value1, $key2, $value2, $result); |
|
92
|
|
|
|
|
|
|
# Bias to success |
|
93
|
0
|
|
|
|
|
0
|
$result = 1; |
|
94
|
|
|
|
|
|
|
# Loop through hash1 while values available |
|
95
|
0
|
|
|
|
|
0
|
HASH1: while (($key1, $value1) = each %$aHash1) { |
|
96
|
|
|
|
|
|
|
# Yes, values are available; |
|
97
|
|
|
|
|
|
|
# Value1 differs from value2? |
|
98
|
0
|
0
|
|
|
|
0
|
if ($value1 ne $aHash2->{$key1}) { |
|
99
|
|
|
|
|
|
|
# Yes, hashes differ; |
|
100
|
|
|
|
|
|
|
# Indicate condition fails |
|
101
|
0
|
|
|
|
|
0
|
$result = 0; |
|
102
|
|
|
|
|
|
|
# Reset 'each' iterator which we're going to break |
|
103
|
0
|
|
|
|
|
0
|
keys %$aHash2; |
|
104
|
|
|
|
|
|
|
# Break loop |
|
105
|
0
|
|
|
|
|
0
|
last HASH1; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
# Return value |
|
109
|
0
|
|
|
|
|
0
|
return $result; |
|
110
|
|
|
|
|
|
|
} # _doesHashEqualHash() |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
#--- HTML::TokenUpdator::_doesTagExistInArray() ------------------------------- |
|
114
|
|
|
|
|
|
|
# function: Check whether tag & attributes matches any of the tags & attributes |
|
115
|
|
|
|
|
|
|
# in the specified array. The array must consist of elements with |
|
116
|
|
|
|
|
|
|
# format: |
|
117
|
|
|
|
|
|
|
# |
|
118
|
|
|
|
|
|
|
# [$tag, \%attributes] |
|
119
|
|
|
|
|
|
|
# |
|
120
|
|
|
|
|
|
|
# args: - $aTag: tag to search for |
|
121
|
|
|
|
|
|
|
# - $aAttributes: tag attributes to search for |
|
122
|
|
|
|
|
|
|
# - $aArray: Array to search in. |
|
123
|
|
|
|
|
|
|
# returns: 1 if tag does exist in array, 0 if not. |
|
124
|
|
|
|
|
|
|
# note: Class function. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _doesTagExistInArray { |
|
127
|
|
|
|
|
|
|
# Get arguments |
|
128
|
180
|
|
|
180
|
|
261
|
my ($aTag, $aAttributes, $aArray) = @_; |
|
129
|
|
|
|
|
|
|
# Local variables |
|
130
|
180
|
|
|
|
|
227
|
my ($tag, $result); |
|
131
|
|
|
|
|
|
|
# Bias to non-existing tag |
|
132
|
180
|
|
|
|
|
213
|
$result = 0; |
|
133
|
|
|
|
|
|
|
# Loop through existing tags |
|
134
|
180
|
|
|
|
|
227
|
TAG: foreach $tag (@{$aArray}) { |
|
|
180
|
|
|
|
|
375
|
|
|
135
|
10
|
50
|
|
|
|
12
|
if (defined(@{$tag}[0])) { |
|
|
10
|
|
|
|
|
18
|
|
|
136
|
|
|
|
|
|
|
# Does tag equals any existing tag? |
|
137
|
10
|
50
|
|
|
|
9
|
if ($aTag eq @{$tag}[0]) { |
|
|
10
|
|
|
|
|
28
|
|
|
138
|
|
|
|
|
|
|
# Yes, tag equals existing tag; |
|
139
|
|
|
|
|
|
|
# Do hashes equal? |
|
140
|
0
|
0
|
|
|
|
0
|
if (HTML::TocUpdator::_doesHashEqualHash( |
|
|
0
|
|
|
|
|
0
|
|
|
141
|
|
|
|
|
|
|
$aAttributes, @{$tag}[1] |
|
142
|
|
|
|
|
|
|
)) { |
|
143
|
|
|
|
|
|
|
# Yes, hashes are the same; |
|
144
|
|
|
|
|
|
|
# Indicate tag exists in array |
|
145
|
0
|
|
|
|
|
0
|
$result = 1; |
|
146
|
|
|
|
|
|
|
# Break loop |
|
147
|
0
|
|
|
|
|
0
|
last TAG; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
# Return value |
|
153
|
180
|
|
|
|
|
485
|
return $result; |
|
154
|
|
|
|
|
|
|
} # _doesTagExistInArray() |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_initializeUpdatorBatch() ---------------------------- |
|
158
|
|
|
|
|
|
|
# function: Initialize insertor batch. |
|
159
|
|
|
|
|
|
|
# args: - $aMode: Mode. Can be either MODE_DO_INSERT or MODE_DO_UPDATE |
|
160
|
|
|
|
|
|
|
# - $aTocs: Reference to array of tocs. |
|
161
|
|
|
|
|
|
|
# - $aOptions: optional options |
|
162
|
|
|
|
|
|
|
# note: Updating actually means: deleting the old ToC and inserting a new |
|
163
|
|
|
|
|
|
|
# ToC. That's why we're calling 'insertor' methods here. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _initializeUpdatorBatch { |
|
166
|
|
|
|
|
|
|
# Get arguments |
|
167
|
12
|
|
|
12
|
|
24
|
my ($self, $aMode, $aTocs, $aOptions) = @_; |
|
168
|
|
|
|
|
|
|
# Initialize insertor batch |
|
169
|
12
|
|
|
|
|
64
|
$self->_initializeInsertorBatch($aTocs, $aOptions); |
|
170
|
|
|
|
|
|
|
# Parse ToC update templates |
|
171
|
12
|
|
|
|
|
44
|
$self->_parseTocUpdateTokens(); |
|
172
|
|
|
|
|
|
|
# Indicate start of ToC updating |
|
173
|
12
|
|
|
|
|
201
|
$self->{htu__Mode} = $aMode; |
|
174
|
|
|
|
|
|
|
} # _initializeUpdatorBatch() |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_parseTocUpdateTokens() -------------------------------- |
|
178
|
|
|
|
|
|
|
# function: Parse ToC insertion point specifier. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub _parseTocUpdateTokens { |
|
181
|
|
|
|
|
|
|
# Get arguments |
|
182
|
12
|
|
|
12
|
|
17
|
my ($self) = @_; |
|
183
|
|
|
|
|
|
|
# Local variables |
|
184
|
12
|
|
|
|
|
19
|
my ($toc, $tokenType, $tokenPreposition, $token); |
|
185
|
0
|
|
|
|
|
0
|
my ($tocInsertionPoint, $tocInsertionPointTokenAttributes); |
|
186
|
|
|
|
|
|
|
# Create parser for update begin tokens |
|
187
|
12
|
|
|
|
|
73
|
my $tokenUpdateBeginParser = HTML::_TokenUpdateParser->new( |
|
188
|
|
|
|
|
|
|
$self->{_tokensUpdateBegin} |
|
189
|
|
|
|
|
|
|
); |
|
190
|
|
|
|
|
|
|
# Create parser for update end tokens |
|
191
|
12
|
|
|
|
|
41
|
my $tokenUpdateEndParser = HTML::_TokenUpdateParser->new( |
|
192
|
|
|
|
|
|
|
$self->{_tokensUpdateEnd} |
|
193
|
|
|
|
|
|
|
); |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# Loop through ToCs |
|
196
|
12
|
|
|
|
|
24
|
foreach $toc (@{$self->{_tocs}}) { |
|
|
12
|
|
|
|
|
38
|
|
|
197
|
|
|
|
|
|
|
# Parse update tokens |
|
198
|
16
|
|
|
|
|
79
|
$tokenUpdateBeginParser->parse( |
|
199
|
|
|
|
|
|
|
$toc->{_tokenUpdateBeginOfAnchorNameBegin} |
|
200
|
|
|
|
|
|
|
); |
|
201
|
16
|
|
|
|
|
99
|
$tokenUpdateBeginParser->parse($toc->{_tokenUpdateBeginOfAnchorNameEnd}); |
|
202
|
16
|
|
|
|
|
91
|
$tokenUpdateBeginParser->parse($toc->{_tokenUpdateBeginNumber}); |
|
203
|
16
|
|
|
|
|
92
|
$tokenUpdateBeginParser->parse($toc->{_tokenUpdateBeginToc}); |
|
204
|
|
|
|
|
|
|
|
|
205
|
16
|
|
|
|
|
90
|
$tokenUpdateEndParser->parse($toc->{_tokenUpdateEndOfAnchorNameBegin}); |
|
206
|
16
|
|
|
|
|
87
|
$tokenUpdateEndParser->parse($toc->{_tokenUpdateEndOfAnchorNameEnd}); |
|
207
|
16
|
|
|
|
|
88
|
$tokenUpdateEndParser->parse($toc->{_tokenUpdateEndNumber}); |
|
208
|
16
|
|
|
|
|
207
|
$tokenUpdateEndParser->parse($toc->{_tokenUpdateEndToc}); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
} # _parseTocUpdateTokens() |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_resetBatchVariables() --------------------------------- |
|
214
|
|
|
|
|
|
|
# function: Reset batch variables |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _resetBatchVariables { |
|
217
|
|
|
|
|
|
|
# Get arguments |
|
218
|
36
|
|
|
36
|
|
56
|
my ($self) = @_; |
|
219
|
|
|
|
|
|
|
# Call ancestor |
|
220
|
36
|
|
|
|
|
130
|
$self->SUPER::_resetBatchVariables(); |
|
221
|
|
|
|
|
|
|
# Arrays containing start, end, comment & text tokens which indicate |
|
222
|
|
|
|
|
|
|
# the begin of ToC tokens. The tokens are stored in keys of hashes to |
|
223
|
|
|
|
|
|
|
# avoid storing duplicates as an array would. |
|
224
|
36
|
|
|
|
|
103
|
$self->{_tokensUpdateBegin} = [ |
|
225
|
|
|
|
|
|
|
[], # ['', ] |
|
226
|
|
|
|
|
|
|
{}, # {'' => ''} |
|
227
|
|
|
|
|
|
|
{}, # {'' => ''} |
|
228
|
|
|
|
|
|
|
{} # {'' => ''} |
|
229
|
|
|
|
|
|
|
]; |
|
230
|
|
|
|
|
|
|
# Arrays containing start, end, comment & text tokens which indicate |
|
231
|
|
|
|
|
|
|
# the end of ToC tokens. The tokens are stored in keys of hashes to |
|
232
|
|
|
|
|
|
|
# avoid storing duplicates as an array would. |
|
233
|
36
|
|
|
|
|
260
|
$self->{_tokensUpdateEnd} = [ |
|
234
|
|
|
|
|
|
|
[], # ['', ] |
|
235
|
|
|
|
|
|
|
{}, # {'' => ''} |
|
236
|
|
|
|
|
|
|
{}, # {'' => ''} |
|
237
|
|
|
|
|
|
|
{} # {'' => ''} |
|
238
|
|
|
|
|
|
|
]; |
|
239
|
|
|
|
|
|
|
} # _resetBatchVariables() |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_setActiveAnchorName() --------------------------------- |
|
243
|
|
|
|
|
|
|
# function: Set active anchor name. |
|
244
|
|
|
|
|
|
|
# args: - aAnchorName: Name of anchor name to set active. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub _setActiveAnchorName { |
|
247
|
|
|
|
|
|
|
# Get arguments |
|
248
|
0
|
|
|
0
|
|
0
|
my ($self, $aAnchorName) = @_; |
|
249
|
|
|
|
|
|
|
# Are tokens being deleted? |
|
250
|
0
|
0
|
|
|
|
0
|
if (! $self->{_doDeleteTokens}) { |
|
251
|
|
|
|
|
|
|
# No, tokens aren't being deleted; |
|
252
|
|
|
|
|
|
|
# Call ancestor to set anchor name |
|
253
|
0
|
|
|
|
|
0
|
$self->SUPER::_setActiveAnchorName($aAnchorName); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
} # _setActiveAnchorName() |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_update() ---------------------------------------------- |
|
259
|
|
|
|
|
|
|
# function: Update ToC in string. |
|
260
|
|
|
|
|
|
|
# args: - $aMode: Mode. Can be either MODE_DO_UPDATE or MODE_DO_INSERT. |
|
261
|
|
|
|
|
|
|
# - $aToc: (reference to array of) ToC object to update |
|
262
|
|
|
|
|
|
|
# - $aString: string to update ToC of |
|
263
|
|
|
|
|
|
|
# - $aOptions: optional updator options |
|
264
|
|
|
|
|
|
|
# note: Used internally. |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub _update { |
|
267
|
|
|
|
|
|
|
# Get arguments |
|
268
|
5
|
|
|
5
|
|
8
|
my ($self, $aMode, $aToc, $aString, $aOptions) = @_; |
|
269
|
|
|
|
|
|
|
# Initialize TocUpdator batch |
|
270
|
5
|
|
|
|
|
18
|
$self->_initializeUpdatorBatch($aMode, $aToc, $aOptions); |
|
271
|
|
|
|
|
|
|
# Start updating ToC by starting ToC insertion |
|
272
|
5
|
|
|
|
|
25
|
$self->_insert($aString); |
|
273
|
|
|
|
|
|
|
# Deinitialize TocUpdator batch |
|
274
|
5
|
|
|
|
|
16
|
$self->_deinitializeUpdatorBatch(); |
|
275
|
|
|
|
|
|
|
} # update() |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_updateFile() ------------------------------------------ |
|
279
|
|
|
|
|
|
|
# function: Update ToCs in file. |
|
280
|
|
|
|
|
|
|
# args: - $aMode: Mode. Can be either MODE_DO_UPDATE or MODE_DO_INSERT. |
|
281
|
|
|
|
|
|
|
# - $aToc: (reference to array of) ToC object to update |
|
282
|
|
|
|
|
|
|
# - $aFile: (reference to array of) file to parse for updating. |
|
283
|
|
|
|
|
|
|
# - $aOptions: optional updator options |
|
284
|
|
|
|
|
|
|
# note: Used internally. |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub _updateFile { |
|
287
|
|
|
|
|
|
|
# Get arguments |
|
288
|
7
|
|
|
7
|
|
19
|
my ($self, $aMode, $aToc, $aFile, $aOptions) = @_; |
|
289
|
|
|
|
|
|
|
# Initialize TocUpdator batch |
|
290
|
7
|
|
|
|
|
27
|
$self->_initializeUpdatorBatch($aMode, $aToc, $aOptions); |
|
291
|
|
|
|
|
|
|
# Start updating ToC by starting ToC insertion |
|
292
|
7
|
|
|
|
|
203
|
$self->_insertIntoFile($aFile); |
|
293
|
|
|
|
|
|
|
# Deinitialize TocUpdator batch |
|
294
|
7
|
|
|
|
|
24
|
$self->_deinitializeUpdatorBatch(); |
|
295
|
|
|
|
|
|
|
} # _updateFile() |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_writeOrBufferOutput() --------------------------------- |
|
299
|
|
|
|
|
|
|
# function: Write processed HTML to output device(s). |
|
300
|
|
|
|
|
|
|
# args: - aOutput: scalar to write |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub _writeOrBufferOutput { |
|
303
|
|
|
|
|
|
|
# Get arguments |
|
304
|
671
|
|
|
671
|
|
1008
|
my ($self, $aOutput) = @_; |
|
305
|
|
|
|
|
|
|
# Delete tokens? |
|
306
|
671
|
100
|
|
|
|
1752
|
if ($self->{_doDeleteTokens}) { |
|
307
|
|
|
|
|
|
|
# Yes, delete output; |
|
308
|
316
|
|
|
|
|
455
|
$aOutput = ''; |
|
309
|
|
|
|
|
|
|
} # if |
|
310
|
|
|
|
|
|
|
# Call ancestor |
|
311
|
671
|
|
|
|
|
2076
|
$self->SUPER::_writeOrBufferOutput($aOutput); |
|
312
|
|
|
|
|
|
|
} # _writeOrBufferOutput() |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
#--- HTML::TocUpdator::anchorNameBegin() -------------------------------------- |
|
316
|
|
|
|
|
|
|
# function: Process 'anchor name begin' generated by HTML::Toc. |
|
317
|
|
|
|
|
|
|
# args: - $aAnchorName: Anchor name begin tag to output. |
|
318
|
|
|
|
|
|
|
# - $aToc: Reference to ToC to which anchorname belongs. |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub afterAnchorNameBegin { |
|
321
|
|
|
|
|
|
|
# Get arguments |
|
322
|
60
|
|
|
60
|
0
|
121
|
my ($self, $aAnchorNameBegin, $aToc) = @_; |
|
323
|
|
|
|
|
|
|
# Must ToC be inserted or updated? |
|
324
|
60
|
50
|
|
|
|
178
|
if ($self->{htu__Mode} != MODE_DO_NOTHING) { |
|
325
|
|
|
|
|
|
|
# Yes, ToC must be inserted or updated; |
|
326
|
|
|
|
|
|
|
# Surround anchor name with update tags |
|
327
|
60
|
|
|
|
|
180
|
$aAnchorNameBegin = |
|
328
|
|
|
|
|
|
|
$aToc->{_tokenUpdateBeginOfAnchorNameBegin} . |
|
329
|
|
|
|
|
|
|
$aAnchorNameBegin . |
|
330
|
|
|
|
|
|
|
$aToc->{_tokenUpdateEndOfAnchorNameBegin}; |
|
331
|
|
|
|
|
|
|
} # if |
|
332
|
|
|
|
|
|
|
# Call ancestor |
|
333
|
60
|
|
|
|
|
252
|
$self->SUPER::afterAnchorNameBegin($aAnchorNameBegin, $aToc); |
|
334
|
|
|
|
|
|
|
} # afterAnchorNameBegin() |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
#--- HTML::TocUpdator::anchorNameEnd() ---------------------------------------- |
|
338
|
|
|
|
|
|
|
# function: Process 'anchor name end' generated by HTML::Toc. |
|
339
|
|
|
|
|
|
|
# args: - $aAnchorNameEnd: Anchor name end tag to output. |
|
340
|
|
|
|
|
|
|
# - $aToc: Reference to ToC to which anchorname belongs. |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub anchorNameEnd { |
|
343
|
|
|
|
|
|
|
# Get arguments |
|
344
|
60
|
|
|
60
|
0
|
113
|
my ($self, $aAnchorNameEnd, $aToc) = @_; |
|
345
|
|
|
|
|
|
|
# Call ancestor |
|
346
|
60
|
|
|
|
|
218
|
$self->SUPER::anchorNameEnd($aAnchorNameEnd); |
|
347
|
|
|
|
|
|
|
# Must ToC be inserted or updated? |
|
348
|
60
|
50
|
|
|
|
171
|
if ($self->{htu__Mode} != MODE_DO_NOTHING) { |
|
349
|
|
|
|
|
|
|
# Yes, ToC must be inserted or updated; |
|
350
|
|
|
|
|
|
|
# Surround anchor name with update tags |
|
351
|
60
|
100
|
|
|
|
334
|
if ($self->{_outputPrefix}) { |
|
352
|
1
|
|
|
|
|
7
|
$self->{_outputPrefix} = |
|
353
|
|
|
|
|
|
|
$aToc->{_tokenUpdateBeginOfAnchorNameEnd} . |
|
354
|
|
|
|
|
|
|
$self->{_outputPrefix} . |
|
355
|
|
|
|
|
|
|
$aToc->{_tokenUpdateEndOfAnchorNameEnd}; |
|
356
|
|
|
|
|
|
|
} # if |
|
357
|
|
|
|
|
|
|
} # if |
|
358
|
|
|
|
|
|
|
} # anchorNameEnd() |
|
359
|
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
#--- HTML::TocUpdator::comment() ---------------------------------------------- |
|
362
|
|
|
|
|
|
|
# function: Process comment. |
|
363
|
|
|
|
|
|
|
# args: - $aComment: comment text with '' tags stripped off. |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
sub comment { |
|
366
|
|
|
|
|
|
|
# Get arguments |
|
367
|
124
|
|
|
124
|
1
|
1097
|
my ($self, $aComment) = @_; |
|
368
|
|
|
|
|
|
|
# Must ToC be updated? |
|
369
|
124
|
50
|
|
|
|
432
|
if ($self->{htu__Mode} == MODE_DO_UPDATE) { |
|
370
|
|
|
|
|
|
|
# Yes, ToC must be updated; |
|
371
|
|
|
|
|
|
|
# Updator is currently deleting tokens? |
|
372
|
124
|
100
|
|
|
|
237
|
if ($self->{_doDeleteTokens}) { |
|
373
|
|
|
|
|
|
|
# Yes, tokens must be deleted; |
|
374
|
|
|
|
|
|
|
# Look for update end token |
|
375
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
# Does comment matches update end token? |
|
377
|
62
|
100
|
|
|
|
175
|
if (defined( |
|
378
|
|
|
|
|
|
|
$self->{_tokensUpdateEnd}[TUT_TOKENTYPE_COMMENT]{$aComment} |
|
379
|
|
|
|
|
|
|
)) { |
|
380
|
|
|
|
|
|
|
# Yes, comment matches update end token; |
|
381
|
|
|
|
|
|
|
# Indicate to stop deleting tokens |
|
382
|
56
|
|
|
|
|
510
|
$self->{_doDeleteTokens} = 0; |
|
383
|
|
|
|
|
|
|
} else { |
|
384
|
|
|
|
|
|
|
# Call ancestor |
|
385
|
6
|
|
|
|
|
22
|
$self->SUPER::comment($aComment); |
|
386
|
|
|
|
|
|
|
} # if |
|
387
|
|
|
|
|
|
|
} else { |
|
388
|
|
|
|
|
|
|
# No, tokens mustn't be deleted; |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
# Look for update begin token |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
# Does comment matches update begin token? |
|
393
|
62
|
100
|
|
|
|
179
|
if (defined( |
|
394
|
|
|
|
|
|
|
$self->{_tokensUpdateBegin}[TUT_TOKENTYPE_COMMENT]{$aComment} |
|
395
|
|
|
|
|
|
|
)) { |
|
396
|
|
|
|
|
|
|
# Yes, comment matches update begin token; |
|
397
|
|
|
|
|
|
|
# Indicate to start deleting tokens |
|
398
|
56
|
|
|
|
|
165
|
$self->{_doDeleteTokens} = 1; |
|
399
|
|
|
|
|
|
|
} else { |
|
400
|
|
|
|
|
|
|
# Call ancestor |
|
401
|
6
|
|
|
|
|
26
|
$self->SUPER::comment($aComment); |
|
402
|
|
|
|
|
|
|
} # if |
|
403
|
|
|
|
|
|
|
} # if |
|
404
|
|
|
|
|
|
|
} else { |
|
405
|
|
|
|
|
|
|
# No, ToC mustn't be updated; |
|
406
|
|
|
|
|
|
|
# Call ancestor |
|
407
|
0
|
|
|
|
|
0
|
$self->SUPER::comment($aComment); |
|
408
|
|
|
|
|
|
|
} # if |
|
409
|
|
|
|
|
|
|
} # comment() |
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
#--- HTML::TocUpdator::end() -------------------------------------------------- |
|
413
|
|
|
|
|
|
|
# function: This function is called every time a closing tag is encountered. |
|
414
|
|
|
|
|
|
|
# args: - $aTag: tag name (in lower case). |
|
415
|
|
|
|
|
|
|
# - $aOrigText: tag name including brackets. |
|
416
|
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
sub end { |
|
418
|
|
|
|
|
|
|
# Get arguments |
|
419
|
177
|
|
|
177
|
1
|
314
|
my ($self, $aTag, $aOrigText) = @_; |
|
420
|
|
|
|
|
|
|
# Call ancestor |
|
421
|
177
|
|
|
|
|
505
|
$self->SUPER::end($aTag, $aOrigText); |
|
422
|
|
|
|
|
|
|
# Must ToC be updated? |
|
423
|
177
|
100
|
|
|
|
675
|
if ($self->{htu__Mode} == MODE_DO_UPDATE) { |
|
424
|
|
|
|
|
|
|
# Yes, ToC must be updated; |
|
425
|
|
|
|
|
|
|
# Updator is currently deleting tokens? |
|
426
|
172
|
100
|
|
|
|
907
|
if ($self->{_doDeleteTokens}) { |
|
427
|
|
|
|
|
|
|
# Yes, tokens must be deleted; |
|
428
|
|
|
|
|
|
|
# Does end tag matches update end token? |
|
429
|
89
|
50
|
|
|
|
836
|
if (defined( |
|
430
|
|
|
|
|
|
|
$self->{_tokensUpdateEnd}[TUT_TOKENTYPE_END]{$aTag} |
|
431
|
|
|
|
|
|
|
)) { |
|
432
|
|
|
|
|
|
|
# Yes, end tag matches update end token; |
|
433
|
|
|
|
|
|
|
# Indicate to stop deleting tokens |
|
434
|
0
|
|
|
|
|
0
|
$self->{_doDeleteTokens} = 0; |
|
435
|
|
|
|
|
|
|
} |
|
436
|
|
|
|
|
|
|
} |
|
437
|
|
|
|
|
|
|
} |
|
438
|
|
|
|
|
|
|
} # end() |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
#--- HTML::TocUpdator::insert() ----------------------------------------------- |
|
442
|
|
|
|
|
|
|
# function: Insert ToC in string. |
|
443
|
|
|
|
|
|
|
# args: - $aToc: (reference to array of) ToC object to update |
|
444
|
|
|
|
|
|
|
# - $aString: string to insert ToC in. |
|
445
|
|
|
|
|
|
|
# - $aOptions: optional updator options |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
sub insert { |
|
448
|
|
|
|
|
|
|
# Get arguments |
|
449
|
1
|
|
|
1
|
0
|
693
|
my ($self, $aToc, $aString, $aOptions) = @_; |
|
450
|
|
|
|
|
|
|
# Do start insert |
|
451
|
1
|
|
|
|
|
5
|
$self->_update(MODE_DO_INSERT, $aToc, $aString, $aOptions); |
|
452
|
|
|
|
|
|
|
} # insert() |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
#--- HTML::TocUpdator::insertIntoFile() -------------------------------------- |
|
456
|
|
|
|
|
|
|
# function: Insert ToC in file. |
|
457
|
|
|
|
|
|
|
# args: - $aToc: (reference to array of) ToC object to update |
|
458
|
|
|
|
|
|
|
# - $aFile: File to insert ToC in. |
|
459
|
|
|
|
|
|
|
# - $aOptions: optional updator options |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
sub insertIntoFile { |
|
462
|
|
|
|
|
|
|
# Get arguments |
|
463
|
2
|
|
|
2
|
0
|
479
|
my ($self, $aToc, $aFile, $aOptions) = @_; |
|
464
|
|
|
|
|
|
|
# Do start insert |
|
465
|
2
|
|
|
|
|
27
|
$self->_updateFile(MODE_DO_INSERT, $aToc, $aFile, $aOptions); |
|
466
|
|
|
|
|
|
|
} # insertIntoFile() |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
#--- HTML::TocUpdator::formatNumber() ---------------------------------- |
|
470
|
|
|
|
|
|
|
# function: Process heading number generated by HTML::Toc. |
|
471
|
|
|
|
|
|
|
# args: - $aNumber |
|
472
|
|
|
|
|
|
|
# - $aToc: Reference to ToC to which anchorname belongs. |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
sub formatNumber { |
|
475
|
|
|
|
|
|
|
# Get arguments |
|
476
|
47
|
|
|
47
|
0
|
377
|
my ($self, $aNumber, $aToc) = @_; |
|
477
|
|
|
|
|
|
|
# Call ancestor |
|
478
|
47
|
|
|
|
|
242
|
my $result = $self->SUPER::formatNumber($aNumber, $aToc); |
|
479
|
|
|
|
|
|
|
# Must ToC be inserted or updated? |
|
480
|
47
|
50
|
|
|
|
138
|
if ($self->{htu__Mode} != MODE_DO_NOTHING) { |
|
481
|
|
|
|
|
|
|
# Yes, ToC must be inserted or updated; |
|
482
|
|
|
|
|
|
|
# Surround number with update tags |
|
483
|
47
|
|
|
|
|
135
|
$result = $aToc->{_tokenUpdateBeginNumber} . $result . $aToc->{_tokenUpdateEndNumber}; |
|
484
|
|
|
|
|
|
|
} # if |
|
485
|
47
|
|
|
|
|
177
|
return $result; |
|
486
|
|
|
|
|
|
|
} # formatNumber() |
|
487
|
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
#--- HTML::TocUpdator::start() ------------------------------------------------ |
|
490
|
|
|
|
|
|
|
# function: This function is called every time an opening tag is encountered. |
|
491
|
|
|
|
|
|
|
# args: - $aTag: tag name (in lower case). |
|
492
|
|
|
|
|
|
|
# - $aAttr: reference to hash containing all tag attributes (in lower |
|
493
|
|
|
|
|
|
|
# case). |
|
494
|
|
|
|
|
|
|
# - $aAttrSeq: reference to array containing all tag attributes (in |
|
495
|
|
|
|
|
|
|
# lower case) in the original order |
|
496
|
|
|
|
|
|
|
# - $aOrigText: the original HTML text |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
sub start { |
|
499
|
|
|
|
|
|
|
# Get arguments |
|
500
|
181
|
|
|
181
|
1
|
779
|
my ($self, $aTag, $aAttr, $aAttrSeq, $aOrigText) = @_; |
|
501
|
|
|
|
|
|
|
# Must ToC be updated? |
|
502
|
181
|
100
|
|
|
|
500
|
if ($self->{htu__Mode} == MODE_DO_UPDATE) { |
|
503
|
|
|
|
|
|
|
# Yes, ToC must be updated; |
|
504
|
|
|
|
|
|
|
# Does start tag matches token update begin tag? |
|
505
|
176
|
50
|
|
|
|
502
|
if (HTML::TocUpdator::_doesTagExistInArray( |
|
506
|
|
|
|
|
|
|
$aTag, $aAttr, $self->{_tokensUpdateBegin}[TUT_TOKENTYPE_START] |
|
507
|
|
|
|
|
|
|
)) { |
|
508
|
|
|
|
|
|
|
# Yes, start tag matches token update tag; |
|
509
|
|
|
|
|
|
|
# Indicate to delete tokens |
|
510
|
0
|
|
|
|
|
0
|
$self->{_doDeleteTokens} = 1; |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
} |
|
513
|
|
|
|
|
|
|
# Let ancestor process the start tag |
|
514
|
181
|
|
|
|
|
747
|
$self->SUPER::start($aTag, $aAttr, $aAttrSeq, $aOrigText); |
|
515
|
|
|
|
|
|
|
} # start() |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
#--- HTML::TocUpdator::toc() -------------------------------------------------- |
|
519
|
|
|
|
|
|
|
# function: Toc processing method. Add toc reference to scenario. |
|
520
|
|
|
|
|
|
|
# args: - $aScenario: Scenario to add ToC reference to. |
|
521
|
|
|
|
|
|
|
# - $aToc: Reference to ToC to insert. |
|
522
|
|
|
|
|
|
|
# note: The ToC hasn't been build yet; only a reference to the ToC to be |
|
523
|
|
|
|
|
|
|
# build is inserted. |
|
524
|
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
sub toc { |
|
526
|
|
|
|
|
|
|
# Get arguments |
|
527
|
16
|
|
|
16
|
0
|
25
|
my ($self, $aScenario, $aToc) = @_; |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
# Surround toc with update tokens |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
# Add update begin token |
|
532
|
16
|
|
|
|
|
43
|
push(@$aScenario, \$aToc->{_tokenUpdateBeginToc}); |
|
533
|
|
|
|
|
|
|
# Call ancestor |
|
534
|
16
|
|
|
|
|
68
|
$self->SUPER::toc($aScenario, $aToc); |
|
535
|
|
|
|
|
|
|
# Add update end token |
|
536
|
16
|
|
|
|
|
42
|
push(@$aScenario, \$aToc->{_tokenUpdateEndToc}); |
|
537
|
|
|
|
|
|
|
} # toc() |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_processTocText() -------------------------------------- |
|
541
|
|
|
|
|
|
|
# function: Toc text processing function. |
|
542
|
|
|
|
|
|
|
# args: - $aText: Text to add to ToC. |
|
543
|
|
|
|
|
|
|
# - $aToc: ToC to add text to. |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
sub _processTocText { |
|
546
|
|
|
|
|
|
|
# Get arguments |
|
547
|
85
|
|
|
85
|
|
137
|
my ($self, $aText, $aToc) = @_; |
|
548
|
|
|
|
|
|
|
# Delete output? |
|
549
|
85
|
100
|
|
|
|
244
|
if (! $self->{_doDeleteTokens}) { |
|
550
|
|
|
|
|
|
|
# No, don't delete output; |
|
551
|
|
|
|
|
|
|
# Call ancestor |
|
552
|
61
|
|
|
|
|
239
|
$self->SUPER::_processTocText($aText, $aToc); |
|
553
|
|
|
|
|
|
|
} |
|
554
|
|
|
|
|
|
|
} # _processTocText() |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_processTocTokenChildren() ---------------------- |
|
558
|
|
|
|
|
|
|
# function: Toc token children processing function. |
|
559
|
|
|
|
|
|
|
# args: - $aText: Text to add to ToC. |
|
560
|
|
|
|
|
|
|
# - $aToc: ToC to which text belongs. |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub _processTocTokenChildren { |
|
563
|
|
|
|
|
|
|
# Get arguments |
|
564
|
312
|
|
|
312
|
|
586
|
my ($self, $aText, $aToc) = @_; |
|
565
|
|
|
|
|
|
|
# Delete output? |
|
566
|
312
|
100
|
|
|
|
999
|
if (! $self->{_doDeleteTokens}) { |
|
567
|
|
|
|
|
|
|
# No, don't delete output; |
|
568
|
|
|
|
|
|
|
# Call ancestor |
|
569
|
128
|
|
|
|
|
454
|
$self->SUPER::_processTocTokenChildren($aText, $aToc); |
|
570
|
|
|
|
|
|
|
} # if |
|
571
|
|
|
|
|
|
|
} # _processTocTokenChildren() |
|
572
|
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
#--- HTML::TocUpdator::_processTocTokenText() -------------------------- |
|
575
|
|
|
|
|
|
|
# function: Toc token text processing function. |
|
576
|
|
|
|
|
|
|
# args: - $aText: Text to add to ToC. |
|
577
|
|
|
|
|
|
|
# - $aToc: ToC to which text belongs. |
|
578
|
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
sub _processTocTokenText { |
|
580
|
|
|
|
|
|
|
# Get arguments |
|
581
|
85
|
|
|
85
|
|
131
|
my ($self, $aText, $aToc) = @_; |
|
582
|
|
|
|
|
|
|
# Delete output? |
|
583
|
85
|
100
|
|
|
|
254
|
if (! $self->{_doDeleteTokens}) { |
|
584
|
|
|
|
|
|
|
# No, don't delete output; |
|
585
|
|
|
|
|
|
|
# Call ancestor |
|
586
|
61
|
|
|
|
|
218
|
$self->SUPER::_processTocTokenText($aText, $aToc); |
|
587
|
|
|
|
|
|
|
} # if |
|
588
|
|
|
|
|
|
|
} # _processTocTokenText() |
|
589
|
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
#--- HTML::TocUpdator::update() ----------------------------------------------- |
|
592
|
|
|
|
|
|
|
# function: Update ToC in string. |
|
593
|
|
|
|
|
|
|
# args: - $aToc: (reference to array of) ToC object to update |
|
594
|
|
|
|
|
|
|
# - $aString: string to update ToC of |
|
595
|
|
|
|
|
|
|
# - $aOptions: optional updator options |
|
596
|
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
sub update { |
|
598
|
|
|
|
|
|
|
# Get arguments |
|
599
|
4
|
|
|
4
|
0
|
559
|
my ($self, $aToc, $aString, $aOptions) = @_; |
|
600
|
|
|
|
|
|
|
# Do start update |
|
601
|
4
|
|
|
|
|
17
|
$self->_update(MODE_DO_UPDATE, $aToc, $aString, $aOptions); |
|
602
|
|
|
|
|
|
|
} # update() |
|
603
|
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
#--- HTML::TocUpdator::updateFile() ------------------------------------------- |
|
606
|
|
|
|
|
|
|
# function: Update ToC of file. |
|
607
|
|
|
|
|
|
|
# args: - $aToc: (reference to array of) ToC object to update |
|
608
|
|
|
|
|
|
|
# - $aFile: (reference to array of) file to parse for updating. |
|
609
|
|
|
|
|
|
|
# - $aOptions: optional updator options |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
sub updateFile { |
|
612
|
|
|
|
|
|
|
# Get arguments |
|
613
|
5
|
|
|
5
|
0
|
547
|
my ($self, $aToc, $aFile, $aOptions) = @_; |
|
614
|
|
|
|
|
|
|
# Do start update |
|
615
|
5
|
|
|
|
|
25
|
$self->_updateFile(MODE_DO_UPDATE, $aToc, $aFile, $aOptions); |
|
616
|
|
|
|
|
|
|
} # update() |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
#=== HTML::_TokenUpdateParser ================================================= |
|
622
|
|
|
|
|
|
|
# function: Parse 'update tokens'. 'Update tokens' mark HTML code which is |
|
623
|
|
|
|
|
|
|
# inserted by 'HTML::TocInsertor'. |
|
624
|
|
|
|
|
|
|
# note: Used internally. |
|
625
|
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
package HTML::_TokenUpdateParser; |
|
627
|
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
BEGIN { |
|
630
|
5
|
|
|
5
|
|
38
|
use vars qw(@ISA); |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
246
|
|
|
631
|
|
|
|
|
|
|
|
|
632
|
5
|
|
|
5
|
|
2220
|
@ISA = qw(HTML::Parser); |
|
633
|
|
|
|
|
|
|
} |
|
634
|
|
|
|
|
|
|
|
|
635
|
5
|
|
|
5
|
|
6233
|
END {} |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
#--- HTML::_TokenUpdateParser::new() ------------------------------------------ |
|
639
|
|
|
|
|
|
|
# function: Constructor |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
sub new { |
|
642
|
|
|
|
|
|
|
# Get arguments |
|
643
|
24
|
|
|
24
|
|
40
|
my ($aType, $aTokenArray) = @_; |
|
644
|
|
|
|
|
|
|
# Create instance |
|
645
|
24
|
|
|
|
|
118
|
my $self = $aType->SUPER::new; |
|
646
|
|
|
|
|
|
|
# Reference token array |
|
647
|
24
|
|
|
|
|
966
|
$self->{tokens} = $aTokenArray; |
|
648
|
|
|
|
|
|
|
# Return instance |
|
649
|
24
|
|
|
|
|
46
|
return $self; |
|
650
|
|
|
|
|
|
|
} # new() |
|
651
|
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
#--- HTML::_TokenUpdateParser::comment() -------------------------------------- |
|
654
|
|
|
|
|
|
|
# function: Process comment. |
|
655
|
|
|
|
|
|
|
# args: - $aComment: comment text with '' tags stripped off. |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
sub comment { |
|
658
|
|
|
|
|
|
|
# Get arguments |
|
659
|
120
|
|
|
120
|
|
726
|
my ($self, $aComment) = @_; |
|
660
|
|
|
|
|
|
|
# Add token to array of update tokens |
|
661
|
120
|
|
|
|
|
472
|
$self->{tokens}[HTML::TocUpdator::TUT_TOKENTYPE_COMMENT]{$aComment} = ''; |
|
662
|
|
|
|
|
|
|
} # comment() |
|
663
|
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
#--- HTML::_TokenUpdateParser::end() ------------------------------------------ |
|
666
|
|
|
|
|
|
|
# function: This function is called every time a closing tag is encountered |
|
667
|
|
|
|
|
|
|
# by HTML::Parser. |
|
668
|
|
|
|
|
|
|
# args: - $aTag: tag name (in lower case). |
|
669
|
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
sub end { |
|
671
|
|
|
|
|
|
|
# Get arguments |
|
672
|
4
|
|
|
4
|
|
7
|
my ($self, $aTag, $aOrigText) = @_; |
|
673
|
|
|
|
|
|
|
# Add token to array of update tokens |
|
674
|
4
|
|
|
|
|
23
|
$self->{tokens}[HTML::TocUpdator::TUT_TOKENTYPE_END]{$aTag} = ''; |
|
675
|
|
|
|
|
|
|
} # end() |
|
676
|
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
#--- HTML::_TokenUpdateParser::parse() ---------------------------------------- |
|
679
|
|
|
|
|
|
|
# function: Parse token. |
|
680
|
|
|
|
|
|
|
# args: - $aToken: 'update token' to parse |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
sub parse { |
|
683
|
|
|
|
|
|
|
# Get arguments |
|
684
|
128
|
|
|
128
|
|
176
|
my ($self, $aString) = @_; |
|
685
|
|
|
|
|
|
|
# Call ancestor |
|
686
|
128
|
|
|
|
|
671
|
$self->SUPER::parse($aString); |
|
687
|
|
|
|
|
|
|
} # parse() |
|
688
|
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
#--- HTML::_TokenUpdateParser::start() ---------------------------------------- |
|
691
|
|
|
|
|
|
|
# function: This function is called every time an opening tag is encountered. |
|
692
|
|
|
|
|
|
|
# args: - $aTag: tag name (in lower case). |
|
693
|
|
|
|
|
|
|
# - $aAttr: reference to hash containing all tag attributes (in lower |
|
694
|
|
|
|
|
|
|
# case). |
|
695
|
|
|
|
|
|
|
# - $aAttrSeq: reference to array containing all tag attributes (in |
|
696
|
|
|
|
|
|
|
# lower case) in the original order |
|
697
|
|
|
|
|
|
|
# - $aOrigText: the original HTML text |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
sub start { |
|
700
|
|
|
|
|
|
|
# Get arguments |
|
701
|
4
|
|
|
4
|
|
8
|
my ($self, $aTag, $aAttr, $aAttrSeq, $aOrigText) = @_; |
|
702
|
|
|
|
|
|
|
# Does token exist in array? |
|
703
|
4
|
50
|
|
|
|
10
|
if (! HTML::TocUpdator::_doesTagExistInArray( |
|
704
|
|
|
|
|
|
|
$aTag, $aAttr, $self->{tokens}[HTML::TocUpdator::TUT_TOKENTYPE_START] |
|
705
|
|
|
|
|
|
|
)) { |
|
706
|
|
|
|
|
|
|
# No, token doesn't exist in array; |
|
707
|
|
|
|
|
|
|
# Add token to array of update tokens |
|
708
|
4
|
|
|
|
|
19
|
push( |
|
709
|
4
|
|
|
|
|
5
|
@{$self->{tokens}[HTML::TocUpdator::TUT_TOKENTYPE_START]}, |
|
710
|
|
|
|
|
|
|
[$aTag, $aAttr] |
|
711
|
|
|
|
|
|
|
); |
|
712
|
|
|
|
|
|
|
} |
|
713
|
|
|
|
|
|
|
} # start() |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
#--- HTML::_TokenUpdateParser::text() ----------------------------------------- |
|
717
|
|
|
|
|
|
|
# function: This function is called every time plain text is encountered. |
|
718
|
|
|
|
|
|
|
# args: - @_: array containing data. |
|
719
|
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
sub text { |
|
721
|
|
|
|
|
|
|
# Get arguments |
|
722
|
0
|
|
|
0
|
|
|
my ($self, $aText) = @_; |
|
723
|
|
|
|
|
|
|
# Add token to array of update tokens |
|
724
|
0
|
|
|
|
|
|
$self->{tokens}[HTML::TocUpdator::TUT_TOKENTYPE_TEXT]{$aText} = ''; |
|
725
|
|
|
|
|
|
|
} # text() |
|
726
|
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
1; |