File Coverage

blib/lib/Embperl/Syntax/HTML.pm
Criterion Covered Total %
statement 57 94 60.6
branch 22 42 52.3
condition 4 6 66.6
subroutine 8 11 72.7
pod 6 8 75.0
total 97 161 60.2


line stmt bran cond sub pod time code
1              
2             ###################################################################################
3             #
4             # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5             # Embperl - Copyright (c) 2008-2014 Gerald Richter
6             #
7             # You may distribute under the terms of either the GNU General Public
8             # License or the Artistic License, as specified in the Perl README file.
9             #
10             # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11             # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12             # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13             #
14             # $Id: HTML.pm 1578075 2014-03-16 14:01:14Z richter $
15             #
16             ###################################################################################
17            
18              
19              
20             package Embperl::Syntax::HTML ;
21              
22 1     1   7 use Embperl::Syntax (':types') ;
  1         3  
  1         205  
23              
24 1     1   5 use strict ;
  1         2  
  1         38  
25 1     1   4 use vars qw{@ISA %Attr %AssignAttr %AssignAttrLink %Quotes} ;
  1         2  
  1         1169  
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 2     2 1 4 my $self = shift ;
47              
48 2         7 $self = Embperl::Syntax::new ($self) ;
49              
50 2 50       20 if (!$self -> {-htmlAssignAttr})
51             {
52 2         9 $self -> {-htmlAssignAttr} = $self -> CloneHash (\%AssignAttr) ;
53 2         10 $self -> {-htmlAssignAttrLink} = $self -> CloneHash (\%AssignAttr) ;
54 2         10 $self -> {-htmlQuotes} = $self -> CloneHash (\%Quotes) ;
55             }
56              
57 2         8 return $self ;
58             }
59              
60              
61             # ---------------------------------------------------------------------------------
62             #
63             # Add new element
64             #
65             # ---------------------------------------------------------------------------------
66              
67              
68             sub AddElement
69              
70             {
71 58     58 0 93 my ($self, $tagtype, $tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo, $addsess) = @_ ;
72              
73              
74 58         55 my $ttref ;
75 58 50       165 die "'$tagtype' unknown" if (!($ttref = $self -> {-root}{$tagtype})) ;
76 58   100     121 my $ttfollow = ($ttref -> {'follow'} ||= {}) ;
77              
78 58         108 $ttref -> {'follow'}{-contains} = 'abcdefghijklmnopqrstuvwxyz0123456789_' ;
79            
80 58 100       265 my $tag = $ttfollow -> {$tagname} = {
81             'text' => $tagname,
82             'unescape' => 1,
83             (ref($taginfo) eq 'HASH'?%$taginfo:()),
84             } ;
85 58 100       167 $tag -> {'procinfo'} = { $self -> {-procinfotype} => $procinfo, (ref($taginfo) eq 'HASH'?%{$taginfo->{procinfo}}:()) } if ($procinfo) ;
  4 100       26  
86              
87 58         66 my %inside = (%{$self -> {-htmlQuotes}},
  58         325  
88             'removeslash' =>
89             {
90             'text' => "/",
91             'nodetype' => 0,
92             'cdatatype' => 0,
93             'removespaces' => 0,
94             'nodename' => '',
95             },
96              
97             ) ;
98 58         92 my $addinside = 0 ;
99 58 100       98 if ($attrs)
100             {
101 8         15 my $assignattr = $self -> {-htmlAssignAttr} ;
102 8         15 foreach (@$attrs)
103             {
104 12         53 $inside {$_} = { 'text' => $_, 'nodename' => $_, 'follow' => $assignattr },
105             $addinside++ ;
106             }
107             }
108 58 100       104 if ($attrsurl)
109             {
110 18         33 my $assignattr = $self -> {-htmlAssignAttrLink} ;
111 18         26 foreach (@$attrsurl)
112             {
113 18         88 $inside {$_} = { 'text' => $_, 'nodename' => $_, 'follow' => $assignattr },
114             $addinside++ ;
115             }
116 18 100       87 $tag -> {'procinfo'}{$self->{-procinfotype}}{perlcode} .=
117             q[Embperl::Cmd::AddSessionIdToLink (%$n%, ] . $addsess . q[,'] . join ("','", @$attrsurl) . "') ;"
118             if ($addsess) ;
119             }
120 58 100       92 if ($attrsnoval)
121             {
122 4         6 foreach (@$attrsnoval)
123             {
124 4         21 $inside {$_} = { 'text' => $_, , 'nodetype' => ntypAttr, },
125             $addinside++ ;
126             }
127             }
128 58 100       123 $tag -> {'inside'} = \%inside if ($addinside) ;
129              
130 58 100       116 if (exists ($tag -> {'inside'}))
131             {
132 24   100     61 $self -> {-htmlTagInside} ||= [] ;
133 24         40 push @{$self -> {-htmlTagInside}}, $tag -> {'inside'} ;
  24         61  
134             }
135              
136 58         205 return $tag ;
137             }
138              
139             # ---------------------------------------------------------------------------------
140             #
141             # Add new simple html tag
142             #
143             # ---------------------------------------------------------------------------------
144              
145              
146             sub AddTag
147              
148             {
149 58     58 1 66 my $self = shift ;
150              
151              
152 58 100       183 $self -> AddToRoot ({
153             'A HTML Tag' => {
154             'text' => '<',
155             'end' => '>',
156             }
157             }) if (!exists $self -> {-root}{'A HTML Tag'}) ;
158              
159              
160 58         131 $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 0     0 1 0 my $self = shift ;
176              
177 0         0 my $tag = $self -> AddTag (@_) ;
178            
179              
180 0         0 foreach my $inside (@{$self -> {-htmlTagInside}})
  0         0  
181             {
182 0 0       0 if (!exists ($inside -> {'HTML Tag'}))
183             {
184 0         0 $inside -> {'HTML Tag'} =
185             {
186             'text' => '<',
187             'end' => '>',
188             'follow' => {},
189             } ;
190             }
191 0         0 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
192             }
193              
194 0         0 my $quotes = $self -> {"-htmlQuotes"} ;
195 0         0 while (my ($k2, $v2) = each %$quotes)
196             {
197 0 0       0 if (ref($v2) eq 'HASH')
198             {
199 0         0 my $inside = $v2 -> {inside} ;
200 0 0       0 if (!exists ($inside -> {'HTML Tag'}))
201             {
202 0         0 $inside -> {'HTML Tag'} =
203             {
204             'text' => '<',
205             'end' => '>',
206             'follow' => {},
207             } ;
208             }
209 0         0 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
210              
211             }
212             }
213              
214 0         0 $quotes = $self -> {"-htmlAssignAttr"}{'Assign'}{follow} ;
215 0         0 while (my ($k2, $v2) = each %$quotes)
216             {
217 0 0       0 if (ref($v2) eq 'HASH')
218             {
219 0         0 my $inside = $v2 -> {inside} ;
220 0 0       0 if (!exists ($inside -> {'HTML Tag'}))
221             {
222 0         0 $inside -> {'HTML Tag'} =
223             {
224             'text' => '<',
225             'end' => '>',
226             'follow' => {},
227             } ;
228             }
229 0         0 $inside -> {'HTML Tag'}{follow}{$_[0]} = $tag ;
230              
231             }
232             }
233 0         0 $quotes = $self -> {"-htmlAssignAttrLink"}{'Assign'}{follow} ;
234 0         0 while (my ($k2, $v2) = each %$quotes)
235             {
236 0 0       0 if (ref($v2) eq 'HASH')
237             {
238 0         0 my $inside = $v2 -> {inside} ;
239 0 0       0 if (!exists ($inside -> {'HTML Tag'}))
240             {
241 0         0 $inside -> {'HTML Tag'} =
242             {
243             'text' => '<',
244             'end' => '>',
245             'follow' => {},
246             } ;
247             }
248 0         0 $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 0     0 1 0 my $self = shift ;
266              
267              
268 0 0       0 $self -> AddToRoot (
269             {
270             'HTML Comment' => {
271             'text' => '',
273             }
274             }) if (!exists $self -> {-root}{'HTML Comment'}) ;
275            
276 0         0 $self -> AddElement ('HTML Comment', @_) ;
277             }
278              
279             # ---------------------------------------------------------------------------------
280             #
281             # Add new block html tag
282             #
283             # ---------------------------------------------------------------------------------
284              
285              
286             sub AddTagBlock
287              
288             {
289 18     18 1 32 my ($self, $tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) = @_ ;
290              
291              
292 18         41 my $tag = $self -> AddTag ($tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) ;
293              
294 18         47 $tag -> {'nodetype'} = &ntypStartTag ;
295              
296 18         87 $tag = $self -> AddTag ("/$tagname") ;
297              
298 18         48 $tag -> {'nodetype'} = &ntypEndTag ;
299 18         55 $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 2     2 1 6 my ($self, $tagname, $starttag, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) = @_ ;
314              
315              
316 2         7 my $tag = $self -> AddTag ($tagname, $attrs, $attrsurl, $attrsnoval, $procinfo, $taginfo) ;
317              
318 2         9 $tag -> {'starttag'} = $starttag ;
319             }
320              
321              
322              
323              
324             # ---------------------------------------------------------------------------------
325             #
326             #
327             #
328             # ---------------------------------------------------------------------------------
329              
330              
331            
332             sub AddInside
333              
334             {
335 0     0 0   my ($self, $tagtype, $inside) = @_ ;
336              
337 0           my $ttref ;
338 0 0         die "'$tagtype' unknown" if (!($ttref = $self -> {-tagtype}{$tagtype})) ;
339 0   0       my $ttinside = ($ttref -> {'inside'} ||= {}) ;
340            
341 0           while (my ($k, $v) = each (%$inside))
342             {
343 0           $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__