summaryrefslogtreecommitdiff
path: root/Xerl/Page/Templates.pm
diff options
context:
space:
mode:
authorPaul Buetow (pluto.buetow.org) <paul@buetow.org>2013-09-15 11:51:10 +0200
committerPaul Buetow (pluto.buetow.org) <paul@buetow.org>2013-09-15 11:51:10 +0200
commit6aa12ae5f556ab884b7705379c41a566df86d028 (patch)
tree85441b3a046f58970ebe9ad55460c16e4f4d3d01 /Xerl/Page/Templates.pm
parentc183faa4d53b6e4f091d6b38397847e55b5d2251 (diff)
temp remove includedirs tag, perltidy indention set to 2, initial XML::LibXML
Diffstat (limited to 'Xerl/Page/Templates.pm')
-rw-r--r--Xerl/Page/Templates.pm282
1 files changed, 140 insertions, 142 deletions
diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm
index efe7321..3b7d13f 100644
--- a/Xerl/Page/Templates.pm
+++ b/Xerl/Page/Templates.pm
@@ -44,200 +44,198 @@ use Xerl::Tools::FileIO;
use constant RECURSIVE => 1;
sub parse($) {
- my Xerl::Page::Templates $self = $_[0];
- my Xerl::Page::Configure $config = $self->get_config();
+ my Xerl::Page::Templates $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
- my $site = $config->get_site();
+ my $site = $config->get_site();
- my $subpath = $site;
- if ( $site =~ s#^.*/(.*)$#$1#o ) {
- $subpath =~ s#/[^/]+$#/#;
- $subpath =~ s#/#.sub/#go;
+ my $subpath = $site;
+ if ( $site =~ s#^.*/(.*)$#$1#o ) {
+ $subpath =~ s#/[^/]+$#/#;
+ $subpath =~ s#/#.sub/#go;
- }
- else {
- $subpath = '';
- }
+ }
+ else {
+ $subpath = '';
+ }
- my $cachefile =
- $config->get_template() . ';'
- . $config->get_outputformat() . ';'
- . $site
- . ( $config->noparse_exists() ? '.noparse' : '' )
- . '.cache';
+ my $cachefile =
+ $config->get_template() . ';'
+ . $config->get_outputformat() . ';'
+ . $site
+ . ( $config->noparse_exists() ? '.noparse' : '' )
+ . '.cache';
- my $cachepath = $config->get_cachepath() . $subpath;
+ my $cachepath = $config->get_cachepath() . $subpath;
- if ( -f $cachepath . $cachefile
- && ( $config->usecache_exists() or not $config->nocache_exists() ) )
- {
+ if ( -f $cachepath . $cachefile
+ && ( $config->usecache_exists() or not $config->nocache_exists() ) )
+ {
- my Xerl::Tools::FileIO $io =
- Xerl::Tools::FileIO->new( path => $cachepath . $cachefile );
+ my Xerl::Tools::FileIO $io =
+ Xerl::Tools::FileIO->new( path => $cachepath . $cachefile );
- if ( -1 == $io->fslurp() ) {
- $config->set_finish_request(1);
- return undef;
- }
+ if ( -1 == $io->fslurp() ) {
+ $config->set_finish_request(1);
+ return undef;
+ }
- $self->set_array( $io->get_array() );
+ $self->set_array( $io->get_array() );
- }
- else {
- my $xmlconfigpath = $config->get_hostpath() . 'config.xml';
+ }
+ else {
+ my $xmlconfigpath = $config->get_hostpath() . 'config.xml';
- $xmlconfigpath = $config->get_defaulthostpath() . 'config.xml'
- unless -f $xmlconfigpath;
+ $xmlconfigpath = $config->get_defaulthostpath() . 'config.xml'
+ unless -f $xmlconfigpath;
- my Xerl::XML::Reader $xmlconfigreader =
- Xerl::XML::Reader->new( path => $xmlconfigpath, config => $config );
+ my Xerl::XML::Reader $xmlconfigreader =
+ Xerl::XML::Reader->new( path => $xmlconfigpath, config => $config );
- if ( -1 == $xmlconfigreader->open() ) {
- $config->set_finish_request(1);
- return undef;
- }
+ if ( -1 == $xmlconfigreader->open() ) {
+ $config->set_finish_request(1);
+ return undef;
+ }
- $xmlconfigreader->parse();
- $config->set_xmlconfigrootobj( $xmlconfigreader->get_root() );
+ $xmlconfigreader->parse();
+ $config->set_xmlconfigrootobj( $xmlconfigreader->get_root() );
- my Xerl::Page::Menu $menu = Xerl::Page::Menu->new( config => $config );
+ my Xerl::Page::Menu $menu = Xerl::Page::Menu->new( config => $config );
- $menu->generate();
- $config->set_menuobj($menu);
+ $menu->generate();
+ $config->set_menuobj($menu);
- if ( $site =~ /^(\d+)\./ ) {
- $config->set_templatepath(
- $config->get_hostpath() . "content/$subpath$site.xml" );
- }
- elsif ( -f $config->get_hostpath() . "content/$subpath$site.xml" ) {
- $config->set_templatepath(
- $config->get_hostpath() . "content/$subpath$site.xml" );
- }
+ if ( $site =~ /^(\d+)\./ ) {
+ $config->set_templatepath(
+ $config->get_hostpath() . "content/$subpath$site.xml" );
+ }
+ elsif ( -f $config->get_hostpath() . "content/$subpath$site.xml" ) {
+ $config->set_templatepath(
+ $config->get_hostpath() . "content/$subpath$site.xml" );
+ }
- # Hidden files
- elsif ( -f $config->get_hostpath() . "content/$subpath.$site.xml" ) {
- $config->set_templatepath(
- $config->get_hostpath() . "content/$subpath.$site.xml" );
- }
- else {
- my $glob = $config->get_hostpath() . "content/$subpath*.$site.xml";
- eval "(\$glob) = sort <$glob>;";
- $config->set_templatepath($glob);
- }
+ # Hidden files
+ elsif ( -f $config->get_hostpath() . "content/$subpath.$site.xml" ) {
+ $config->set_templatepath(
+ $config->get_hostpath() . "content/$subpath.$site.xml" );
+ }
+ else {
+ my $glob = $config->get_hostpath() . "content/$subpath*.$site.xml";
+ eval "(\$glob) = sort <$glob>;";
+ $config->set_templatepath($glob);
+ }
- my Xerl::Page::Content $bodycontent =
- Xerl::Page::Content->new( config => $config );
+ my Xerl::Page::Content $bodycontent =
+ Xerl::Page::Content->new( config => $config );
- $bodycontent->parse();
+ $bodycontent->parse();
- my $templatepath =
- $config->get_hostpath()
- . "templates/"
- . $config->get_template() . '.xml';
+ my $templatepath =
+ $config->get_hostpath() . "templates/" . $config->get_template() . '.xml';
- $templatepath =
- $config->get_defaulthostpath()
- . "templates/"
- . $config->get_template() . '.xml'
- unless -f $templatepath;
+ $templatepath =
+ $config->get_defaulthostpath()
+ . "templates/"
+ . $config->get_template() . '.xml'
+ unless -f $templatepath;
- $config->set_templatepath($templatepath);
+ $config->set_templatepath($templatepath);
- my Xerl::Page::Content $templatecontent =
- Xerl::Page::Content->new( config => $config );
+ my Xerl::Page::Content $templatecontent =
+ Xerl::Page::Content->new( config => $config );
- $templatecontent->parse();
+ $templatecontent->parse();
- $self->set_array( $templatecontent->get_content() );
- $config->set_content( $bodycontent->get_content() );
- $self->parsetemplate( '%%', RECURSIVE );
+ $self->set_array( $templatecontent->get_content() );
+ $config->set_content( $bodycontent->get_content() );
+ $self->parsetemplate( '%%', RECURSIVE );
- my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new(
- path => $cachepath,
- filename => $cachefile,
- array => $self->get_array(),
- );
+ my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new(
+ path => $cachepath,
+ filename => $cachefile,
+ array => $self->get_array(),
+ );
- $io->fwrite();
- }
+ $io->fwrite();
+ }
- $self->parsetemplate('$$'); # Parsing dynamic vars.
- return undef;
+ $self->parsetemplate('$$'); # Parsing dynamic vars.
+ return undef;
}
sub parsetemplate($$;$) {
- my Xerl::Page::Templates $self = $_[0];
- my Xerl::Page::Configure $config = $self->get_config();
- my $deepnesslevel = $_[2] || 0;
+ my Xerl::Page::Templates $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+ my $deepnesslevel = $_[2] || 0;
- return $self if $deepnesslevel == 100;
+ return $self if $deepnesslevel == 100;
- my ( $sep, $foundflag ) = quotemeta $_[1];
+ my ( $sep, $foundflag ) = quotemeta $_[1];
- PARSELINE( $config, $sep, \$_, \$foundflag ) for @{ $self->get_array() };
+ PARSELINE( $config, $sep, \$_, \$foundflag ) for @{ $self->get_array() };
- return $self->parsetemplate( $_[1], $deepnesslevel + 1 )
- if defined $deepnesslevel > 0 and $foundflag;
+ return $self->parsetemplate( $_[1], $deepnesslevel + 1 )
+ if defined $deepnesslevel > 0 and $foundflag;
- return undef;
+ return undef;
}
# Static sub
sub PARSELINE($$$;$) {
- my Xerl::Page::Configure $config = $_[0];
- my ( $sep, $line, $foundflag ) = @_[ 1 .. 3 ];
+ my Xerl::Page::Configure $config = $_[0];
+ my ( $sep, $line, $foundflag ) = @_[ 1 .. 3 ];
- $$line =~ s/$sep(!)?(.+?)$sep/
+ $$line =~ s/$sep(!)?(.+?)$sep/
defined $1 ? `$2` :
(ref $config->getval($2) eq 'ARRAY')
? join '', @{$config->getval($2)} :
$config->getval($2)/eg and $$foundflag = 1;
- return undef;
+ return undef;
}
sub print($;$) {
- my Xerl::Page::Templates $self = $_[0];
- my Xerl::Page::Configure $config = $self->get_config();
-
- my ( $code, $flag ) = ( '', 0 );
- my $time = $_[1];
- my $hflag = 1;
-
- for my $line ( @{ $self->get_array() } ) {
- if ( $hflag == 1 && $config->exists('noparse') ) {
- $line =~ s#^Content-Type.*#Content-Type: text/plain#i;
- $hflag = 0;
- }
- $line =~ s/ +/ /g;
- redo if !$flag and $line =~ s/<perl>((?:.|\n)*?)<\/perl>/eval $1/ego;
-
- if ( !$flag and $line =~ s/<perl>(.*)$//o ) {
- $code .= $1;
- $flag = 1;
-
- }
- elsif ( $line =~ s/^(.*?)<\/perl>/eval $code.$1/eo ) {
- ( $code, $flag ) = ( '', 0 );
- redo;
-
- }
- elsif ($flag) {
- $line =~ s/^(.*\n)$//o;
- $code .= $1;
- next;
- }
-
- my $time = defined $time ? sprintf '%1.4f', tv_interval($time) : '';
-
- $line =~ s/!!TIME!!/$time/ge;
- $line =~ s/!!LT!!/</g;
- $line =~ s/!!GT!!/>/g;
- $line =~ s#!!URL\((.+?)\)!!#<a href="$1">$1</a>#g;
- print $line;
+ my Xerl::Page::Templates $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ my ( $code, $flag ) = ( '', 0 );
+ my $time = $_[1];
+ my $hflag = 1;
+
+ for my $line ( @{ $self->get_array() } ) {
+ if ( $hflag == 1 && $config->exists('noparse') ) {
+ $line =~ s#^Content-Type.*#Content-Type: text/plain#i;
+ $hflag = 0;
+ }
+ $line =~ s/ +/ /g;
+ redo if !$flag and $line =~ s/<perl>((?:.|\n)*?)<\/perl>/eval $1/ego;
+
+ if ( !$flag and $line =~ s/<perl>(.*)$//o ) {
+ $code .= $1;
+ $flag = 1;
+
}
+ elsif ( $line =~ s/^(.*?)<\/perl>/eval $code.$1/eo ) {
+ ( $code, $flag ) = ( '', 0 );
+ redo;
+
+ }
+ elsif ($flag) {
+ $line =~ s/^(.*\n)$//o;
+ $code .= $1;
+ next;
+ }
+
+ my $time = defined $time ? sprintf '%1.4f', tv_interval($time) : '';
+
+ $line =~ s/!!TIME!!/$time/ge;
+ $line =~ s/!!LT!!/</g;
+ $line =~ s/!!GT!!/>/g;
+ $line =~ s#!!URL\((.+?)\)!!#<a href="$1">$1</a>#g;
+ print $line;
+ }
- return undef;
+ return undef;
}
1;