uHTML/std.pm untested

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