uHTML/std.pm untested

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