uHTML/std.pm untested

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