blib/lib/Embperl/Syntax/HTML.pm untested

filter: Statementstmt 0.0% 0 / 125 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 195 CC 22 SCAR 41.8
CC
22
Cov
0%
AddElement
132.0
AddTagInside
72.0
new
6.0
CRAP 65.2
1  
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2015 Gerald Richter
6 # Embperl - Copyright (c) 2015-2023 actevy.io
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the Perl README file.
10 #
11 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
12 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 #
15  
16 ###################################################################################
17
18  
19  
20 package Embperl::Syntax::HTML ;
21  
22 use Embperl::Syntax (':types') ;
23  
24 use strict ;
25 use vars qw{@ISA %Attr %AssignAttr %AssignAttrLink %Quotes} ;
26  
27  
28 @ISA = qw(Embperl::Syntax) ;
29  
30  
31 ###################################################################################
32 #
33 # Methods
34 #
35 ###################################################################################
36  
37 # ---------------------------------------------------------------------------------
38 #
39 # Create new Syntax Object
40 #
41 # ---------------------------------------------------------------------------------
42  
43 sub new
44  
45 {
46 my $self = shift ;
47  
48 $self = Embperl::Syntax::new ($self) ;
49  
50 if (!$self -> {-htmlAssignAttr})
51 {
52 $self -> {-htmlAssignAttr} = $self -> CloneHash (\%AssignAttr) ;
53 $self -> {-htmlAssignAttrLink} = $self -> CloneHash (\%AssignAttr) ;
54 $self -> {-htmlQuotes} = $self -> CloneHash (\%Quotes) ;
55 }
56  
57 return $self ;
58 }
59  
60  
61 # ---------------------------------------------------------------------------------
62 #
63 # Add new element
64 #
65 # ---------------------------------------------------------------------------------
66  
67  
68 sub AddElement
69  
70 {
71 my ($self, $tagtype, $tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo, $addsess) = @_ ;
72  
73  
74 my $ttref ;
75 die "'$tagtype' unknown" if (!($ttref = $self -> {-root}{$tagtype})) ;
76 my $ttfollow = ($ttref -> {'follow'} ||= {}) ;
77  
78 $ttref -> {'follow'}{-contains} = 'abcdefghijklmnopqrstuvwxyz0123456789_' ;
79
80 my $tag = $ttfollow -> {$tagname} = {
81 'text' => $tagname,
82 'unescape' => 1,
83 (ref($taginfo) eq 'HASH'?%$taginfo:()),
84 } ;
85 $tag -> {'procinfo'} = { $self -> {-procinfotype} => $procinfo, (ref($taginfo) eq 'HASH'?%{$taginfo->{procinfo}}:()) } if ($procinfo) ;
86  
87 my %inside = (%{$self -> {-htmlQuotes}},
88 'removeslash' =>
89 {
90 'text' => "/",
91 'nodetype' => 0,
92 'cdatatype' => 0,
93 'removespaces' => 0,
94 'nodename' => '',
95 },
96  
97 ) ;
98 my $addinside = 0 ;
99 if ($attrs)
100 {
101 my $assignattr = $self -> {-htmlAssignAttr} ;
102 foreach (@$attrs)
103 {
104 $inside {$_} = { 'text' => $_, 'nodename' => $_, 'follow' => $assignattr },
105 $addinside++ ;
106 }
107 }
108 if ($attrsurl)
109 {
110 my $assignattr = $self -> {-htmlAssignAttrLink} ;
111 foreach (@$attrsurl)
112 {
113 $inside {$_} = { 'text' => $_, 'nodename' => $_, 'follow' => $assignattr },
114 $addinside++ ;
115 }
116 $tag -> {'procinfo'}{$self->{-procinfotype}}{perlcode} .=
117 q[Embperl::Cmd::AddSessionIdToLink (%$n%, ] . $addsess . q[,'] . join ("','", @$attrsurl) . "') ;"
118 if ($addsess) ;
119 }
120 if ($attrsnoval)
121 {
122 foreach (@$attrsnoval)
123 {
124 $inside {$_} = { 'text' => $_, , 'nodetype' => ntypAttr, },
125 $addinside++ ;
126 }
127 }
128 $tag -> {'inside'} = \%inside if ($addinside) ;
129  
130 if (exists ($tag -> {'inside'}))
131 {
132 $self -> {-htmlTagInside} ||= [] ;
133 push @{$self -> {-htmlTagInside}}, $tag -> {'inside'} ;
134 }
135  
136 return $tag ;
137 }
138  
139 # ---------------------------------------------------------------------------------
140 #
141 # Add new simple html tag
142 #
143 # ---------------------------------------------------------------------------------
144  
145  
146 sub AddTag
147  
148 {
149 my $self = shift ;
150  
151  
152 $self -> AddToRoot ({
153 'A HTML Tag' => {
154 'text' => '<',
155 'end' => '>',
156 }
157 }) if (!exists $self -> {-root}{'A HTML Tag'}) ;
158  
159  
160 $self -> AddElement ('A HTML Tag', @_) ;
161 }
162  
163  
164  
165 # ---------------------------------------------------------------------------------
166 #
167 # Add new simple html tag which is also available inside of other tags
168 #
169 # ---------------------------------------------------------------------------------
170  
171  
172 sub AddTagInside
173  
174 {
175 my $self = shift ;
176  
177 my $tag = $self -> AddTag (@_) ;
178
179  
180 foreach my $inside (@{$self -> {-htmlTagInside}})
181 {
182 if (!exists ($inside -> {'HTML Tag'}))
183 {
184 $inside -> {'HTML Tag'} =
185 {
186 'text' => '<',
187 'end' => '>',
188 'follow' => {},
189 } ;
190 }
191 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
192 }
193  
194 my $quotes = $self -> {"-htmlQuotes"} ;
195 while (my ($k2, $v2) = each %$quotes)
196 {
197 if (ref($v2) eq 'HASH')
198 {
199 my $inside = $v2 -> {inside} ;
200 if (!exists ($inside -> {'HTML Tag'}))
201 {
202 $inside -> {'HTML Tag'} =
203 {
204 'text' => '<',
205 'end' => '>',
206 'follow' => {},
207 } ;
208 }
209 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
210  
211 }
212 }
213  
214 $quotes = $self -> {"-htmlAssignAttr"}{'Assign'}{follow} ;
215 while (my ($k2, $v2) = each %$quotes)
216 {
217 if (ref($v2) eq 'HASH')
218 {
219 my $inside = $v2 -> {inside} ;
220 if (!exists ($inside -> {'HTML Tag'}))
221 {
222 $inside -> {'HTML Tag'} =
223 {
224 'text' => '<',
225 'end' => '>',
226 'follow' => {},
227 } ;
228 }
229 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
230  
231 }
232 }
233 $quotes = $self -> {"-htmlAssignAttrLink"}{'Assign'}{follow} ;
234 while (my ($k2, $v2) = each %$quotes)
235 {
236 if (ref($v2) eq 'HASH')
237 {
238 my $inside = $v2 -> {inside} ;
239 if (!exists ($inside -> {'HTML Tag'}))
240 {
241 $inside -> {'HTML Tag'} =
242 {
243 'text' => '<',
244 'end' => '>',
245 'follow' => {},
246 } ;
247 }
248 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
249  
250 }
251 }
252 }
253  
254  
255 # ---------------------------------------------------------------------------------
256 #
257 # Add new html comment tag
258 #
259 # ---------------------------------------------------------------------------------
260  
261  
262 sub AddComment
263  
264 {
265 my $self = shift ;
266  
267  
268 $self -> AddToRoot (
269 {
270 'HTML Comment' => {
271 'text' => '<!--',
272 'end' => '-->',
273 }
274 }) if (!exists $self -> {-root}{'HTML Comment'}) ;
275
276 $self -> AddElement ('HTML Comment', @_) ;
277 }
278  
279 # ---------------------------------------------------------------------------------
280 #
281 # Add new block html tag
282 #
283 # ---------------------------------------------------------------------------------
284  
285  
286 sub AddTagBlock
287  
288 {
289 my ($self, $tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) = @_ ;
290  
291  
292 my $tag = $self -> AddTag ($tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) ;
293  
294 $tag -> {'nodetype'} = &ntypStartTag ;
295  
296 $tag = $self -> AddTag ("/$tagname") ;
297  
298 $tag -> {'nodetype'} = &ntypEndTag ;
299 $tag -> {'starttag'} = $tagname ;
300 }
301  
302  
303 # ---------------------------------------------------------------------------------
304 #
305 # Add new html tag which is an optional end tag
306 #
307 # ---------------------------------------------------------------------------------
308  
309  
310 sub AddTagWithStart
311  
312 {
313 my ($self, $tagname, $starttag, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) = @_ ;
314  
315  
316 my $tag = $self -> AddTag ($tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) ;
317  
318 $tag -> {'starttag'} = $starttag ;
319 }
320  
321  
322  
323  
324 # ---------------------------------------------------------------------------------
325 #
326 #
327 #
328 # ---------------------------------------------------------------------------------
329  
330  
331
332 sub AddInside
333  
334 {
335 my ($self, $tagtype, $inside) = @_ ;
336  
337 my $ttref ;
338 die "'$tagtype' unknown" if (!($ttref = $self -> {-tagtype}{$tagtype})) ;
339 my $ttinside = ($ttref -> {'inside'} ||= {}) ;
340
341 while (my ($k, $v) = each (%$inside))
342 {
343 $ttinside -> {$k} = $v ;
344 }
345  
346 }
347  
348  
349 ###################################################################################
350 #
351 # Definitions for HTML attributs
352 #
353 ###################################################################################
354  
355  
356 %Attr = (
357 '-lsearch' => 1,
358 'Attribut ""' =>
359 {
360 'text' => '"',
361 'end' => '"',
362 'nodetype' => ntypAttr,
363 'cdatatype' => ntypAttrValue,
364 },
365 'Attribut \'\'' =>
366 {
367 'text' => '\'',
368 'end' => '\'',
369 'nodetype' => ntypAttr,
370 'cdatatype' => ntypAttrValue,
371 'addflags' => aflgSingleQuote,
372 },
373 'Attribut alphanum' =>
374 {
375 'contains' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789',
376 'nodetype' => ntypAttr,
377 'cdatatype' => ntypAttrValue,
378 }
379 ) ;
380  
381  
382 %AssignAttr = (
383 'Assign' =>
384 {
385 'text' => '=',
386 'follow' => \%Attr,
387 }
388 ) ;
389  
390 %Quotes = (
391 'Quote ""' =>
392 {
393 'text' => '"',
394 'end' => '"',
395 'nodetype' => ntypCDATA,
396 'cdatatype' => ntypAttrValue,
397 },
398 'Quote \'\'' =>
399 {
400 'text' => '\'',
401 'end' => '\'',
402 'nodetype' => ntypCDATA,
403 'cdatatype' => ntypAttrValue,
404 },
405 ) ;
406  
407  
408 1;
409  
410  
411 __END__