uHTML/std.pm untested

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