uHTML/std.pm untested

filter: Statementstmt 0.0% 0 / 466 Branchbran 0.0% 0 / 240 Conditioncond 0.0% 0 / 146 Subroutinesub 0.0% 0 / 48 Podpod 0.0% 0 / 38 totaltotal 0.0% 0 / 938 CC 121 SCAR 43.4
CC
121
Cov
0%
Repeat
342.0
Choice
132.0
Include
110.0
CRAP 76.9
1  
2  
3 #
4 # Author: Roland Mosler - Roland@Place.Ug
5 #
6 # Das ist eine uHTML-Bibliothek von Place.Ug
7 # Es ist erlaubt dieses Paket unter der aktuellen GNU LGPL zu nutzen
8 # Bei Weiterentwicklungen ist die Ursprungsbibliothek zu nennen
9 #
10 # Fehler und Verbesserungen bitte an uHTML@Place.Ug
11 #
12 # This is a uHTML library from Place.Ug
13 # It is allowed to use this library under the actual GNU LGPL
14 # The name of this library is to be named in all derivations
15 #
16 # Please report errors to uHTML@Place.Ug
17 #
18 # © Roland Mosler, Place.Ug
19 #
20  
21 use strict ;
22  
23 package uHTML::std ;
24  
25 use version ; our $VERSION = "2.24" ;
26  
27 require Exporter;
28 our @ISA = qw(Exporter);
29 our @EXPORT_OK = qw( uFilePath ) ;
30  
31 use uHTML ;
32 use uHTML::ListFuncs( 'uniq','section','difference','shuffle' ) ;
33  
34 my( %MACROS ) ;
35  
36 my $SO = qr/\s*,\s*/ ;
37 my $RO = qr/\s*[,;:]\s*/ ;
38  
39 use constant { TIMEOUT => 6000 } ;
40  
41  
42 sub DoIf( $ )
43 {
44 my $Node = shift ;
45  
46 my $Child ;
47  
48 if( eval( $Node->attr( 'cond' ) ) )
49 {
50 my @D ;
51  
52 for( $Child=$Node->{'FirstChild'}; $Child; $Child=$Child->{'Next'} )
53 {
54 push @D,$Child if $Child->{'Name'} eq 'else';
55 }
56 $_->delete() foreach @D ;
57 $Node->map( '','' ) ;
58 }
59 else
60 {
61 my( $Elif,$Else ) ;
62  
63 for( $Child=$Node->{'FirstChild'}; $Child && !$Elif; $Child=$Child->{'Next'} )
64 {
65 next unless $Child->{'Name'} eq 'else' ;
66  
67 if( $Child->testAttr( 'cond' ) )
68 {
69 $Elif = $Child if eval( $Child->attr( 'cond' ) ) ;
70 }
71 else
72 {
73 $Else = $Child ;
74 }
75 }
76 $Else = $Elif if $Elif ;
77 $Node->{'Text'} = '' ;
78 $Node->{'HTML'} = $Else ? $Else->map( '','' ) : undef ;
79 }
80 }
81  
82 sub Choice( $ )
83 {
84 my $Node = shift ;
85 return unless $Node->testAttr( 'tag' ) ;
86 my $Name = $Node->attr( 'tag' ) ;
87 return unless $Name ;
88 my $cond = eval( $Node->attr( 'cond' ) ) ? 0 : 1 ;
89 my( $P,@S ) ;
90 @S = split m/\|/,$Name,2 ;
91 $Name = $S[$cond] if $#S>0 ;
92 return unless $Name and $Name ne 'choice' ;
93 $Node->name( $Name ) ;
94 my $Add = $Node->attr( 'attr' ) ;
95 $Node->deleteAttr( 'cond','tag','attr' ) ;
96 foreach( keys %{$Node->attributes()} )
97 {
98 next unless $P = $Node->rawAttr( $_ ) ;
99 @S = split m/\|/,$P,2 ;
100 $S[$cond] ne '' ? $Node->rawAttr( $_,$S[$cond] ) : $Node->deleteAttr( $_ ) if $#S>0 ;
101 }
102 if( $Add )
103 {
104 @S = split m/\|/,$Add,2 ;
105 $Node->addAttr( split $SO,( $#S>0?$S[$cond]:$Add ) ) ;
106 }
107 $Node->process() ; #kein insert da dann uHTML-Tags nicht berücksichtigt werden
108 $Node->trailer( '' ) ; #process hat den Anhang bereits angefügt
109 }
110  
111 sub VarChoice( $ )
112 {
113 my( $Node,$Par,$Var,$cond,$true,$false ) = @_ ;
114 return( eval $cond ? $true : $false ) ;
115 }
116  
117 sub CondAttr
118 {
119 my $Node = shift ;
120 my $Name = $Node->attr( 'tag' ) ;
121  
122 return unless $Name ;
123 $Node->name( $Name ) ;
124 $Node->deleteAttr( 'tag' ) ;
125 $Node->attr( $_ ) ne '' or $Node->deleteAttr( $_ ) foreach keys %{$Node->attributes()} ;
126 $Node->map( '','' ) ;
127 }
128  
129 sub Identity( $ )
130 {
131 my $Node = shift ;
132  
133 return $_[1] if shift ;
134 $Node->map( '','' ) ;
135 }
136  
137 sub InsertText( $ )
138 {
139 my $Node = shift ;
140  
141 return uHTML::recode( $_[1],$Node->{'ENV'} ) if shift ;
142 $Node->testAttr( 'raw' ) ? $Node->HTML( $Node->attr( 'text' ) ) : $Node->map( $Node->attr( 'text' ),'' ) ;
143 }
144  
145 sub ReplaceText
146 {
147 my( $Node,$Par,$Var,$Text,$Pattern,$Replace,$opt ) = @_ ;
148  
149 unless( $Par )
150 {
151 $Text = $Node->attr( 'text' ) ;
152 $Pattern = $Node->attr( 'pattern' ) ;
153 $Replace = $Node->attr( 'replace' ) ;
154 $opt = $Node->attr( 'options' ) ;
155 }
156 $Pattern =~ s"(?<!\\)/"\\/"g ;
157 $Replace =~ s"(?<!\\)/"\\/"g ;
158 $opt =~ s"[^msixpgcadlu]""g ;
159 eval( "\$Text =~ s/$Pattern/$Replace/$opt" ) ;
160 return $Text ;
161 }
162  
163 sub uFilePath( $$ )
164 {
165 my( $IFile,$env ) = @_ ;
166 $env = \%ENV unless ref $env eq 'HASH' ;
167  
168 return( $IFile=~s/^#// ? ( $env->{'DATA_ROOT'} && $IFile !~ m%^/% ? "$env->{'DATA_ROOT'}/$IFile" : $IFile ) :
169 ( $env->{'DOCUMENT_ROOT'}.(($IFile=~m%^/%) ? '' : ($env->{'PATH_INFO'}=~m%^(.*/)[^/]*$%)[0] ). $IFile ) ) ;
170 }
171  
172 sub getFilePath
173 {
174 return uFilePath( $_[1] ? $_[3] : $_[0]->attr('path'),$_[0]->env() ) ;
175 }
176  
177 sub Include( $ )
178 {
179 my $Node = shift ;
180 my $env = $Node->{'ENV'} ;
181  
182 return if $Node->testAttr( 'cond' ) and not eval( $Node->attr( 'cond' ) ) ;
183  
184 my( $FH,$FN,$IFile,@Files,@Text ) ;
185  
186 push @Files,$IFile if $Node->testAttr( 'file' ) and $IFile = uFilePath( $Node->attr( 'file' ),$env ) and -f $IFile ;
187 push @Files,grep -f,glob( uFilePath( $IFile,$env ) ) if $Node->testAttr( 'files' ) and $IFile = $Node->attr( 'files' ) ;
188 @Files = grep -f,glob( uFilePath( $IFile,$env ) ) if not @Files and $IFile = $Node->attr( 'alt' ) ;
189  
190  
191 if( @Files )
192 {
193 foreach $FN( @Files )
194 {
195 if( -f $FN and open $FH,$FN )
196 {
197 local $_ ;
198  
199  
200 if( $Node->testAttr( 'raw' ) )
201 {
202 push @Text,<$FH> ;
203 }
204 else
205 {
206 my( $FT,$HT ) ;
207  
208 uHTML::fileStart( $FN ) ;
209 read $FH,$FT,-s $FH ;
210 $HT = uHTML::recodedList( $FT,$env ) ;
211 push @Text,@{$HT} ;
212  
213  
214 uHTML::fileEnd() ;
215 }
216 }
217 else
218 {
219 $Node->errorMsg( "Include: File \"$FN\" not readable." ) if $Node->testAttr( 'warn' ) ;
220 }
221 }
222 $Node->HTML( @Text ) ;
223 }
224 else
225 {
226 $Node->errorMsg( "Include: File \"$IFile\" not found." ) if $Node->testAttr( 'warn' ) ;
227 }
228 }
229  
230 sub VarInclude()
231 {
232 my( $Node,$Par,$Var,$IFile,$alt,$raw ) = @_ ;
233 return '' unless $IFile ;
234  
235 my( $FH,$FN,@Files,@Text ) ;
236 my $env = $Node->{'ENV'} ;
237  
238 if( @Files = grep -f,glob( uFilePath( $IFile,$env ) ) )
239 {
240 foreach $FN( @Files )
241 {
242 if( -f $FN and open $FH,$FN )
243 {
244 local $_ ;
245  
246 if( $raw )
247 {
248 push @Text,<$FH> ;
249 }
250 else
251 {
252 my( $FT,$HT ) ;
253  
254 uHTML::fileStart( $FN ) ;
255 read $FH,$FT,-s $FH ;
256 $HT = uHTML::recodedList( $FT,$env ) ;
257 push @Text,@{$HT} ;
258 uHTML::fileEnd() ;
259 }
260 }
261 }
262 return join( '',@Text ) ;
263 }
264  
265 return $alt ;
266  
267 }
268  
269  
270 sub _getDefine( $$ )
271 {
272 my( $env,$Name ) = @_ ;
273  
274 return $env->{'uHTML.Defines'}->{$Name} if ref $env->{'uHTML.Defines'} eq 'HASH' ;
275  
276 my %Defines ;
277 $env->{'uHTML.Defines'} = \%Defines ;
278 return undef ;
279 }
280  
281 sub _testDefine( $$ )
282 {
283 my $D = _getDefine( $_[0],$_[1] ) ;
284 return( ref $D eq 'ARRAY' and @{$D} and $D->[0] ne '' ) ;
285 }
286  
287 sub _Replace( $$$ )
288 {
289 my( $Node,$Par,$Var ) = @_ ;
290 $Var = $Node->name() unless $Par ;
291 my $D = _getDefine( $Node->{'ENV'},$Var ) ;
292  
293  
294 return( ref $D eq 'ARRAY' ? join '',uHTML::recode( $D->[0],$Node->{'ENV'} ) : '' ) ;
295 }
296  
297 sub Define( $ )
298 {
299 my $Node = shift ;
300 my $env = $Node->{'ENV'} ;
301 my $def ;
302  
303 return unless $Node->attributes() ;
304 if( $Node->testAttr( 'createonly' ) and not $Node->rawAttr( 'createonly' ) )
305 {
306 foreach $def( keys %{$Node->attributes()} )
307 {
308 next if $def eq 'createonly' or _testDefine( $env,$def ) ;
309 uHTML::register( $def,\&_Replace,1 ) ;
310 $env->{'uHTML.Defines'}->{$def}->[0] = $Node->attr( $def ) ;
311 }
312 }
313 elsif( $Node->testAttr( 'replace' ) and not $Node->rawAttr( 'replace' ) )
314 {
315 foreach $def( keys %{$Node->attributes()} )
316 {
317 next if $def eq 'replace' ;
318 uHTML::register( $def,\&_Replace,1 ) unless _testDefine( $env,$def ) ;
319 $env->{'uHTML.Defines'}->{$def}->[0] = $Node->attr( $def ) ;
320 }
321 }
322 else
323 {
324 foreach $def( keys %{$Node->attributes()} )
325 {
326 my $v = $Node->codeAttr( $def ) ;
327 uHTML::register( $def,\&_Replace,1 ) unless _testDefine( $env,$def ) ;
328 unshift @{$env->{'uHTML.Defines'}->{$def}},$Node->attr( $def ) ;
329 }
330 }
331 }
332  
333 sub ClearDef( $ )
334 {
335 my $Node = shift ;
336  
337 return unless $Node->attributes() ;
338 foreach( keys %{$Node->attributes()} )
339 {
340 my $D = _getDefine( $Node->{'ENV'},$_ ) ;
341 next unless ref $D eq 'ARRAY' and @{$D} ;
342 shift @{$D} ;
343 uHTML::register( $_,undef,1 ) unless @{$D} ;
344 }
345 }
346  
347 sub Alternative
348 {
349 my $Node = shift ;
350 my $Par = shift ;
351 my $Var = shift ;
352 my $Cnt = $Node->ParamCount() ;
353 my $Val ;
354  
355 $Val = shift and return $Val while $Cnt-- ;
356  
357 return '' ;
358 }
359  
360 sub AltText
361 {
362 my $Node = shift ;
363 my $Par = shift ;
364 my $Var = shift ;
365 my $Cnt = $Node->ParamCount() ;
366 my $Val ;
367  
368 ($Val = shift) ne '' and return $Val while $Cnt-- ;
369  
370 return '' ;
371 }
372  
373 sub _checkMacro( $$ )
374 {
375 my( $env,$Name ) = @_ ;
376  
377 return undef unless $Name and ref $env eq 'HASH' ;
378  
379 if( ref $env->{'uHTML.Macros'} ne 'HASH' )
380 {
381 #
382  
383 my( %Macros,%MacroVal,%MacroHTML,%MacroBody ) ;
384 $env->{'uHTML.Macros'} = \%Macros ; #$MACROS{$env->{'HTTP_HOST'}}->{'Macros'} ;
385 $env->{'uHTML.MacroVal'} = \%MacroVal ; #$MACROS{$env->{'HTTP_HOST'}}->{'MacroVal'} ;
386 $env->{'uHTML.MacroHTML'} = \%MacroHTML ;#$MACROS{$env->{'HTTP_HOST'}}->{'MacroHTML'} ;
387 $env->{'uHTML.MacroBody'} = \%MacroBody ;#$MACROS{$env->{'HTTP_HOST'}}->{'MacroBody'} ;
388 }
389  
390  
391 return $env->{'uHTML.Macros'}->{$Name} ;
392 }
393  
394 sub _getMacroValue()
395 {
396 my $Node = shift ;
397 my $Par = shift ;
398 my $Name = shift ;
399 my $Cnt = scalar @_ ;
400 my $env = $Node->{'ENV'} ;
401 my $M = _checkMacro( $env,$Name ) ;
402  
403 return '' unless $M and ref $M eq 'uHTMLnode' ;
404 return $env->{'uHTML.MacroHTML'}->{$Name} if exists $env->{'uHTML.MacroHTML'}->{$Name} ;
405 my $Macro = $M->copy ;
406 if( $Cnt and ref $env->{'uHTML.MacroAttr'}->{$Name} eq 'ARRAY' )
407 {
408 my( $attr,$val ) ;
409 $env->{'uHTML.MacroVal'}->{$Name}->{$a} = $b ;
410 foreach $attr( @{$env->{'uHTML.MacroAttr'}->{$Name}} )
411 {
412 $val = $Cnt-- > 0 ? shift : $env->{'uHTML.MacroVal'}->{$Name}->{$attr} ;
413 uHTML::register( $attr,\&_Replace,1 ) unless _testDefine( $env,$attr ) ;
414 unshift @{$env->{'uHTML.Defines'}->{$attr}},$val ;
415 }
416 $Macro->map( '','' ) ;
417 shift @{$env->{'uHTML.Defines'}->{$_}} foreach @{$env->{'uHTML.MacroAttr'}->{$Name}} ;
418 }
419 else
420 {
421 $Macro->map( '','' ) ;
422 }
423 return( $env->{'uHTML.MacroHTML'}->{$Name} = $Macro->HTML() ) ;
424 }
425  
426 sub _DoMacro( $ )
427 {
428 my $Node = shift ;
429 my $env = $Node->{'ENV'} ;
430 my $Name = $Node->name() ;
431 my $Macro ;
432  
433 return unless my $M = _checkMacro( $env,$Name ) ;
434  
435 $Node->map( '','' ) ;
436 $Macro = $M->copy() ;
437  
438 foreach( keys %{$env->{'uHTML.MacroVal'}->{$Name}} ) { $Node->setAttr( $_,$env->{'uHTML.MacroVal'}->{$Name}->{$_} ) unless $Node->testAttr( $_ ) }
439 $Node->deleteAttr( 'createonly','replace' ) ;
440 Define( $Node ) ;
441 $Macro->map( '','' ) ;
442 ClearDef( $Node ) ;
443  
444  
445  
446 # else
447  
448 if( $env->{'uHTML.MacroBody'}->{$Name} )
449 {
450 my( $H,$T ) = split m/<MacroBody>/s,$Macro->HTML(),2 ;
451 $T =~ s/<MacroBody>//sg ;
452 $Node->HTML( $H . $Node->HTML() . $T ) ;
453 }
454 else
455 {
456 $Node->HTML( $Macro->HTML() ) ;
457 # $Node->HTML( $Macro->HTML() . $Node->HTML() ) ; # Orig Version !!!!!
458 }
459 }
460  
461 sub _findMacroBody
462 {
463 my $Node = shift ;
464  
465 return undef unless $Node->firstChild() ;
466  
467 my( $Child,$Body ) ;
468  
469 for( $Child = $Node->firstChild() ; $Child ; $Child=$Child->next() )
470 {
471 return $Child if $Child->name() eq 'MacroBody' ;
472 return $Body if $Body = _findMacroBody( $Child ) ;
473 }
474 return undef ;
475 }
476  
477 sub Macro( $ )
478 {
479 my $Node = shift ;
480 my $env = $Node->{'ENV'} ;
481 my $Replace ;
482 my $Name ;
483  
484 return unless $Node->end() and $Name = $Node->attr( 'name' ) ;
485 return if $Replace = _checkMacro( $env,$Name ) and not $Node->testAttr( 'replace' ) ;
486 $env->{'uHTML.MacroBody'}->{$Name} = _findMacroBody( $env->{'uHTML.Macros'}->{$Name} = $Node ) ;
487 if( $Node->testAttr( 'attributes' ) )
488 {
489 my( $a,$b,$t,$v,@A ) ;
490 my @AT = split $SO,$Node->attr( 'attributes' ) ;
491 while( @AT )
492 {
493 $b = '' ;
494 $v = shift @AT ;
495 ( $a,$b ) = ($v =~ m/([^\=\s]+)(?:\s*\=\s*(\S.*))?/) ;
496 if( $b and $b =~ s/^(["'])// )
497 {
498 $t = $1 ;
499 $b .= shift @AT unless $b =~ s/$t$// or not @AT ;
500 }
501 $env->{'uHTML.MacroVal'}->{$Name}->{$a} = $b ;
502 push @A,$a ;
503 }
504 $env->{'uHTML.MacroAttr'}->{$Name} = \@A ;
505 }
506 return if $Replace ;
507 uHTML::registerTag( $Name,\&_DoMacro,1 ) ;
508 uHTML::registerVar( $Name,\&_getMacroValue,1 ) ;
509 }
510  
511 sub DefinedVar
512 {
513 my( $Node,$Par,$Var,$Name ) = @_ ;
514 my $env = $Node->{'ENV'} ;
515 return( $Name ne '' && ( _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ) ? 1 : 0 ) ;
516 }
517  
518 sub DefinedTag
519 {
520 my $Node = shift ;
521 my $env = $Node->{'ENV'} ;
522 my $Attr = $Node->attributes ;
523  
524 if( ref $Attr eq 'HASH' )
525 {
526 my $Name = $Attr->{'name'} ;
527 _testDefine( $env,$_ ) || _checkMacro( $env,$_ ) || $_ eq 'name' && $Name ne '' or return foreach keys %{$Attr} ;
528 return if $Name ne '' and not _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ;
529 }
530 $Node->map( '','' ) ;
531 }
532  
533 sub NotDefinedVar
534 {
535 my( $Node,$Par,$Var,$Name ) = @_ ;
536 my $env = $Node->{'ENV'} ;
537  
538 return( $Name ne '' && ( _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ) ? 0 : 1 ) ;
539 }
540  
541 sub NotDefinedTag
542 {
543 my $Node = shift ;
544 my $env = $Node->{'ENV'} ;
545 my $Attr = $Node->attributes ;
546  
547 if( ref $Attr eq 'HASH' )
548 {
549 my $Name = exists $Attr->{'name'} ? $Attr->{'name'} : '' ;
550 _testDefine( $env,$_ ) || _checkMacro( $env,$_ ) || $_ eq 'name' && $Name eq '' and return foreach keys %{$Attr} ;
551 return if $Name ne '' and _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ;
552 }
553 $Node->map( '','' ) ;
554 }
555  
556 sub _filterNode
557 {
558 my( $Node,$R ) = @_ ;
559  
560 $Node->{Text} =~ s/$R//gs ;
561 $Node->{Trailer} =~ s/$R//gs ;
562  
563 for( my $Child = $Node->{FirstChild} ; $Child ; $Child = $Child->{Next} )
564 {
565 _filterNode( $Child,$R ) ;
566 }
567 }
568  
569 sub skipLF
570 {
571 my $Node = shift ;
572  
573 my $R = $Node->testAttr( 'keepspaces' ) ? qr/\n/ :
574 $Node->testAttr( 'allspaces' ) ? qr/(?:\s*\n\s*)+/ : qr/\n\s*/ ;
575 _filterNode( $Node,$R ) ;
576 if( $R = $Node->attr( 'tag' ) )
577 {
578 $Node->name( $R ) ;
579 $Node->deleteAttr( 'keepspaces','allspaces','tag' ) ;
580 $Node->insert() ;
581 return ;
582 }
583 $Node->map( '','' ) ;
584 }
585  
586 sub skipSpaces
587 {
588 my $Node = shift ;
589  
590 my $R = qr/^\s*|\s*$/ ;
591 _filterNode( $Node,$R ) ;
592 if( $R = $Node->attr( 'tag' ) )
593 {
594 $Node->name( $R ) ;
595 $Node->deleteAttr( 'tag' ) ;
596 $Node->insert() ;
597 return ;
598 }
599 $Node->map( '','' ) ;
600 }
601  
602 sub ForEachVal
603 {
604 return $_[0]->{'ENV'}->{'ForEachValue'} ;
605 }
606  
607 sub ForEachCnt
608 {
609 return $_[0]->{'ENV'}->{'ForEachCount'} ;
610 }
611  
612 sub ForEachNum
613 {
614 return $_[0]->{'ENV'}->{'ForEachCount'}+1 ;
615 }
616  
617 sub Repeat( $ )
618 {
619 my $Node = shift ;
620 my $env = $Node->{'ENV'} ;
621 my $FEC = $env->{'ForEachCount'} ;
622 my $FEV = $env->{'ForEachValue'} ;
623 my $JOIN = $Node->testAttr( 'joint' ) ? $Node->attr( 'joint' ) : $Node->attr( 'join' ) ;
624 my $SKIP = not $Node->testAttr( 'skipempty' ) ;
625 my( $SEP,$NC,$code,$S,$E,$I,$C,$F,$n,$i,@List ) ;
626  
627 if( $Node->testAttr( 'list' ) )
628 {
629 $SEP = $Node->testAttr( 'separator' ) ? ($SEP=$Node->attr( 'separator' ),qr/$SEP/) : $RO ;
630 @List = split $SEP,$Node->attr( 'list' ) ;
631 @List = sort @List if $Node->testAttr( 'sort' ) or $Node->testAttr( 'uniq' ) ;
632 @List = uniq @List if $Node->testAttr( 'uniq' ) ;
633 $C = $Node->testAttr( 'count' ) ? int( $Node->attr( 'count' ) ) : scalar @List ;
634 $F = $Node->testAttr( 'from' ) ? int( $Node->attr( 'from' ) ) - 1 : 0 ;
635 for( $env->{'ForEachCount'}=0; $env->{'ForEachCount'}<$C; $env->{'ForEachCount'}++ )
636 {
637 $env->{'ForEachValue'} = $List[$env->{'ForEachCount'}] ;
638 $NC = $Node->copy ;
639 $NC->map( '','' ) ;
640 next unless ($n = $NC->HTML()) or $SKIP ;
641 $code .= $JOIN if $code ;
642 $code .= $n ;
643 }
644 }
645 elsif( $Node->testAttr( 'to' ) or $Node->testAttr( 'count' ) )
646 {
647 $S = int( $Node->testAttr( 'from' ) ? $Node->attr( 'from' ) : 1 ) ;
648 $I = int( $Node->attr( 'step' ) ) ;
649 $I = 1 unless $I ;
650 $C = int( $Node->attr( 'count' ) ) ;
651 $E = int( $Node->testAttr( 'to' ) ? $Node->attr( 'to' ) : $C*$I+$S ) ;
652 if( $I != 0 and ($E-$S)*$I>=0 )
653 {
654 $n = int(($E-$S)/$I + 1) ;
655 $C = $n if $C <= 0 or $n > 0 and $n < $C ;
656  
657 $env->{'ForEachCount'} = 0 ;
658 for( $env->{'ForEachValue'}=$S; $C-- > 0; $env->{'ForEachValue'}+=$I )
659 {
660 $NC = $Node->copy ;
661 $NC->map( '','' ) ;
662 if( $SKIP or $NC->HTML() )
663 {
664 $code .= $JOIN if $code ;
665 $code .= $NC->HTML() ;
666 }
667 $env->{'ForEachCount'}++ ;
668 }
669 }
670 }
671 $env->{'ForEachCount'} = $FEC ;
672 $env->{'ForEachValue'} = $FEV ;
673 $Node->HTML( $code ) ;
674 }
675  
676 sub getListElement
677 {
678 my( $Node,$Par,$Var,$List,$nr,$SEP ) = @_ ;
679  
680 unless( $Par )
681 {
682 $List = $Node->attr( 'list' ) ;
683 $nr = $Node->attr( 'nr' ) ;
684 $SEP = $Node->attr( 'separator' ) ;
685 }
686 return '' unless $List and $nr > 0 ;
687 $SEP = $SEP ? qr/$SEP/ : $RO ;
688 my @L = split $SEP,$List ;
689 return '' if --$nr > $#L ;
690 return $L[$nr] ;
691 }
692  
693 sub useScript
694 {
695 my( $Node,$Par,$Var,$Path,$error ) = @_ ;
696 my( @E,$p,@P ) ;
697  
698 if( $Par )
699 {
700 @P = split( $SO,$Path ) ;
701 }
702 else
703 {
704 foreach( 'path','script','module','modules','dir' )
705 {
706 push @P,map uFilePath( $_,$Node->env() ),split $SO,$Node->attr( $_ ) if $Node->testAttr( $_ ) ;
707 }
708 push @P,split $SO,$Node->attr( 'use' ) if $Node->testAttr( 'use' ) ;
709 map { require "uHTML/$_.pm" } split $SO,$Node->attr( 'uHTML' ) if $Node->testAttr( 'uHTML' ) ;
710 }
711  
712 if( @P )
713 {
714 foreach $p( @P )
715 {
716 if( -d $p )
717 {
718 if( opendir DH,$p )
719 {
720 foreach( grep m/\.pm$/,readdir DH )
721 {
722 -r "$p/$_" ? { require "$p/$_" } : push @E,"$p/$_" ;
723 }
724 }
725 else
726 {
727 push @E,$p ;
728 }
729 }
730 elsif( -r $p )
731 {
732 require $p ;
733 }
734 else
735 {
736 require $p
737 }
738 }
739 }
740  
741 return '' ;
742 }
743  
744 sub getENV
745 {
746 my $N = $_[1] ? $_[3] : $_[0]->attr('name') ;
747 return( $N ? $_[0]->{ENV}->{$N} : '' ) ;
748 }
749  
750  
751 sub ENVkeys
752 {
753 my $S = $_[1] ? $_[4] : $_[0]->attr('separator') ;
754 $S = ',' unless $S ;
755 return join( $S, sort keys %{$_[0]->{ENV}} ) if $_[1] ? $_[3] : $_[0]->testAttr('sort') ;
756 return join( $S, keys %{$_[0]->{ENV}} ) ;
757 }
758  
759 uHTML::registerTag( 'if',\&DoIf ) ;
760 uHTML::registerTag( 'choice',\&Choice ) ;
761 uHTML::registerVar( 'choice',\&VarChoice ) ;
762 uHTML::registerTag( 'CondAttr',\&CondAttr ) ;
763 uHTML::registerTag( 'include',\&Include ) ;
764 uHTML::registerVar( 'include',\&VarInclude ) ;
765 uHTML::registerTag( 'insert',\&InsertText ) ;
766 uHTML::registerVar( 'uHTMLtoHTML',\&InsertText ) ;
767 uHTML::registerTag( 'define',\&Define ) ;
768 uHTML::registerTag( 'undef',\&ClearDef ) ;
769 uHTML::registerVar( 'defined',\&DefinedVar ) ;
770 uHTML::registerTag( 'defined',\&DefinedTag ) ;
771 uHTML::registerVar( 'notdefined',\&NotDefinedVar ) ;
772 uHTML::registerTag( 'notdefined',\&NotDefinedTag ) ;
773 uHTML::registerVar( 'Alternative',\&Alternative ) ;
774 uHTML::registerVar( 'AltText',\&AltText ) ;
775 uHTML::registerTag( 'macro',\&Macro ) ;
776 uHTML::registerTag( 'identity',\&Identity ) ;
777 uHTML::registerVar( 'identity',\&Identity ) ;
778 uHTML::registerTag( 'skipLF',\&skipLF ) ;
779 uHTML::registerTag( 'skipSpaces',\&skipSpaces ) ;
780 uHTML::register( 'ENV',\&getENV ) ;
781 uHTML::register( 'ENVkeys',\&ENVkeys ) ;
782 uHTML::register( 'replace',\&ReplaceText ) ;
783 uHTML::register( 'RepeatNum',\&ForEachNum ) ;
784 uHTML::register( 'RepeatCount',\&ForEachCnt ) ;
785 uHTML::register( 'RepeatValue',\&ForEachVal ) ;
786 uHTML::registerTag( 'repeat',\&Repeat ) ;
787 uHTML::registerTag( 'Repeat',\&Repeat ) ;
788 uHTML::register( 'uFilePath',\&getFilePath ) ;
789 uHTML::register( 'ListElement',\&getListElement ) ;
790 uHTML::register( 'Modules',\&useScript ) ;
791 uHTML::register( 'Module',\&useScript ) ;
792 uHTML::register( 'uModule',\&useScript ) ;
793  
794  
795  
796 ######################################
797 ######################################
798  
799 =pod
800  
801 =encoding UTF-8
802  
803 =head1 NAME
804  
805 =over 2
806  
807 =item B<uHTML::std> - standard B<HTML> tags
808  
809 =for comment =item B<uHTMLnode> - central B<uHTML> data structure
810  
811 =back
812  
813 =head1 VERSION
814  
815 Version 2.21
816  
817 =head1 DESCRIPTION
818  
819 Standard tags and functions are the most used uHTML tags and functions - think I<std.h> in B<C>.
820 They are used in nearly every B<uHTML> project. It brings programming capabilities directly
821 into the B<uHTML>-files and addresses rather the programmer than the designer, although most
822 designers value especially the tags B<include> and B<define> which use is quite obvious for them.
823 The tags B<if>/B<else>, B<choice>, B<repeat> and B<macro> are usually utilized with support
824 of the programmer. Due their compliance with the standard B<HTML>-syntax designers do not
825 hesitate to alter them without help of the programmer. While doing that the designer seldom
826 incorporate errors into the B<uHTML> file as the tags program code is not affected and
827 a faulty result can be noticed by the designer immediately.
828  
829 =head1 REQUIREMENTS
830  
831 This std library do not require any other libraries but the main B<uHTML> library.
832  
833 =head1 uHTML tags provided by the std library
834  
835 B< >
836  
837 =head2 include
838  
839 =head3 Overview
840  
841 The include tag includes the content of a uHTML file into another uHTML-file.
842 It is intended to move constant parts of the website files like header lines,
843 menus, footers, etc. into one file and save thereby development and maintenance
844 time ans as well reduce probability of random mistakes.
845  
846 =head3 Conventions
847  
848 Path names beginning with '/' are considered as relative to DOCUMENT_ROOT.
849 Path names not beginning with '/' and not prefixed with '#' are considered as
850 relative to the path of the current file. Path names prefixed with '#' are considered
851 as file system absolute if a '/' follows the '#' and relative to DATA_ROOT
852 (or the script directory) if no '/' follows the '#'.
853  
854 =head3 Attributes
855  
856 =head4 file="FILEPATH"
857  
858 The attribute file defines the path and name of the included file.
859  
860 =head4 files="FILEPATH"
861  
862 The attribute files defines the path and name of the included file whereby wildcards *
863 and ? are expanded according to glob rules and the included files get concatenated.
864  
865 =head4 alt="FILEPATH"
866  
867 In case no file defined by the file or files attributes is found, the file defined by
868 the alt attribute get included whereby wildcards * and ? are expanded according to
869 glob rules and the included files get concatenated.
870  
871 =head4 raw
872  
873 The attribute raw without value prevents the interpretation of uHTML-elements in the
874 included file. It should be used if files without uHTML-elements get included.
875  
876 =head4 nowarn
877  
878 The attribute nowarn without value prevents error messages in case the included file
879 isn't found or is not readable.
880  
881 =head4 cond="clause"
882  
883 The cond attribute is optional. If present, then the include tag is executed only if
884 the clause in the attribute cond evaluates 'true'.
885  
886 =head3 Example
887  
888 <include file="/include/navigation" >
889  
890 =head2 define
891  
892 =head3 Overview
893  
894 The define tag defines new uHTML tags and variables assigning to each constant content
895 which isn't interpreted as uHTML. It helps to shorten source files abbreviating frequently
896 used code sequences. At the same time it reduces the risk of random errors while copying
897 of the same content across the site's source files. It is possible to define several tags
898 and variables within one define tag. It is advisable to use the include-tag to collect
899 definitions used in the whole site in one file.
900  
901 =head3 Conventions
902  
903 Previous definitions with the same name are saved and get recovered when a definition
904 done with define get revoked with undef unless the definition is done with the attribute replace.
905  
906 =head3 Attributes
907  
908 =head4 createonly
909  
910 If a attribute createonly without any value is supplied,
911 only new definitions will be regarded. Existing definitions will be skipped.
912  
913 =head4 replace
914  
915 If a attribute replace without any value is supplied,
916 the last definition of a tag and variable will be replaced not recoverable by undef.
917  
918 =head3 Example
919  
920 =head4 Definition:
921  
922 E<lt>define uHTML='E<lt>span style="font-family:serif;color:#34a;"E<gt>
923 E<lt>span style="font-weight:bold;color:#fe6f02; font-size:0.8em"E<gt>UE<lt>/span>HTMLE<lt>/spanE<gt>'
924 bluestyle="color:blue;font-weight:bold;"E<gt>
925  
926 =head4 Use:
927  
928 <uHTML> <span style="$bluestyle"> is exciting </span>
929  
930 =head2 undef
931  
932 =head3 Overview
933  
934 The undef tag revokes definitions done with define. It recovers the previous definition if it exists.
935  
936 =head3 Example
937  
938 <undef uHTML bluestyle>
939  
940 =head2 macro
941  
942 =head3 Overview
943  
944 The macro tag allows to define complex new tags with own attributes within a uHTML file.
945 The uHTML-code within the tag defined with the macro tag is interpreted.
946 Definitions done with macro cannot be revoked like it can be done with definitions
947 done with define, but they can be replaced if the replace attribute
948 is supplied with the new definition.
949  
950 Macros without own parameters can be used as variables in attributes.
951  
952 =head3 Special Tag
953  
954 =head4 <MacroBody>
955  
956 The optional MacroBody tag within a macro definition marks the position of
957 the body when the macro is deployed as a closed tag. If the macro is deployed
958 as a not closed tag, MacroBody is ignored.
959  
960 =head3 Attributes
961  
962 =head4 name="MacroName"
963  
964 The attribute name defines the name of the macro.
965  
966 =head4 attributes="AttributeList"
967  
968 The attribute attributes defines the valid attributes of the defined macro.
969 The attributes of the macro are given in a comma separated list.
970 It is possible to define default values for the macro attributes.
971 Those default values are separated by a '=' from the attribute name.
972 Leading and trailing spaces are ignored unless the value is included
973 in single or double quotation marks. The value must not contain any comma.
974  
975 =head4 replace
976  
977 The attribute replace forces the replacement of a former macro definition
978 with the same name. Without the attribute replace the definition get ignored
979 if a macro with the same name exists.
980  
981 =head3 Example
982  
983 =head4 Definition:
984  
985 <macro name="Label" attributes="text">
986 <div class="toplabel"><text></div>
987 </macro>
988  
989 =head4 Use:
990  
991 <Label text="Home">
992  
993 =head4 Definition:
994  
995 <macro name="Box" attributes="color,background=white">
996 <div class="boxclass" style="color:$color;background-color:$background">
997 <MacroBody>
998 </div>
999 </macro>
1000  
1001 =head4 Use:
1002  
1003 <Box color="blue" background="#e3fff6">Boxtext</Box>
1004  
1005 =head2 defined
1006  
1007 =head3 Overview
1008  
1009 The defined tag content is included in the uHTML output if all attributes
1010 without a value equal to a name defined with define or macro or if the value
1011 of the attribute name contains a name defined either with define or with macro.
1012  
1013 =head3 Attributes
1014  
1015 =head4 name="name"
1016  
1017 The name of the define or macro which should be tested for existence.
1018  
1019 =head3 Example
1020  
1021 <defined name="Count">
1022 <Count>
1023 </defined>
1024  
1025 =head2 notdefined
1026  
1027 =head3 Overview
1028  
1029 The notdefined tag content is included in the uHTML output if none
1030 of the attributes without a value equals to a name defined with define
1031 or macro or if the value of the attribute name do not contains a name
1032 defined either with define or with macro.
1033  
1034 =head3 Attributes
1035  
1036 =head4 name="name"
1037  
1038 The name of the define or macro which should be tested for existence.
1039  
1040 =head3 Example
1041  
1042 <notdefined name="bluestyle">
1043 <define bluestyle="color:blue;font-weight:bold;">
1044 </notdefined>
1045  
1046 =head2 if
1047  
1048 =head3 Overview
1049  
1050 The tag if allows conditional content.
1051 It usually contains one ore more else tags which enclose alternative content.
1052  
1053 =head3 Attributes
1054  
1055 =head4 cond="clause"
1056  
1057 The clause in the attribute cond decides if the content of the if tag
1058 is processed and passed to the http client. It is interpreted as a perl expression.
1059 It is true if the result is not 0 or it contains a string with a non-zero length.
1060 In the latter case the string need to be enclosed in quotation marks within
1061 the quotation marks of the attribute value.
1062  
1063 If the attribute content evaluates 'true' the content of the tag
1064 is processed and passed on while the content of subordinated else-tags is ignored.
1065 In opposite case the tag content is discarded while the else tags get evaluated.
1066  
1067 =head3 Example
1068  
1069 <if cond="$File ne 'index.uhtml'">
1070 <a href="/index.uhtml">Home</a>
1071 </if>
1072  
1073 =head2 else
1074  
1075 =head3 Overview
1076  
1077 The tag else used within a if tag defines alternative content.
1078 If it contains the attribute cond, it's content get only processed and passed on
1079 if the clause in the attribute cond evaluates 'true'. In this case all other
1080 else tags within the parental if tag get discarded along with the content of the if tag.
1081  
1082 =head3 Attributes
1083  
1084 =head4 cond="clause"
1085  
1086 The clause in the attribute cond decides if the content of the else tag is processed
1087 and passed to the http client. It is interpreted as a perl expression.
1088 It is true if the result is not 0 or it contains a string with a non-zero length.
1089 In the latter case the string need to be enclosed in quotation marks within the
1090 quotation marks of the attribute value.
1091  
1092 If the attribute content evaluates 'true' the content of the tag is processed
1093 and passed on while the content of all other else tags within the parental
1094 if tags get discarded along with the content of the if tag.
1095  
1096 =head3 Example
1097  
1098 <if cond="$File ne 'index.uhtml'">
1099 <a href="/index.uhtml">Home</a>
1100 <else><img src="spacer.png" alt="placeholder"></else>
1101 </if>
1102  
1103 =head2 choice
1104  
1105 =head3 Overview
1106  
1107 The deployment of if tags with an included else tag is always text-intensive.
1108 Sometimes just two tags or just two attribute values in some attributes of a
1109 tag make the difference. In such cases the tag choice is often the better alternative.
1110 The tag choice can be used as open or closed tag. The alternative values of the attributes
1111 need to be separated by "|". In case the clause in the attribute cond evaluates true,
1112 the value left of "|" is used, otherwise the value right of "|". If the value has a zero length, the attribute is omitted.
1113  
1114 =head3 Attributes
1115  
1116 =head4 cond="clause"
1117  
1118 The clause in the attribute cond decides if the content on the left or the content
1119 on the right side of "|" in the attribute values is used. If no "|" is found in an
1120 attributes value, the value is used independent of the condition.
1121  
1122 =head4 tag="ELEMENTNAME"
1123  
1124 The attribute tag defines the name of the tag by which choice will be replaced.
1125 It is obligatory and in case it is missing or equals to a zero length string,
1126 the whole tag is omitted. It can contain two values separated by "|" which will
1127 be used according to the result of cond.
1128  
1129 =head4 attr="AttributeList"
1130  
1131 A comma separated list of attributes without values which have to be added to the tag.
1132 Two lists separated by "|" can be defined. The lists will be used according to the result of cond.
1133  
1134 =head3 Example
1135  
1136 <choice cond="'$ENV(HTTP_USER_AGENT)' =~ m/Explorer/" tag="div" class="explorer|normal">
1137 ....Text....
1138 </choice>
1139  
1140 =head2 CondAttr
1141  
1142 =head3 Overview
1143  
1144 CondAttr drops all empty attributes. It is meant to avoid empty attributes which may confuse browsers.
1145  
1146 =head3 Attributes
1147  
1148 =head4 tag="ELEMENTNAME"
1149  
1150 The attribute tag defines the name of the tag by which CondAttr will be replaced.
1151 It is obligatory and in case it is missing or equals to a zero length string, the whole tag is omitted.
1152  
1153 =head3 Example
1154  
1155 <CondAttr tag="div" class="$SpecialClass">
1156 ....Text....
1157 </CondAttr>
1158  
1159 =head2 replace
1160  
1161 =head3 Overview
1162  
1163 The tag replace applies perl regular expressions to the text provided by the attribute
1164 text and inserts it into the HTML code. For more information on perl regular expressions,
1165 please consult the corresponding man page perlre.
1166  
1167 =head3 Attributes
1168  
1169 =head4 text="TEXT"
1170  
1171 The text to be altered.
1172  
1173 =head4 pattern="RegExPattern"
1174  
1175 Patterns of the regular expression. Notice that backslashes "\" must be escaped (doubled) "\\".
1176  
1177 =head4 replace="ReplaceText"
1178  
1179 Text that will replace pattern. Notice that "$" signs must be escaped "\$".
1180  
1181 =head4 options="OPTIONS"
1182  
1183 Replace options. For more information about possible options
1184 please consult the perl regular expressions man page perlre.
1185  
1186 =head3 Example
1187  
1188 <replace text="$include(#data/products)" pattern="," replace="<br>">
1189  
1190 =head2 skipLF
1191  
1192 =head3 Overview
1193  
1194 The tag skipLF removes line feeds and any spaces and tabs following it,
1195 speak any spaces or tabs at the beginning of a line. It helps to keep the
1196 source code readable while allowing e.g. place images adjacent.
1197 It is especially useful with the tags macro and repeat.
1198  
1199 =head3 Attributes
1200  
1201 =head4 keepspaces
1202  
1203 Remove line feeds only and keep all spaces.
1204  
1205 =head4 allspaces
1206  
1207 Remove spaces at the end of the lines as well.
1208  
1209 =head4 tag="ELEMENTNAME"
1210  
1211 If present, the attribute tag defines the name of a tag by which skipLF
1212 will be replaced. If it is missing or equals to a zero length string,
1213 the attribute is treated as not existent.
1214  
1215 =head3 Example
1216  
1217 <skipLF>
1218 <img src="/img/left.gif">
1219 <img src="/img/right.gif">
1220 </skipLF>
1221  
1222 =head2 skipSpaces
1223  
1224 =head3 Overview
1225  
1226 Within the tag skipSpaces spaces, tabs and line feeds ahead and following
1227 any tag are removed. It helps to keep the source code readable while allowing
1228 e.g. place images adjacent. It is especially useful with the tags macro and repeat.
1229  
1230 =head3 Attributes
1231  
1232 =head4 tag="ELEMENTNAME"
1233  
1234 If present, the attribute tag defines the name of a tag by which skipSpaces
1235 will be replaced. If it is missing or equals to a zero length string,
1236 the attribute is treated as not existent.
1237  
1238 =head3 Example
1239  
1240 <skipSpaces>
1241 <img src="/img/left.gif">
1242 <img src="/img/right.gif">
1243 </skipSpaces>
1244  
1245 =head2 repeat
1246  
1247 =head2 Repeat
1248  
1249 =head3 Overview
1250  
1251 The tag repeat repeats itself according to the values of it's attributes.
1252 The repeat tags can be nested. The variants repeat and Repeat are identical.
1253  
1254 =head3 Attributes
1255  
1256 =head4 list="ValueList"
1257  
1258 A list of values separated by separator. The tag repeat is repeated once for
1259 each element of the list. If list is defined, other attributes are ignored.
1260  
1261 =head4 separator="REGEX"
1262  
1263 A regular expression used to split the list. If omitted the values in list
1264 must be separated by commas, colons or semicolons surrounded by optional (ignored) spaces (\s*[,;:]\s*).
1265  
1266 =head4 sort
1267  
1268 Valid only if the list attribute is given.
1269 If present, the list will be sorted alphabetically before the execution of repeat.
1270  
1271 =head4 uniq
1272  
1273 Valid only if the list attribute is given.
1274 If present, identical adjacent values of list are ignored. if the attribute sort is given,
1275 uniq is applied on the sorted list.
1276  
1277 =head4 skipempty
1278  
1279 Valid only if the list attribute is given. If present, empty list elements are ignored.
1280  
1281 =head4 from="integer"
1282  
1283 The attribute from defines the initial value to count the iterations. If not defined it defaults to 1.
1284  
1285 If the attribute list is given, it defines the initial list element to be used. The first list element is referred by 1.
1286  
1287 =head4 step="integer"
1288  
1289 The attribute step defines the increment value for a iteration. It can have a negative value.
1290 If not defined it defaults to 1. It is ignored if the attribute list is given.
1291  
1292 =head4 to="integer"
1293  
1294 The attribute to defines the last value for a iteration.
1295 If not defined it defaults to 0. It is ignored if the attribute list is given.
1296  
1297 =head4 count="integer"
1298  
1299 The attribute to defines the count of iteration.
1300 If not defined it defaults to 0. It is ignored if to is defined and different from 0.
1301  
1302 If the attribute list is given, it defines the count of elements to be used.
1303  
1304 =head4 joint="text"
1305  
1306 Text inserted between the repetitions of repeat. It can contain HTML tags. uHTML tags and variables will be ignored.
1307  
1308 If uHTML tags and variables should get interpreted, the function $uHTMLtoHTML can be used.
1309  
1310 =head3 Example
1311  
1312 <center><repeat count="11" >#</repeat></center>
1313  
1314 =head2 RepeatCount
1315  
1316 =head3 Overview
1317  
1318 The tag RepeatCount is valid within the repeat tag. It returns the count of completed iterations of the tag repeat.
1319  
1320 =head3 Example
1321  
1322 <repeat count="20"><RepeatCount> completed<br></repeat>
1323  
1324 =head2 RepeatNum
1325  
1326 =head3 Overview
1327  
1328 The tag RepeatNum is valid within the repeat tag. It returns the number of the current iteration of the tag repeat.
1329  
1330 =head3 Example
1331  
1332 <repeat count="20">Am in iteration <RepeatNum><br></repeat>
1333  
1334 =head2 RepeatValue
1335  
1336 =head3 Overview
1337  
1338 The tag RepeatValue is valid within the repeat tag.
1339 It returns the current value associated the current iteration of the tag repeat.
1340 In case the overlying repeat tag has the attribute list, it returns the
1341 corresponding list value. Otherwise it returns the value calculated according
1342 to the attributes from and step of the overlying repeat tag.
1343  
1344 =head3 Example
1345  
1346 <repeat count="10">Line <RepeatValue><br></repeat>
1347  
1348 =head2 ListElement
1349  
1350 =head3 Overview
1351  
1352 The tag ListElement extracts an single element from a text list.
1353 It is ineffective and should be only used to occasionally extract
1354 a single list element and must be never used within a loop.
1355  
1356 =head3 Attributes
1357  
1358 =head4 list="LIST"
1359  
1360 The list from which the element hast to be extracted. If missing or empty the tag is omitted.
1361  
1362 =head4 nr="NUMBER"
1363  
1364 Number of the element to be extracted.
1365 The first element in the list has the number 1. If missing or out of range the tag is omitted.
1366  
1367 =head4 SEP="REGEX"
1368  
1369 Element separator used in the list.
1370 If omitted it defaults to commas, colons or semicolons surrounded by optional (ignored) spaces (\s*[,;:]\s*).
1371  
1372 =head3 Example
1373  
1374 <ListElement list="A, B, C" nr="2">
1375  
1376 =head2 uFilePath
1377  
1378 =head3 Overview
1379  
1380 The tag uFilePath determines the absolute path of a file according
1381 to the uHTML path name conventions. Path names beginning with '/'
1382 are considered as relative to DOCUMENT_ROOT. Path names not
1383 beginning with '/' and not prefixed with '#' are considered as
1384 relative to the path of the current file. Path names prefixed
1385 with '#' are considered as file system absolute if a '/' follows
1386 the '#' and relative to DATA_ROOT (or the script directory) if no '/' follows the '#'.
1387  
1388 =head3 Attributes
1389  
1390 =head4 path="PATH"
1391  
1392 Path to convert.
1393  
1394 =head3 Example
1395  
1396 Document Root: <uFilePath path="/">
1397  
1398 =head2 ENV
1399  
1400 =head3 Overview
1401  
1402 The tag ENV inserts the value of the environment variable name into the HTML-code.
1403  
1404 =head3 Attributes
1405  
1406 =head4 name="EnvVarName"
1407  
1408 Name of the environment variable.
1409  
1410 =head3 Example
1411  
1412 <ENV name="SERVER_NAME">
1413  
1414 =head2 ENVkeys
1415  
1416 =head3 Overview
1417  
1418 The tag ENVkeys inserts a list of all environment variables names into the HTML-code.
1419  
1420 =head3 Attributes
1421  
1422 =head4 separator="SEPARATOR"
1423  
1424 Separator between the names to be used in the list. Defaults to "," if omitted.
1425  
1426 =head4 sort
1427  
1428 If the attribute sort is present, the list is sorted.
1429  
1430 =head3 Example
1431  
1432 <ENVkeys>
1433  
1434 =head2 insert
1435  
1436 =head3 Overview
1437  
1438 The tag insert inserts the value of the attribute text into the HTML-code.
1439 The attribute raw prevents the interpretation of uHTML elements in text.
1440 This tag is used mainly for site debugging purposes.
1441  
1442 =head3 Attributes
1443  
1444 =head4 text="Text"
1445  
1446 Text inserted into HTML.
1447  
1448 = head4 raw
1449  
1450 The attribute raw prevents the interpretation of uHTML elements in text.
1451  
1452 =head3 Example
1453  
1454 <insert text="$testfunc(A,1)">
1455  
1456 =head2 identity
1457  
1458 =head3 Overview
1459  
1460 The tag identity does literal nothing. This tag is used mainly for site debugging purposes.
1461  
1462 =head3 Example
1463  
1464 <identity>Text</identity>
1465  
1466 =head2 uModule
1467  
1468 =head3 Overview
1469  
1470 The tag uModule makes perl modules (usually uHTML modules) accessible within the website.
1471  
1472 =head3 Attributes
1473  
1474 =head4 path="FileName"
1475  
1476 =head4 script="FileName"
1477  
1478 =head4 module="FileName"
1479  
1480 =head4 modules="FileName"
1481  
1482 =head4 dir="FileName"
1483  
1484 The filename of the required module. The attribute can contain several module names
1485 separated by commas. The file names are interpreted according to the uHTML file name
1486 conventions. Path names beginning with '/' are considered as relative to DOCUMENT_ROOT.
1487 Path names not beginning with '/' and not prefixed with '#' are considered as relative
1488 to the path of the current file. Path names prefixed with '#' are considered as file
1489 system absolute if a '/' follows the '#' and relative to DATA_ROOT (or the script
1490 directory) if no '/' follows the '#'.
1491  
1492 =head4 error
1493  
1494 The attribute error forces error messages in the servers log files.
1495  
1496 =head3 Example
1497  
1498 <uModule script="inc/edit/uHTML/edit.pm">
1499  
1500 B< >
1501  
1502 B< >
1503  
1504 =head1 Attribute variables and functions provided by the std library
1505  
1506 B< >
1507  
1508 =head2 $defined(name)
1509  
1510 =head3 Overview
1511  
1512 The $defined function is used mainly within the cond attribute of different tags.
1513  
1514 =head3 Parameters
1515  
1516 =head4 name
1517  
1518 The name of a definition either by define or by macro which should be tested for existence.
1519  
1520 =head3 Example
1521  
1522 <if cond="$defined(Products)">
1523 <Products>
1524 </if>
1525  
1526 =head2 $notdefined(name)
1527  
1528 =head3 Overview
1529  
1530 The $notdefined function is used mainly within the cond attribute of different tags.
1531  
1532 =head3 Parameters
1533  
1534 =head4 name
1535  
1536 The name of a definition either by define or by macro which should be tested for existence.
1537  
1538 =head3 Example
1539  
1540 <include cond="$notdefined(Products)" file="#inc/products">
1541  
1542 =head2 $choice(cond,true,false)
1543  
1544 =head3 Overview
1545  
1546 Sometimes even the tag choice is to complex to choose between two alternative values for one attribute or two different attributes of the same tag need different values depending on different conditions for each attribute. For such cases the function $choice is defined.
1547  
1548 =head3 Parameters
1549  
1550 =head4 cond
1551  
1552 Depending on the result of the clause in the parameter cond, either the value of the parameter true or the value of the parameter false is returned by the function choice.
1553  
1554 =head4 true
1555  
1556 Value returned if cond evaluates true.
1557  
1558 =head4 false
1559  
1560 Value returned if cond evaluates false.
1561  
1562 =head3 Example
1563  
1564 <div class="$choice($SiteName,std,special)">
1565  
1566 =head2 $Alternative(par1,par1,par3,…)
1567  
1568 =head3 Overview
1569  
1570 Sometimes the first true (in sense of perl) out of many values is needed.
1571 For such cases the function $Alternative is defined. $Alternative returns
1572 the first parameter which isn't an empty string or zero. To use it as a tag
1573 wrap it into the tag insert.
1574  
1575 =head3 Parameters
1576  
1577 =head4 par1,par1,par3,…
1578  
1579 The first par* parameter which isn't an empty string or zero will be returned by the function Alternative.
1580  
1581 =head3 Example
1582  
1583 <insert text="$Alternative($FormData,$Default)">
1584  
1585 =head2 $AltText(par1,par1,par3,…)
1586  
1587 =head3 Overview
1588  
1589 Sometimes the first value containing some text out of many values is needed.
1590 For such cases the function $AltText is defined. $AltText returns the first
1591 parameter which isn't an empty string. To use it as a tag wrap it into the tag insert.
1592  
1593 =head3 Parameters
1594  
1595 =head4 par1,par1,par3,…
1596  
1597 The first par* parameter which isn't an empty string will be returned by the function AltText.
1598  
1599 =head3 Example
1600  
1601 <insert text="$AltText($FormData,$Default)">
1602  
1603 =head2 $include(file,alt)
1604  
1605 =head3 Overview
1606  
1607 The function $include inserts the content of a file into a attribute.
1608 The file names are interpreted according to the uHTML file name conventions.
1609 Path names beginning with '/' are considered as relative to DOCUMENT_ROOT.
1610 Path names not beginning with '/' and not prefixed with '#' are considered
1611 as relative to the path of the current file. Path names prefixed with '#' are
1612 considered as file system absolute if a '/' follows the '#' and relative to
1613 DATA_ROOT (or the script directory) if no '/' follows the '#'.
1614  
1615 =head3 Parameters
1616  
1617 =head4 file
1618  
1619 The parameter file defines the path and name of the included file. Wildcards * and ? are expanded according to glob rules and the included files get concatenated.
1620  
1621 =head4 alt
1622  
1623 In case no file defined by the file parameter is found, the file defined by the alt parameter get included. This parameter can be omitted.
1624  
1625 =head3 Example
1626  
1627 <select name="products">
1628 <repeat list="$include(#data/products)">
1629 <option><RepeatValue></option>
1630 </repeat>
1631 </select>
1632  
1633 =head2 $replace(text,pattern,replace,options)
1634  
1635 =head3 Overview
1636  
1637 The function $replace applies perl regular expressions to the text provided
1638 by the parameter text before returning it. For more information on perl
1639 regular expressions, please consult the corresponding man page perlre.
1640  
1641 =head3 Parameters
1642  
1643 =head4 text
1644  
1645 The text to be altered.
1646  
1647 =head4 pattern
1648  
1649 Patterns of the regular expression. Notice that backslashes "\" must be escaped (doubled) "\\".
1650  
1651 =head4 replace
1652  
1653 Text that will replace pattern. Notice that "$" signs must be escaped "\$".
1654  
1655 =head4 options
1656  
1657 Replace options. For more information about possible options please consult the perl regular expressions man page perlre.
1658  
1659 =head3 Example
1660  
1661 <insert text="$replace('$include(#data/products)',',','<br>')">
1662  
1663 =head2 $RepeatCount()
1664  
1665 =head3 Overview
1666  
1667 The variable $RepeatCount is valid within the repeat tag.
1668 It returns the count of completed iterations of the tag repeat.
1669  
1670 =head3 Example
1671  
1672 <select name="weekday">
1673 <repeat list="Monday,Tuesday,Wednesday,Thursday.Friday,Saturday,Sunday">
1674 <option value="$RepeatCount"><RepeatValue></option>
1675 </repeat>
1676 </select>
1677  
1678 =head2 $RepeatNum()
1679  
1680 =head3 Overview
1681  
1682 The variable $RepeatNum is valid within the repeat tag.
1683 It returns the number of the current iteration of the tag repeat.
1684  
1685 =head3 Example
1686  
1687 <select name="weekday">
1688 <repeat list="Monday,Tuesday,Wednesday,Thursday.Friday,Saturday,Sunday">
1689 <option value="$RepeatCount"><RepeatNum>: <RepeatValue></option>
1690 </repeat>
1691 </select>
1692  
1693 =head2 $RepeatValue()
1694  
1695 =head3 Overview
1696  
1697 The variable $RepeatValue is valid within the repeat tag.
1698 It returns the current value associated the current iteration of the tag repeat,
1699 e.g. the corresponding value from the attribute list.
1700  
1701 =head3 Example
1702  
1703 <select name="weekday">
1704 <repeat list="Monday,Tuesday,Wednesday,Thursday.Friday,Saturday,Sunday">
1705 <option value="$RepeatNum"><RepeatValue></option>
1706 </repeat>
1707 </select>
1708  
1709 =head2 $ListElement(List,nr,SEP)
1710  
1711 =head3 Overview
1712  
1713 The variable $ListElement extracts an single element from a text list.
1714 It is ineffective and should be only used to occasionally extract a single
1715 list element and must be never used within a loop.
1716  
1717 =head3 Parameters
1718  
1719 =head4 list
1720  
1721 The list from which the element hast to be extracted. If empty the result is an empty string.
1722  
1723 =head4 nr
1724  
1725 Number of the element to be extracted. The first element in the list has the number 1.
1726 If missing or out of range the result is an empty string.
1727  
1728 =head4 SEP
1729  
1730 Element separator used in the list. If omitted it defaults to \s*[,;:]\s*.
1731  
1732 =head3 Example
1733  
1734 <insert text="$ListElement( 'A, B, C',2 )">
1735  
1736 =head2 $uFilePath(path)
1737  
1738 =head3 Overview
1739  
1740 The function $uFilePath determines the absolute path of a file according
1741 to the uHTML path name conventions. Path names beginning with '/' are
1742 considered as relative to DOCUMENT_ROOT. Path names not beginning with '/'
1743 and not prefixed with '#' are considered as relative to the path of the
1744 current file. Path names prefixed with '#' are considered as file system
1745 absolute if a '/' follows the '#' and relative to DATA_ROOT (or the script
1746 directory) if no '/' follows the '#'.
1747  
1748 =head3 Parameters
1749  
1750 =head4 path
1751  
1752 Path to convert.
1753  
1754 =head3 Example
1755  
1756 <if cond="-f '$uFilePath(/index.html)'"> <code>/index.html</code> exists. </if>
1757  
1758 =head2 $ENV(name)
1759  
1760 =head3 Overview
1761  
1762 The function $ENV inserts the value of the environment variable name into a attribute.
1763  
1764 =head3 Parameters
1765  
1766 =head4 name
1767  
1768 Name of the environment variable.
1769  
1770 =head3 Example
1771  
1772 <if cond="'$ENV(HTTP_VIA)'"> Request passed a proxy server. </if>
1773  
1774 =head2 $ENVkeys(sort,separator)
1775  
1776 =head3 Overview
1777  
1778 The function $ENV inserts the value of the environment variable name into a attribute.
1779  
1780 =head3 Parameters
1781  
1782 =head4 sort
1783  
1784 If true the list get sorted.
1785  
1786 =head4 separator
1787  
1788 Separator between the names to be used in the list. Defaults to "," if omitted.
1789  
1790 =head3 Example
1791  
1792 <repeat list="$ENVkeys(sort,';')">
1793 <div><RepeatValue>=<ENV name="$RepeatValue"></div>
1794 </repeat>
1795  
1796 =head2 $identity(value)
1797  
1798 =head3 Overview
1799  
1800 The function $identity does literal nothing.
1801 It just returns the unchanged parameter value. This tag is used mainly for site debugging purposes.
1802  
1803 =head3 Parameters
1804  
1805 =head4 value
1806  
1807 The parameter value defines the return value of the function $identity.
1808  
1809 =head3 Example
1810  
1811 <insert text="$identity(Text)">
1812  
1813 =head2 $uHTMLtoHTML(uHTML)
1814 ,
1815 =head3 Overview
1816  
1817 The function $uHTMLtoHTML forces a parameter to be interpreted
1818 as B<uHTML> input and be translated into B<HTML>.
1819  
1820 =head3 Parameters
1821  
1822 =head4 uHTML
1823  
1824 The parameter uHTML get translated into HTML.
1825  
1826 =head3 Example
1827  
1828 <skipLF>
1829 <repeat count="20" joint="$uHTMLtoHTML(<RecordSeparator>)">
1830 <Record num="$RepeatCount">
1831 </repeat>
1832 </skipLF>
1833  
1834 B< >
1835  
1836 B< >
1837  
1838 =head1 perl functions provided by the uHTML::std library
1839  
1840 B< >
1841  
1842 =head2 uFilePath($path)
1843  
1844 =head3 Overview
1845  
1846 The function uFilePath determines the absolute path of a file according to the uHTML path name conventions. Path names beginning with '/' are considered as relative to DOCUMENT_ROOT. Path names not beginning with '/' and not prefixed with '#' are considered as relative to the path of the current file. Path names prefixed with '#' are considered as file system absolute if a '/' follows the '#' and relative to DATA_ROOT (or the script directory) if no '/' follows the '#'.
1847  
1848 =head3 Parameters
1849  
1850 =head4 $path
1851  
1852 Path to convert.
1853  
1854 =head3 Example
1855  
1856 if(-f uFilePath('/index.html')) {...
1857  
1858  
1859  
1860 =head1 SEE ALSO
1861  
1862 perl(1), uHTML, http://www.uhtml.de/en/doc/std.uhtml
1863  
1864  
1865  
1866 =head1 AUTHOR
1867  
1868 Roland Mosler (Roland.Mosler@Place.Ug)
1869  
1870 =head1 COPYRIGHT
1871  
1872 Copyright 2009 Roland Mosler. All rights reserved.
1873  
1874 This library is free software; you can redistribute it and/or
1875 modify it under the same terms as Perl itself.
1876  
1877