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.23" ;
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() . $Node->HTML() ) ;
457 }
458 }
459  
460 sub _findMacroBody
461 {
462 my $Node = shift ;
463  
464 return undef unless $Node->firstChild() ;
465  
466 my( $Child,$Body ) ;
467  
468 for( $Child = $Node->firstChild() ; $Child ; $Child=$Child->next() )
469 {
470 return $Child if $Child->name() eq 'MacroBody' ;
471 return $Body if $Body = _findMacroBody( $Child ) ;
472 }
473 return undef ;
474 }
475  
476 sub Macro( $ )
477 {
478 my $Node = shift ;
479 my $env = $Node->{'ENV'} ;
480 my $Replace ;
481 my $Name ;
482  
483 return unless $Node->end() and $Name = $Node->attr( 'name' ) ;
484 return if $Replace = _checkMacro( $env,$Name ) and not $Node->testAttr( 'replace' ) ;
485 $env->{'uHTML.MacroBody'}->{$Name} = _findMacroBody( $env->{'uHTML.Macros'}->{$Name} = $Node ) ;
486 if( $Node->testAttr( 'attributes' ) )
487 {
488 my( $a,$b,$t,$v,@A ) ;
489 my @AT = split $SO,$Node->attr( 'attributes' ) ;
490 while( @AT )
491 {
492 $b = '' ;
493 $v = shift @AT ;
494 ( $a,$b ) = ($v =~ m/([^\=\s]+)(?:\s*\=\s*(\S.*))?/) ;
495 if( $b and $b =~ s/^(["'])// )
496 {
497 $t = $1 ;
498 $b .= shift @AT unless $b =~ s/$t$// or not @AT ;
499 }
500 $env->{'uHTML.MacroVal'}->{$Name}->{$a} = $b ;
501 push @A,$a ;
502 }
503 $env->{'uHTML.MacroAttr'}->{$Name} = \@A ;
504 }
505 return if $Replace ;
506 uHTML::registerTag( $Name,\&_DoMacro,1 ) ;
507 uHTML::registerVar( $Name,\&_getMacroValue,1 ) ;
508 }
509  
510 sub DefinedVar
511 {
512 my( $Node,$Par,$Var,$Name ) = @_ ;
513 my $env = $Node->{'ENV'} ;
514 return( $Name ne '' && ( _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ) ? 1 : 0 ) ;
515 }
516  
517 sub DefinedTag
518 {
519 my $Node = shift ;
520 my $env = $Node->{'ENV'} ;
521 my $Attr = $Node->attributes ;
522  
523 if( ref $Attr eq 'HASH' )
524 {
525 my $Name = $Attr->{'name'} ;
526 _testDefine( $env,$_ ) || _checkMacro( $env,$_ ) || $_ eq 'name' && $Name ne '' or return foreach keys %{$Attr} ;
527 return if $Name ne '' and not _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ;
528 }
529 $Node->map( '','' ) ;
530 }
531  
532 sub NotDefinedVar
533 {
534 my( $Node,$Par,$Var,$Name ) = @_ ;
535 my $env = $Node->{'ENV'} ;
536  
537 return( $Name ne '' && ( _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ) ? 0 : 1 ) ;
538 }
539  
540 sub NotDefinedTag
541 {
542 my $Node = shift ;
543 my $env = $Node->{'ENV'} ;
544 my $Attr = $Node->attributes ;
545  
546 if( ref $Attr eq 'HASH' )
547 {
548 my $Name = exists $Attr->{'name'} ? $Attr->{'name'} : '' ;
549 _testDefine( $env,$_ ) || _checkMacro( $env,$_ ) || $_ eq 'name' && $Name eq '' and return foreach keys %{$Attr} ;
550 return if $Name ne '' and _testDefine( $env,$Name ) || _checkMacro( $env,$Name ) ;
551 }
552 $Node->map( '','' ) ;
553 }
554  
555 sub _filterNode
556 {
557 my( $Node,$R ) = @_ ;
558  
559 $Node->{Text} =~ s/$R//gs ;
560 $Node->{Trailer} =~ s/$R//gs ;
561  
562 for( my $Child = $Node->{FirstChild} ; $Child ; $Child = $Child->{Next} )
563 {
564 _filterNode( $Child,$R ) ;
565 }
566 }
567  
568 sub skipLF
569 {
570 my $Node = shift ;
571  
572 my $R = $Node->testAttr( 'keepspaces' ) ? qr/\n/ :
573 $Node->testAttr( 'allspaces' ) ? qr/(?:\s*\n\s*)+/ : qr/\n\s*/ ;
574 _filterNode( $Node,$R ) ;
575 if( $R = $Node->attr( 'tag' ) )
576 {
577 $Node->name( $R ) ;
578 $Node->deleteAttr( 'keepspaces','allspaces','tag' ) ;
579 $Node->insert() ;
580 return ;
581 }
582 $Node->map( '','' ) ;
583 }
584  
585 sub skipSpaces
586 {
587 my $Node = shift ;
588  
589 my $R = qr/^\s*|\s*$/ ;
590 _filterNode( $Node,$R ) ;
591 if( $R = $Node->attr( 'tag' ) )
592 {
593 $Node->name( $R ) ;
594 $Node->deleteAttr( 'tag' ) ;
595 $Node->insert() ;
596 return ;
597 }
598 $Node->map( '','' ) ;
599 }
600  
601 sub ForEachVal
602 {
603 return $_[0]->{'ENV'}->{'ForEachValue'} ;
604 }
605  
606 sub ForEachCnt
607 {
608 return $_[0]->{'ENV'}->{'ForEachCount'} ;
609 }
610  
611 sub ForEachNum
612 {
613 return $_[0]->{'ENV'}->{'ForEachCount'}+1 ;
614 }
615  
616 sub Repeat( $ )
617 {
618 my $Node = shift ;
619 my $env = $Node->{'ENV'} ;
620 my $FEC = $env->{'ForEachCount'} ;
621 my $FEV = $env->{'ForEachValue'} ;
622 my $JOIN = $Node->testAttr( 'joint' ) ? $Node->attr( 'joint' ) : $Node->attr( 'join' ) ;
623 my $SKIP = not $Node->testAttr( 'skipempty' ) ;
624 my( $SEP,$NC,$code,$S,$E,$I,$C,$F,$n,$i,@List ) ;
625  
626 if( $Node->testAttr( 'list' ) )
627 {
628 $SEP = $Node->testAttr( 'separator' ) ? ($SEP=$Node->attr( 'separator' ),qr/$SEP/) : $RO ;
629 @List = split $SEP,$Node->attr( 'list' ) ;
630 @List = sort @List if $Node->testAttr( 'sort' ) or $Node->testAttr( 'uniq' ) ;
631 @List = uniq @List if $Node->testAttr( 'uniq' ) ;
632 $C = $Node->testAttr( 'count' ) ? int( $Node->attr( 'count' ) ) : scalar @List ;
633 $F = $Node->testAttr( 'from' ) ? int( $Node->attr( 'from' ) ) - 1 : 0 ;
634 for( $env->{'ForEachCount'}=0; $env->{'ForEachCount'}<$C; $env->{'ForEachCount'}++ )
635 {
636 $env->{'ForEachValue'} = $List[$env->{'ForEachCount'}] ;
637 $NC = $Node->copy ;
638 $NC->map( '','' ) ;
639 next unless ($n = $NC->HTML()) or $SKIP ;
640 $code .= $JOIN if $code ;
641 $code .= $n ;
642 }
643 }
644 elsif( $Node->testAttr( 'to' ) or $Node->testAttr( 'count' ) )
645 {
646 $S = int( $Node->testAttr( 'from' ) ? $Node->attr( 'from' ) : 1 ) ;
647 $I = int( $Node->attr( 'step' ) ) ;
648 $I = 1 unless $I ;
649 $C = int( $Node->attr( 'count' ) ) ;
650 $E = int( $Node->testAttr( 'to' ) ? $Node->attr( 'to' ) : $C*$I+$S ) ;
651 if( $I != 0 and ($E-$S)*$I>=0 )
652 {
653 $n = int(($E-$S)/$I + 1) ;
654 $C = $n if $C <= 0 or $n > 0 and $n < $C ;
655  
656 $env->{'ForEachCount'} = 0 ;
657 for( $env->{'ForEachValue'}=$S; $C-- > 0; $env->{'ForEachValue'}+=$I )
658 {
659 $NC = $Node->copy ;
660 $NC->map( '','' ) ;
661 if( $SKIP or $NC->HTML() )
662 {
663 $code .= $JOIN if $code ;
664 $code .= $NC->HTML() ;
665 }
666 $env->{'ForEachCount'}++ ;
667 }
668 }
669 }
670 $env->{'ForEachCount'} = $FEC ;
671 $env->{'ForEachValue'} = $FEV ;
672 $Node->HTML( $code ) ;
673 }
674  
675 sub getListElement
676 {
677 my( $Node,$Par,$Var,$List,$nr,$SEP ) = @_ ;
678  
679 unless( $Par )
680 {
681 $List = $Node->attr( 'list' ) ;
682 $nr = $Node->attr( 'nr' ) ;
683 $SEP = $Node->attr( 'separator' ) ;
684 }
685 return '' unless $List and $nr > 0 ;
686 $SEP = $SEP ? qr/$SEP/ : $RO ;
687 my @L = split $SEP,$List ;
688 return '' if --$nr > $#L ;
689 return $L[$nr] ;
690 }
691  
692 sub useScript
693 {
694 my( $Node,$Par,$Var,$Path,$error ) = @_ ;
695 my( @E,$p,@P ) ;
696  
697 if( $Par )
698 {
699 @P = split( $SO,$Path ) ;
700 }
701 else
702 {
703 foreach( 'path','script','module','modules','dir' )
704 {
705 push @P,map uFilePath( $_,$Node->env() ),split $SO,$Node->attr( $_ ) if $Node->testAttr( $_ ) ;
706 }
707 push @P,split $SO,$Node->attr( 'use' ) if $Node->testAttr( 'use' ) ;
708 map { require "uHTML/$_.pm" } split $SO,$Node->attr( 'uHTML' ) if $Node->testAttr( 'uHTML' ) ;
709 }
710  
711 if( @P )
712 {
713 foreach $p( @P )
714 {
715 if( -d $p )
716 {
717 if( opendir DH,$p )
718 {
719 foreach( grep m/\.pm$/,readdir DH )
720 {
721 -r "$p/$_" ? { require "$p/$_" } : push @E,"$p/$_" ;
722 }
723 }
724 else
725 {
726 push @E,$p ;
727 }
728 }
729 elsif( -r $p )
730 {
731 require $p ;
732 }
733 else
734 {
735 require $p
736 }
737 }
738 }
739  
740 return '' ;
741 }
742  
743 sub getENV
744 {
745 my $N = $_[1] ? $_[3] : $_[0]->attr('name') ;
746 return( $N ? $_[0]->{ENV}->{$N} : '' ) ;
747 }
748  
749  
750 sub ENVkeys
751 {
752 my $S = $_[1] ? $_[4] : $_[0]->attr('separator') ;
753 $S = ',' unless $S ;
754 return join( $S, sort keys %{$_[0]->{ENV}} ) if $_[1] ? $_[3] : $_[0]->testAttr('sort') ;
755 return join( $S, keys %{$_[0]->{ENV}} ) ;
756 }
757  
758 uHTML::registerTag( 'if',\&DoIf ) ;
759 uHTML::registerTag( 'choice',\&Choice ) ;
760 uHTML::registerVar( 'choice',\&VarChoice ) ;
761 uHTML::registerTag( 'CondAttr',\&CondAttr ) ;
762 uHTML::registerTag( 'include',\&Include ) ;
763 uHTML::registerVar( 'include',\&VarInclude ) ;
764 uHTML::registerTag( 'insert',\&InsertText ) ;
765 uHTML::registerVar( 'uHTMLtoHTML',\&InsertText ) ;
766 uHTML::registerTag( 'define',\&Define ) ;
767 uHTML::registerTag( 'undef',\&ClearDef ) ;
768 uHTML::registerVar( 'defined',\&DefinedVar ) ;
769 uHTML::registerTag( 'defined',\&DefinedTag ) ;
770 uHTML::registerVar( 'notdefined',\&NotDefinedVar ) ;
771 uHTML::registerTag( 'notdefined',\&NotDefinedTag ) ;
772 uHTML::registerVar( 'Alternative',\&Alternative ) ;
773 uHTML::registerVar( 'AltText',\&AltText ) ;
774 uHTML::registerTag( 'macro',\&Macro ) ;
775 uHTML::registerTag( 'identity',\&Identity ) ;
776 uHTML::registerVar( 'identity',\&Identity ) ;
777 uHTML::registerTag( 'skipLF',\&skipLF ) ;
778 uHTML::registerTag( 'skipSpaces',\&skipSpaces ) ;
779 uHTML::register( 'ENV',\&getENV ) ;
780 uHTML::register( 'ENVkeys',\&ENVkeys ) ;
781 uHTML::register( 'replace',\&ReplaceText ) ;
782 uHTML::register( 'RepeatNum',\&ForEachNum ) ;
783 uHTML::register( 'RepeatCount',\&ForEachCnt ) ;
784 uHTML::register( 'RepeatValue',\&ForEachVal ) ;
785 uHTML::registerTag( 'repeat',\&Repeat ) ;
786 uHTML::registerTag( 'Repeat',\&Repeat ) ;
787 uHTML::register( 'uFilePath',\&getFilePath ) ;
788 uHTML::register( 'ListElement',\&getListElement ) ;
789 uHTML::register( 'Modules',\&useScript ) ;
790 uHTML::register( 'Module',\&useScript ) ;
791 uHTML::register( 'uModule',\&useScript ) ;
792  
793  
794  
795 ######################################
796 ######################################
797  
798 =pod
799  
800 =encoding UTF-8
801  
802 =head1 NAME
803  
804 =over 2
805  
806 =item B<uHTML::std> - standard B<HTML> tags
807  
808 =for comment =item B<uHTMLnode> - central B<uHTML> data structure
809  
810 =back
811  
812 =head1 VERSION
813  
814 Version 2.21
815  
816 =head1 DESCRIPTION
817  
818 Standard tags and functions are the most used uHTML tags and functions - think I<std.h> in B<C>.
819 They are used in nearly every B<uHTML> project. It brings programming capabilities directly
820 into the B<uHTML>-files and addresses rather the programmer than the designer, although most
821 designers value especially the tags B<include> and B<define> which use is quite obvious for them.
822 The tags B<if>/B<else>, B<choice>, B<repeat> and B<macro> are usually utilized with support
823 of the programmer. Due their compliance with the standard B<HTML>-syntax designers do not
824 hesitate to alter them without help of the programmer. While doing that the designer seldom
825 incorporate errors into the B<uHTML> file as the tags program code is not affected and
826 a faulty result can be noticed by the designer immediately.
827  
828 =head1 REQUIREMENTS
829  
830 This std library do not require any other libraries but the main B<uHTML> library.
831  
832 =head1 uHTML tags provided by the std library
833  
834 B< >
835  
836 =head2 include
837  
838 =head3 Overview
839  
840 The include tag includes the content of a uHTML file into another uHTML-file.
841 It is intended to move constant parts of the website files like header lines,
842 menus, footers, etc. into one file and save thereby development and maintenance
843 time ans as well reduce probability of random mistakes.
844  
845 =head3 Conventions
846  
847 Path names beginning with '/' are considered as relative to DOCUMENT_ROOT.
848 Path names not beginning with '/' and not prefixed with '#' are considered as
849 relative to the path of the current file. Path names prefixed with '#' are considered
850 as file system absolute if a '/' follows the '#' and relative to DATA_ROOT
851 (or the script directory) if no '/' follows the '#'.
852  
853 =head3 Attributes
854  
855 =head4 file="FILEPATH"
856  
857 The attribute file defines the path and name of the included file.
858  
859 =head4 files="FILEPATH"
860  
861 The attribute files defines the path and name of the included file whereby wildcards *
862 and ? are expanded according to glob rules and the included files get concatenated.
863  
864 =head4 alt="FILEPATH"
865  
866 In case no file defined by the file or files attributes is found, the file defined by
867 the alt attribute get included whereby wildcards * and ? are expanded according to
868 glob rules and the included files get concatenated.
869  
870 =head4 raw
871  
872 The attribute raw without value prevents the interpretation of uHTML-elements in the
873 included file. It should be used if files without uHTML-elements get included.
874  
875 =head4 nowarn
876  
877 The attribute nowarn without value prevents error messages in case the included file
878 isn't found or is not readable.
879  
880 =head4 cond="clause"
881  
882 The cond attribute is optional. If present, then the include tag is executed only if
883 the clause in the attribute cond evaluates 'true'.
884  
885 =head3 Example
886  
887 <include file="/include/navigation" >
888  
889 =head2 define
890  
891 =head3 Overview
892  
893 The define tag defines new uHTML tags and variables assigning to each constant content
894 which isn't interpreted as uHTML. It helps to shorten source files abbreviating frequently
895 used code sequences. At the same time it reduces the risk of random errors while copying
896 of the same content across the site's source files. It is possible to define several tags
897 and variables within one define tag. It is advisable to use the include-tag to collect
898 definitions used in the whole site in one file.
899  
900 =head3 Conventions
901  
902 Previous definitions with the same name are saved and get recovered when a definition
903 done with define get revoked with undef unless the definition is done with the attribute replace.
904  
905 =head3 Attributes
906  
907 =head4 createonly
908  
909 If a attribute createonly without any value is supplied,
910 only new definitions will be regarded. Existing definitions will be skipped.
911  
912 =head4 replace
913  
914 If a attribute replace without any value is supplied,
915 the last definition of a tag and variable will be replaced not recoverable by undef.
916  
917 =head3 Example
918  
919 =head4 Definition:
920  
921 E<lt>define uHTML='E<lt>span style="font-family:serif;color:#34a;"E<gt>
922 E<lt>span style="font-weight:bold;color:#fe6f02; font-size:0.8em"E<gt>UE<lt>/span>HTMLE<lt>/spanE<gt>'
923 bluestyle="color:blue;font-weight:bold;"E<gt>
924  
925 =head4 Use:
926  
927 <uHTML> <span style="$bluestyle"> is exciting </span>
928  
929 =head2 undef
930  
931 =head3 Overview
932  
933 The undef tag revokes definitions done with define. It recovers the previous definition if it exists.
934  
935 =head3 Example
936  
937 <undef uHTML bluestyle>
938  
939 =head2 macro
940  
941 =head3 Overview
942  
943 The macro tag allows to define complex new tags with own attributes within a uHTML file.
944 The uHTML-code within the tag defined with the macro tag is interpreted.
945 Definitions done with macro cannot be revoked like it can be done with definitions
946 done with define, but they can be replaced if the replace attribute
947 is supplied with the new definition.
948  
949 Macros without own parameters can be used as variables in attributes.
950  
951 =head3 Special Tag
952  
953 =head4 <MacroBody>
954  
955 The optional MacroBody tag within a macro definition marks the position of
956 the body when the macro is deployed as a closed tag. If the macro is deployed
957 as a not closed tag, MacroBody is ignored.
958  
959 =head3 Attributes
960  
961 =head4 name="MacroName"
962  
963 The attribute name defines the name of the macro.
964  
965 =head4 attributes="AttributeList"
966  
967 The attribute attributes defines the valid attributes of the defined macro.
968 The attributes of the macro are given in a comma separated list.
969 It is possible to define default values for the macro attributes.
970 Those default values are separated by a '=' from the attribute name.
971 Leading and trailing spaces are ignored unless the value is included
972 in single or double quotation marks. The value must not contain any comma.
973  
974 =head4 replace
975  
976 The attribute replace forces the replacement of a former macro definition
977 with the same name. Without the attribute replace the definition get ignored
978 if a macro with the same name exists.
979  
980 =head3 Example
981  
982 =head4 Definition:
983  
984 <macro name="Label" attributes="text">
985 <div class="toplabel"><text></div>
986 </macro>
987  
988 =head4 Use:
989  
990 <Label text="Home">
991  
992 =head4 Definition:
993  
994 <macro name="Box" attributes="color,background=white">
995 <div class="boxclass" style="color:$color;background-color:$background">
996 <MacroBody>
997 </div>
998 </macro>
999  
1000 =head4 Use:
1001  
1002 <Box color="blue" background="#e3fff6">Boxtext</Box>
1003  
1004 =head2 defined
1005  
1006 =head3 Overview
1007  
1008 The defined tag content is included in the uHTML output if all attributes
1009 without a value equal to a name defined with define or macro or if the value
1010 of the attribute name contains a name defined either with define or with macro.
1011  
1012 =head3 Attributes
1013  
1014 =head4 name="name"
1015  
1016 The name of the define or macro which should be tested for existence.
1017  
1018 =head3 Example
1019  
1020 <defined name="Count">
1021 <Count>
1022 </defined>
1023  
1024 =head2 notdefined
1025  
1026 =head3 Overview
1027  
1028 The notdefined tag content is included in the uHTML output if none
1029 of the attributes without a value equals to a name defined with define
1030 or macro or if the value of the attribute name do not contains a name
1031 defined either with define or with macro.
1032  
1033 =head3 Attributes
1034  
1035 =head4 name="name"
1036  
1037 The name of the define or macro which should be tested for existence.
1038  
1039 =head3 Example
1040  
1041 <notdefined name="bluestyle">
1042 <define bluestyle="color:blue;font-weight:bold;">
1043 </notdefined>
1044  
1045 =head2 if
1046  
1047 =head3 Overview
1048  
1049 The tag if allows conditional content.
1050 It usually contains one ore more else tags which enclose alternative content.
1051  
1052 =head3 Attributes
1053  
1054 =head4 cond="clause"
1055  
1056 The clause in the attribute cond decides if the content of the if tag
1057 is processed and passed to the http client. It is interpreted as a perl expression.
1058 It is true if the result is not 0 or it contains a string with a non-zero length.
1059 In the latter case the string need to be enclosed in quotation marks within
1060 the quotation marks of the attribute value.
1061  
1062 If the attribute content evaluates 'true' the content of the tag
1063 is processed and passed on while the content of subordinated else-tags is ignored.
1064 In opposite case the tag content is discarded while the else tags get evaluated.
1065  
1066 =head3 Example
1067  
1068 <if cond="$File ne 'index.uhtml'">
1069 <a href="/index.uhtml">Home</a>
1070 </if>
1071  
1072 =head2 else
1073  
1074 =head3 Overview
1075  
1076 The tag else used within a if tag defines alternative content.
1077 If it contains the attribute cond, it's content get only processed and passed on
1078 if the clause in the attribute cond evaluates 'true'. In this case all other
1079 else tags within the parental if tag get discarded along with the content of the if tag.
1080  
1081 =head3 Attributes
1082  
1083 =head4 cond="clause"
1084  
1085 The clause in the attribute cond decides if the content of the else tag is processed
1086 and passed to the http client. It is interpreted as a perl expression.
1087 It is true if the result is not 0 or it contains a string with a non-zero length.
1088 In the latter case the string need to be enclosed in quotation marks within the
1089 quotation marks of the attribute value.
1090  
1091 If the attribute content evaluates 'true' the content of the tag is processed
1092 and passed on while the content of all other else tags within the parental
1093 if tags get discarded along with the content of the if tag.
1094  
1095 =head3 Example
1096  
1097 <if cond="$File ne 'index.uhtml'">
1098 <a href="/index.uhtml">Home</a>
1099 <else><img src="spacer.png" alt="placeholder"></else>
1100 </if>
1101  
1102 =head2 choice
1103  
1104 =head3 Overview
1105  
1106 The deployment of if tags with an included else tag is always text-intensive.
1107 Sometimes just two tags or just two attribute values in some attributes of a
1108 tag make the difference. In such cases the tag choice is often the better alternative.
1109 The tag choice can be used as open or closed tag. The alternative values of the attributes
1110 need to be separated by "|". In case the clause in the attribute cond evaluates true,
1111 the value left of "|" is used, otherwise the value right of "|". If the value has a zero length, the attribute is omitted.
1112  
1113 =head3 Attributes
1114  
1115 =head4 cond="clause"
1116  
1117 The clause in the attribute cond decides if the content on the left or the content
1118 on the right side of "|" in the attribute values is used. If no "|" is found in an
1119 attributes value, the value is used independent of the condition.
1120  
1121 =head4 tag="ELEMENTNAME"
1122  
1123 The attribute tag defines the name of the tag by which choice will be replaced.
1124 It is obligatory and in case it is missing or equals to a zero length string,
1125 the whole tag is omitted. It can contain two values separated by "|" which will
1126 be used according to the result of cond.
1127  
1128 =head4 attr="AttributeList"
1129  
1130 A comma separated list of attributes without values which have to be added to the tag.
1131 Two lists separated by "|" can be defined. The lists will be used according to the result of cond.
1132  
1133 =head3 Example
1134  
1135 <choice cond="'$ENV(HTTP_USER_AGENT)' =~ m/Explorer/" tag="div" class="explorer|normal">
1136 ....Text....
1137 </choice>
1138  
1139 =head2 CondAttr
1140  
1141 =head3 Overview
1142  
1143 CondAttr drops all empty attributes. It is meant to avoid empty attributes which may confuse browsers.
1144  
1145 =head3 Attributes
1146  
1147 =head4 tag="ELEMENTNAME"
1148  
1149 The attribute tag defines the name of the tag by which CondAttr will be replaced.
1150 It is obligatory and in case it is missing or equals to a zero length string, the whole tag is omitted.
1151  
1152 =head3 Example
1153  
1154 <CondAttr tag="div" class="$SpecialClass">
1155 ....Text....
1156 </CondAttr>
1157  
1158 =head2 replace
1159  
1160 =head3 Overview
1161  
1162 The tag replace applies perl regular expressions to the text provided by the attribute
1163 text and inserts it into the HTML code. For more information on perl regular expressions,
1164 please consult the corresponding man page perlre.
1165  
1166 =head3 Attributes
1167  
1168 =head4 text="TEXT"
1169  
1170 The text to be altered.
1171  
1172 =head4 pattern="RegExPattern"
1173  
1174 Patterns of the regular expression. Notice that backslashes "\" must be escaped (doubled) "\\".
1175  
1176 =head4 replace="ReplaceText"
1177  
1178 Text that will replace pattern. Notice that "$" signs must be escaped "\$".
1179  
1180 =head4 options="OPTIONS"
1181  
1182 Replace options. For more information about possible options
1183 please consult the perl regular expressions man page perlre.
1184  
1185 =head3 Example
1186  
1187 <replace text="$include(#data/products)" pattern="," replace="<br>">
1188  
1189 =head2 skipLF
1190  
1191 =head3 Overview
1192  
1193 The tag skipLF removes line feeds and any spaces and tabs following it,
1194 speak any spaces or tabs at the beginning of a line. It helps to keep the
1195 source code readable while allowing e.g. place images adjacent.
1196 It is especially useful with the tags macro and repeat.
1197  
1198 =head3 Attributes
1199  
1200 =head4 keepspaces
1201  
1202 Remove line feeds only and keep all spaces.
1203  
1204 =head4 allspaces
1205  
1206 Remove spaces at the end of the lines as well.
1207  
1208 =head4 tag="ELEMENTNAME"
1209  
1210 If present, the attribute tag defines the name of a tag by which skipLF
1211 will be replaced. If it is missing or equals to a zero length string,
1212 the attribute is treated as not existent.
1213  
1214 =head3 Example
1215  
1216 <skipLF>
1217 <img src="/img/left.gif">
1218 <img src="/img/right.gif">
1219 </skipLF>
1220  
1221 =head2 skipSpaces
1222  
1223 =head3 Overview
1224  
1225 Within the tag skipSpaces spaces, tabs and line feeds ahead and following
1226 any tag are removed. It helps to keep the source code readable while allowing
1227 e.g. place images adjacent. It is especially useful with the tags macro and repeat.
1228  
1229 =head3 Attributes
1230  
1231 =head4 tag="ELEMENTNAME"
1232  
1233 If present, the attribute tag defines the name of a tag by which skipSpaces
1234 will be replaced. If it is missing or equals to a zero length string,
1235 the attribute is treated as not existent.
1236  
1237 =head3 Example
1238  
1239 <skipSpaces>
1240 <img src="/img/left.gif">
1241 <img src="/img/right.gif">
1242 </skipSpaces>
1243  
1244 =head2 repeat
1245  
1246 =head2 Repeat
1247  
1248 =head3 Overview
1249  
1250 The tag repeat repeats itself according to the values of it's attributes.
1251 The repeat tags can be nested. The variants repeat and Repeat are identical.
1252  
1253 =head3 Attributes
1254  
1255 =head4 list="ValueList"
1256  
1257 A list of values separated by separator. The tag repeat is repeated once for
1258 each element of the list. If list is defined, other attributes are ignored.
1259  
1260 =head4 separator="REGEX"
1261  
1262 A regular expression used to split the list. If omitted the values in list
1263 must be separated by commas, colons or semicolons surrounded by optional (ignored) spaces (\s*[,;:]\s*).
1264  
1265 =head4 sort
1266  
1267 Valid only if the list attribute is given.
1268 If present, the list will be sorted alphabetically before the execution of repeat.
1269  
1270 =head4 uniq
1271  
1272 Valid only if the list attribute is given.
1273 If present, identical adjacent values of list are ignored. if the attribute sort is given,
1274 uniq is applied on the sorted list.
1275  
1276 =head4 skipempty
1277  
1278 Valid only if the list attribute is given. If present, empty list elements are ignored.
1279  
1280 =head4 from="integer"
1281  
1282 The attribute from defines the initial value to count the iterations. If not defined it defaults to 1.
1283  
1284 If the attribute list is given, it defines the initial list element to be used. The first list element is referred by 1.
1285  
1286 =head4 step="integer"
1287  
1288 The attribute step defines the increment value for a iteration. It can have a negative value.
1289 If not defined it defaults to 1. It is ignored if the attribute list is given.
1290  
1291 =head4 to="integer"
1292  
1293 The attribute to defines the last value for a iteration.
1294 If not defined it defaults to 0. It is ignored if the attribute list is given.
1295  
1296 =head4 count="integer"
1297  
1298 The attribute to defines the count of iteration.
1299 If not defined it defaults to 0. It is ignored if to is defined and different from 0.
1300  
1301 If the attribute list is given, it defines the count of elements to be used.
1302  
1303 =head4 joint="text"
1304  
1305 Text inserted between the repetitions of repeat. It can contain HTML tags. uHTML tags and variables will be ignored.
1306  
1307 If uHTML tags and variables should get interpreted, the function $uHTMLtoHTML can be used.
1308  
1309 =head3 Example
1310  
1311 <center><repeat count="11" >#</repeat></center>
1312  
1313 =head2 RepeatCount
1314  
1315 =head3 Overview
1316  
1317 The tag RepeatCount is valid within the repeat tag. It returns the count of completed iterations of the tag repeat.
1318  
1319 =head3 Example
1320  
1321 <repeat count="20"><RepeatCount> completed<br></repeat>
1322  
1323 =head2 RepeatNum
1324  
1325 =head3 Overview
1326  
1327 The tag RepeatNum is valid within the repeat tag. It returns the number of the current iteration of the tag repeat.
1328  
1329 =head3 Example
1330  
1331 <repeat count="20">Am in iteration <RepeatNum><br></repeat>
1332  
1333 =head2 RepeatValue
1334  
1335 =head3 Overview
1336  
1337 The tag RepeatValue is valid within the repeat tag.
1338 It returns the current value associated the current iteration of the tag repeat.
1339 In case the overlying repeat tag has the attribute list, it returns the
1340 corresponding list value. Otherwise it returns the value calculated according
1341 to the attributes from and step of the overlying repeat tag.
1342  
1343 =head3 Example
1344  
1345 <repeat count="10">Line <RepeatValue><br></repeat>
1346  
1347 =head2 ListElement
1348  
1349 =head3 Overview
1350  
1351 The tag ListElement extracts an single element from a text list.
1352 It is ineffective and should be only used to occasionally extract
1353 a single list element and must be never used within a loop.
1354  
1355 =head3 Attributes
1356  
1357 =head4 list="LIST"
1358  
1359 The list from which the element hast to be extracted. If missing or empty the tag is omitted.
1360  
1361 =head4 nr="NUMBER"
1362  
1363 Number of the element to be extracted.
1364 The first element in the list has the number 1. If missing or out of range the tag is omitted.
1365  
1366 =head4 SEP="REGEX"
1367  
1368 Element separator used in the list.
1369 If omitted it defaults to commas, colons or semicolons surrounded by optional (ignored) spaces (\s*[,;:]\s*).
1370  
1371 =head3 Example
1372  
1373 <ListElement list="A, B, C" nr="2">
1374  
1375 =head2 uFilePath
1376  
1377 =head3 Overview
1378  
1379 The tag uFilePath determines the absolute path of a file according
1380 to the uHTML path name conventions. Path names beginning with '/'
1381 are considered as relative to DOCUMENT_ROOT. Path names not
1382 beginning with '/' and not prefixed with '#' are considered as
1383 relative to the path of the current file. Path names prefixed
1384 with '#' are considered as file system absolute if a '/' follows
1385 the '#' and relative to DATA_ROOT (or the script directory) if no '/' follows the '#'.
1386  
1387 =head3 Attributes
1388  
1389 =head4 path="PATH"
1390  
1391 Path to convert.
1392  
1393 =head3 Example
1394  
1395 Document Root: <uFilePath path="/">
1396  
1397 =head2 ENV
1398  
1399 =head3 Overview
1400  
1401 The tag ENV inserts the value of the environment variable name into the HTML-code.
1402  
1403 =head3 Attributes
1404  
1405 =head4 name="EnvVarName"
1406  
1407 Name of the environment variable.
1408  
1409 =head3 Example
1410  
1411 <ENV name="SERVER_NAME">
1412  
1413 =head2 ENVkeys
1414  
1415 =head3 Overview
1416  
1417 The tag ENVkeys inserts a list of all environment variables names into the HTML-code.
1418  
1419 =head3 Attributes
1420  
1421 =head4 separator="SEPARATOR"
1422  
1423 Separator between the names to be used in the list. Defaults to "," if omitted.
1424  
1425 =head4 sort
1426  
1427 If the attribute sort is present, the list is sorted.
1428  
1429 =head3 Example
1430  
1431 <ENVkeys>
1432  
1433 =head2 insert
1434  
1435 =head3 Overview
1436  
1437 The tag insert inserts the value of the attribute text into the HTML-code.
1438 The attribute raw prevents the interpretation of uHTML elements in text.
1439 This tag is used mainly for site debugging purposes.
1440  
1441 =head3 Attributes
1442  
1443 =head4 text="Text"
1444  
1445 Text inserted into HTML.
1446  
1447 = head4 raw
1448  
1449 The attribute raw prevents the interpretation of uHTML elements in text.
1450  
1451 =head3 Example
1452  
1453 <insert text="$testfunc(A,1)">
1454  
1455 =head2 identity
1456  
1457 =head3 Overview
1458  
1459 The tag identity does literal nothing. This tag is used mainly for site debugging purposes.
1460  
1461 =head3 Example
1462  
1463 <identity>Text</identity>
1464  
1465 =head2 uModule
1466  
1467 =head3 Overview
1468  
1469 The tag uModule makes perl modules (usually uHTML modules) accessible within the website.
1470  
1471 =head3 Attributes
1472  
1473 =head4 path="FileName"
1474  
1475 =head4 script="FileName"
1476  
1477 =head4 module="FileName"
1478  
1479 =head4 modules="FileName"
1480  
1481 =head4 dir="FileName"
1482  
1483 The filename of the required module. The attribute can contain several module names
1484 separated by commas. The file names are interpreted according to the uHTML file name
1485 conventions. Path names beginning with '/' are considered as relative to DOCUMENT_ROOT.
1486 Path names not beginning with '/' and not prefixed with '#' are considered as relative
1487 to the path of the current file. Path names prefixed with '#' are considered as file
1488 system absolute if a '/' follows the '#' and relative to DATA_ROOT (or the script
1489 directory) if no '/' follows the '#'.
1490  
1491 =head4 error
1492  
1493 The attribute error forces error messages in the servers log files.
1494  
1495 =head3 Example
1496  
1497 <uModule script="inc/edit/uHTML/edit.pm">
1498  
1499 B< >
1500  
1501 B< >
1502  
1503 =head1 Attribute variables and functions provided by the std library
1504  
1505 B< >
1506  
1507 =head2 $defined(name)
1508  
1509 =head3 Overview
1510  
1511 The $defined function is used mainly within the cond attribute of different tags.
1512  
1513 =head3 Parameters
1514  
1515 =head4 name
1516  
1517 The name of a definition either by define or by macro which should be tested for existence.
1518  
1519 =head3 Example
1520  
1521 <if cond="$defined(Products)">
1522 <Products>
1523 </if>
1524  
1525 =head2 $notdefined(name)
1526  
1527 =head3 Overview
1528  
1529 The $notdefined function is used mainly within the cond attribute of different tags.
1530  
1531 =head3 Parameters
1532  
1533 =head4 name
1534  
1535 The name of a definition either by define or by macro which should be tested for existence.
1536  
1537 =head3 Example
1538  
1539 <include cond="$notdefined(Products)" file="#inc/products">
1540  
1541 =head2 $choice(cond,true,false)
1542  
1543 =head3 Overview
1544  
1545 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.
1546  
1547 =head3 Parameters
1548  
1549 =head4 cond
1550  
1551 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.
1552  
1553 =head4 true
1554  
1555 Value returned if cond evaluates true.
1556  
1557 =head4 false
1558  
1559 Value returned if cond evaluates false.
1560  
1561 =head3 Example
1562  
1563 <div class="$choice($SiteName,std,special)">
1564  
1565 =head2 $Alternative(par1,par1,par3,…)
1566  
1567 =head3 Overview
1568  
1569 Sometimes the first true (in sense of perl) out of many values is needed.
1570 For such cases the function $Alternative is defined. $Alternative returns
1571 the first parameter which isn't an empty string or zero. To use it as a tag
1572 wrap it into the tag insert.
1573  
1574 =head3 Parameters
1575  
1576 =head4 par1,par1,par3,…
1577  
1578 The first par* parameter which isn't an empty string or zero will be returned by the function Alternative.
1579  
1580 =head3 Example
1581  
1582 <insert text="$Alternative($FormData,$Default)">
1583  
1584 =head2 $AltText(par1,par1,par3,…)
1585  
1586 =head3 Overview
1587  
1588 Sometimes the first value containing some text out of many values is needed.
1589 For such cases the function $AltText is defined. $AltText returns the first
1590 parameter which isn't an empty string. To use it as a tag wrap it into the tag insert.
1591  
1592 =head3 Parameters
1593  
1594 =head4 par1,par1,par3,…
1595  
1596 The first par* parameter which isn't an empty string will be returned by the function AltText.
1597  
1598 =head3 Example
1599  
1600 <insert text="$AltText($FormData,$Default)">
1601  
1602 =head2 $include(file,alt)
1603  
1604 =head3 Overview
1605  
1606 The function $include inserts the content of a file into a attribute.
1607 The file names are interpreted according to the uHTML file name conventions.
1608 Path names beginning with '/' are considered as relative to DOCUMENT_ROOT.
1609 Path names not beginning with '/' and not prefixed with '#' are considered
1610 as relative to the path of the current file. Path names prefixed with '#' are
1611 considered as file system absolute if a '/' follows the '#' and relative to
1612 DATA_ROOT (or the script directory) if no '/' follows the '#'.
1613  
1614 =head3 Parameters
1615  
1616 =head4 file
1617  
1618 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.
1619  
1620 =head4 alt
1621  
1622 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.
1623  
1624 =head3 Example
1625  
1626 <select name="products">
1627 <repeat list="$include(#data/products)">
1628 <option><RepeatValue></option>
1629 </repeat>
1630 </select>
1631  
1632 =head2 $replace(text,pattern,replace,options)
1633  
1634 =head3 Overview
1635  
1636 The function $replace applies perl regular expressions to the text provided
1637 by the parameter text before returning it. For more information on perl
1638 regular expressions, please consult the corresponding man page perlre.
1639  
1640 =head3 Parameters
1641  
1642 =head4 text
1643  
1644 The text to be altered.
1645  
1646 =head4 pattern
1647  
1648 Patterns of the regular expression. Notice that backslashes "\" must be escaped (doubled) "\\".
1649  
1650 =head4 replace
1651  
1652 Text that will replace pattern. Notice that "$" signs must be escaped "\$".
1653  
1654 =head4 options
1655  
1656 Replace options. For more information about possible options please consult the perl regular expressions man page perlre.
1657  
1658 =head3 Example
1659  
1660 <insert text="$replace('$include(#data/products)',',','<br>')">
1661  
1662 =head2 $RepeatCount()
1663  
1664 =head3 Overview
1665  
1666 The variable $RepeatCount is valid within the repeat tag.
1667 It returns the count of completed iterations of the tag repeat.
1668  
1669 =head3 Example
1670  
1671 <select name="weekday">
1672 <repeat list="Monday,Tuesday,Wednesday,Thursday.Friday,Saturday,Sunday">
1673 <option value="$RepeatCount"><RepeatValue></option>
1674 </repeat>
1675 </select>
1676  
1677 =head2 $RepeatNum()
1678  
1679 =head3 Overview
1680  
1681 The variable $RepeatNum is valid within the repeat tag.
1682 It returns the number of the current iteration of the tag repeat.
1683  
1684 =head3 Example
1685  
1686 <select name="weekday">
1687 <repeat list="Monday,Tuesday,Wednesday,Thursday.Friday,Saturday,Sunday">
1688 <option value="$RepeatCount"><RepeatNum>: <RepeatValue></option>
1689 </repeat>
1690 </select>
1691  
1692 =head2 $RepeatValue()
1693  
1694 =head3 Overview
1695  
1696 The variable $RepeatValue is valid within the repeat tag.
1697 It returns the current value associated the current iteration of the tag repeat,
1698 e.g. the corresponding value from the attribute list.
1699  
1700 =head3 Example
1701  
1702 <select name="weekday">
1703 <repeat list="Monday,Tuesday,Wednesday,Thursday.Friday,Saturday,Sunday">
1704 <option value="$RepeatNum"><RepeatValue></option>
1705 </repeat>
1706 </select>
1707  
1708 =head2 $ListElement(List,nr,SEP)
1709  
1710 =head3 Overview
1711  
1712 The variable $ListElement extracts an single element from a text list.
1713 It is ineffective and should be only used to occasionally extract a single
1714 list element and must be never used within a loop.
1715  
1716 =head3 Parameters
1717  
1718 =head4 list
1719  
1720 The list from which the element hast to be extracted. If empty the result is an empty string.
1721  
1722 =head4 nr
1723  
1724 Number of the element to be extracted. The first element in the list has the number 1.
1725 If missing or out of range the result is an empty string.
1726  
1727 =head4 SEP
1728  
1729 Element separator used in the list. If omitted it defaults to \s*[,;:]\s*.
1730  
1731 =head3 Example
1732  
1733 <insert text="$ListElement( 'A, B, C',2 )">
1734  
1735 =head2 $uFilePath(path)
1736  
1737 =head3 Overview
1738  
1739 The function $uFilePath determines the absolute path of a file according
1740 to the uHTML path name conventions. Path names beginning with '/' are
1741 considered as relative to DOCUMENT_ROOT. Path names not beginning with '/'
1742 and not prefixed with '#' are considered as relative to the path of the
1743 current file. Path names prefixed with '#' are considered as file system
1744 absolute if a '/' follows the '#' and relative to DATA_ROOT (or the script
1745 directory) if no '/' follows the '#'.
1746  
1747 =head3 Parameters
1748  
1749 =head4 path
1750  
1751 Path to convert.
1752  
1753 =head3 Example
1754  
1755 <if cond="-f '$uFilePath(/index.html)'"> <code>/index.html</code> exists. </if>
1756  
1757 =head2 $ENV(name)
1758  
1759 =head3 Overview
1760  
1761 The function $ENV inserts the value of the environment variable name into a attribute.
1762  
1763 =head3 Parameters
1764  
1765 =head4 name
1766  
1767 Name of the environment variable.
1768  
1769 =head3 Example
1770  
1771 <if cond="'$ENV(HTTP_VIA)'"> Request passed a proxy server. </if>
1772  
1773 =head2 $ENVkeys(sort,separator)
1774  
1775 =head3 Overview
1776  
1777 The function $ENV inserts the value of the environment variable name into a attribute.
1778  
1779 =head3 Parameters
1780  
1781 =head4 sort
1782  
1783 If true the list get sorted.
1784  
1785 =head4 separator
1786  
1787 Separator between the names to be used in the list. Defaults to "," if omitted.
1788  
1789 =head3 Example
1790  
1791 <repeat list="$ENVkeys(sort,';')">
1792 <div><RepeatValue>=<ENV name="$RepeatValue"></div>
1793 </repeat>
1794  
1795 =head2 $identity(value)
1796  
1797 =head3 Overview
1798  
1799 The function $identity does literal nothing.
1800 It just returns the unchanged parameter value. This tag is used mainly for site debugging purposes.
1801  
1802 =head3 Parameters
1803  
1804 =head4 value
1805  
1806 The parameter value defines the return value of the function $identity.
1807  
1808 =head3 Example
1809  
1810 <insert text="$identity(Text)">
1811  
1812 =head2 $uHTMLtoHTML(uHTML)
1813 ,
1814 =head3 Overview
1815  
1816 The function $uHTMLtoHTML forces a parameter to be interpreted
1817 as B<uHTML> input and be translated into B<HTML>.
1818  
1819 =head3 Parameters
1820  
1821 =head4 uHTML
1822  
1823 The parameter uHTML get translated into HTML.
1824  
1825 =head3 Example
1826  
1827 <skipLF>
1828 <repeat count="20" joint="$uHTMLtoHTML(<RecordSeparator>)">
1829 <Record num="$RepeatCount">
1830 </repeat>
1831 </skipLF>
1832  
1833 B< >
1834  
1835 B< >
1836  
1837 =head1 perl functions provided by the uHTML::std library
1838  
1839 B< >
1840  
1841 =head2 uFilePath($path)
1842  
1843 =head3 Overview
1844  
1845 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 '#'.
1846  
1847 =head3 Parameters
1848  
1849 =head4 $path
1850  
1851 Path to convert.
1852  
1853 =head3 Example
1854  
1855 if(-f uFilePath('/index.html')) {...
1856  
1857  
1858  
1859 =head1 SEE ALSO
1860  
1861 perl(1), uHTML, http://www.uhtml.de/en/doc/std.uhtml
1862  
1863  
1864  
1865 =head1 AUTHOR
1866  
1867 Roland Mosler (Roland.Mosler@Place.Ug)
1868  
1869 =head1 COPYRIGHT
1870  
1871 Copyright 2009 Roland Mosler. All rights reserved.
1872  
1873 This library is free software; you can redistribute it and/or
1874 modify it under the same terms as Perl itself.
1875  
1876