X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/489e7846289d4fb66eb4b9fab0fed4af719b98ee..e4453d784ec8903820ff2e03c29545b13060f060:/selfforum-cgi/shared/Template.pm?ds=sidebyside diff --git a/selfforum-cgi/shared/Template.pm b/selfforum-cgi/shared/Template.pm index 44da2cc..50103d2 100644 --- a/selfforum-cgi/shared/Template.pm +++ b/selfforum-cgi/shared/Template.pm @@ -4,16 +4,23 @@ package Template; # # # File: shared/Template.pm # # # -# Authors: André Malo , 2001-04-12 # +# Authors: André Malo , 2001-07-01 # +# Frank Schoenmann , 2001-06-04 # # # # Description: Handle XML based HTML-Templates # # # ################################################################################ use strict; -use vars qw($xml_dom_used); +use vars qw( + $xml_dom_used + $VERSION +); -use Carp qw(croak confess); +use Carp qw( + croak + confess +); BEGIN { $xml_dom_used = eval q[ @@ -23,6 +30,13 @@ BEGIN { ]; } +################################################################################ +# +# Version check +# +$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + + ### sub new #################################################################### # # constructor @@ -93,13 +107,30 @@ sub insert { # sub list { my $self = shift; - my $name = shift; croak "no template file specified" unless (defined $self -> {file}); -# no warnings 'uninitialized'; - my $list = join '' => map { ${ $self -> scrap ($name, $_) } } @{ +shift }; + $self -> joinlist ('' => @_); +} + +### sub joinlist ############################################################### +# +# fill in a complete list, using a scrap between the list elements +# +# Params: $join - joining string (or stringref) +# $name - name of the atomic list scrap +# $array - list of hashes (same strcuture like the hash used by 'scrap') +# +# Return: scalar reference - filled in list +# +sub joinlist { + my $self = shift; + my $join = shift; + $join = $$join if ref($join); + my $name = shift; + + my $list = join $join => map { ${ $self -> scrap ($name, $_) } } @{ +shift }; # return \$list; @@ -109,7 +140,10 @@ sub list { # # fill in a template scrap # -# Params: $name - name of the scrap +# Params: $name name of the scrap +# ... +# $no_nl 1 - remove newlines (\n) +# 0 - do no such thing # # Return: scalar reference - filled in scrap # @@ -117,6 +151,11 @@ sub scrap { my $self = shift; my $name = shift; + my $no_nl; + if (!ref $_[$#_]) { + $no_nl = pop @_; + } + croak "no template file specified" unless (defined $self -> {file}); @@ -168,10 +207,50 @@ sub scrap { \%params ); + # remove newlines + # + $scrap =~ s/\015\012|\015|\012//g if ($no_nl); + # return \$scrap; } +### printscrap () ############################################################## +# +# fill in a template scrap and print to STDOUT +# +# Params: $name name of the scrap +# ... +# $no_nl 1 - remove newlines (\n) +# 0 - do no such thing +# +# Return: success code (boolean) +# +sub printscrap { + my $self = shift; + + $self -> scrap2file (\*STDOUT, @_); +} + +### scrap2file () ############################################################## +# +# fill in a template scrap and print to a file handle +# +# Params: $handle filehandle +# $name name of the scrap +# ... +# $no_nl 1 - remove newlines (\n) +# 0 - do no such thing +# +# Return: success code (boolean) +# +sub scrap2file { + my $self = shift; + my $handle = shift; + + print $handle ${$self->scrap(@_)}; +} + ### sub parse_file ############################################################# # # read in and parse template file @@ -333,7 +412,7 @@ sub parse_if { return; } -# keeping 'require' happy +# keep 'require' happy 1; #