summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2011-03-06 10:57:41 +0000
committerPaul Buetow <paul@buetow.org>2011-03-06 10:57:41 +0000
commit213033db33be271791f2d9ff1c9c44c0bed79f18 (patch)
tree1b3ff0d0eddfc7f6995afa67b5d3fc2ef8fa85a7
initial xerl import to utils
-rw-r--r--COPYING28
-rw-r--r--Makefile32
-rw-r--r--README68
-rw-r--r--STYLEGUIDE71
-rw-r--r--TODO10
-rw-r--r--Xerl.pm98
-rw-r--r--Xerl/.htaccess0
-rw-r--r--Xerl/Base.pm130
-rw-r--r--Xerl/Main/Global.pm97
-rw-r--r--Xerl/Page/Configure.pm165
-rw-r--r--Xerl/Page/Content.pm226
-rw-r--r--Xerl/Page/Document.pm71
-rw-r--r--Xerl/Page/Menu.pm128
-rw-r--r--Xerl/Page/Parameter.pm72
-rw-r--r--Xerl/Page/Request.pm70
-rw-r--r--Xerl/Page/Rules.pm95
-rw-r--r--Xerl/Page/Templates.pm262
-rw-r--r--Xerl/Plugins/Session.pm127
-rw-r--r--Xerl/Tools/FileIO.pm186
-rw-r--r--Xerl/XML/Element.pm111
-rw-r--r--Xerl/XML/Reader.pm195
-rw-r--r--config.txt24
-rwxr-xr-xindex.pl10
-rw-r--r--scripts/modules/file.pm54
-rwxr-xr-xscripts/mreplace.sh12
-rwxr-xr-xscripts/replace.sh6
-rw-r--r--scripts/stats.pl92
-rwxr-xr-xscripts/stats/calc.sh49
-rwxr-xr-xscripts/stats/clean.sh49
-rwxr-xr-xscripts/stats/replace.sh11
-rwxr-xr-xscripts/stats/stats.sh61
31 files changed, 2610 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..be5ae5e
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,28 @@
+# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.perl9.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a9c9285
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,32 @@
+all: stats
+clean:
+ rm -Rf cache/*
+stats: clean
+ perl scripts/stats.pl
+replace:
+ for i in index.pl Xerl.pm conf.txt; \
+ do \
+ sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" $$i && mv -f .tmp $$i; \
+ done
+ find ./Xerl -name '*.pm' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ find ./Xerl -name '*.pl' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ find ./Xerl -name '*.log' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ find ./Xerl -name '*.xml' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ chmod 755 index.pl
+pidy:
+ find . -name \*.pl | xargs perltidy -b
+ find . -name \*.pm | xargs perltidy -b
+ find . -name \*.bak | xargs rm -f
+todo:
+ grep -R TODO . | grep -v Makefile | grep -v .svn
+warn:
+ perl index.pl 2> warnings
+ less warnings
+ rm -f warnings
+kb:
+ find . -name '*.pm' -exec du -hs {} \; | awk 'BEGIN{kb=0}{kb+=$$1}END{print kb}'
diff --git a/README b/README
new file mode 100644
index 0000000..7a6d984
--- /dev/null
+++ b/README
@@ -0,0 +1,68 @@
+Always do:
+
+- Pragmatic modules ALWAYS to use in ALL packages:
+
+ use strict;
+ use warnings;
+
+- Only for packages for including package UNIVERSAL definitions
+
+ use Xerl::Page::Base;
+
+- Object oriented coding style
+
+- Always use method prototypes if possible
+
+ sub foo($;$) { .... }
+
+- Explicit object typing if possible
+
+ my Class::Name::Here $foo = Class::Name::Here->new();
+
+- If no real ret val, set undef; explicitly
+
+ sub foo() {
+ # Do some stuff
+ ...
+ # Set explicit undef ret value
+ return undef;
+ }
+
+- Private subs use _ as its prefix and are called only from the current package.
+
+ package Xerl::Foo::Bla;
+ .
+ .
+
+ sub _iamprivate($) {
+ my Xerl::Foo:Bla $self = $_[0];
+ .
+ .
+ }
+
+ sub iampublic($) {
+ my Xerl::Foo:Bla $self = $_[0];
+ $self->_iamprivate();
+ return undef;
+ }
+
+- Static subs (not OOP) are in CAPITAL letters.
+
+ sub IAMSTATIC($) {
+ print shift;
+ return 'Hello World';
+ }
+
+ sub iamdynamic($) {
+ my Xerl::Foo:Bla $self = $_[0];
+ return Xerl::Foo::Bla::IAMSTATIC( $self->get_somevalue() );
+ }
+
+- Static private subs start with _ and are written in CAPITAL letters
+
+ sub _IAMSTATICPRIVATE() {
+ .
+ .
+ }
+
+- Use Pidy to automaically restyle the code! (make pidy)
diff --git a/STYLEGUIDE b/STYLEGUIDE
new file mode 100644
index 0000000..e6dd3c9
--- /dev/null
+++ b/STYLEGUIDE
@@ -0,0 +1,71 @@
+Always do:
+
+- Pragmatic modules ALWAYS to use in ALL packages:
+
+ use strict;
+ use warnings;
+
+- Only for packages for including package UNIVERSAL definitions
+
+ use Xerl::Page::Base;
+
+- Object oriented coding style
+
+- Always use method prototypes if possible
+
+ sub foo($;$) { .... }
+
+- Explicit object typing if possible
+
+ my Class::Name::Here $foo = Class::Name::Here->new();
+
+- If no real ret val, set undef; explicitly
+
+ sub foo() {
+ # Do some stuff
+ ...
+ # Set explicit undef ret value
+ return undef;
+ }
+
+- Private subs use _ as its prefix and are called only from the current package.
+
+ package Xerl::Foo::Bla;
+ .
+ .
+
+ sub _iamprivate($) {
+ my Xerl::Foo:Bla $self = $_[0];
+ .
+ .
+ }
+
+ sub iampublic($) {
+ my Xerl::Foo:Bla $self = $_[0];
+ $self->_iamprivate();
+ return undef;
+ }
+
+- Static subs (not OOP) are in CAPITAL letters.
+
+ sub IAMSTATIC($) {
+ print shift;
+ return 'Hello World';
+ }
+
+ sub iamdynamic($) {
+ my Xerl::Foo:Bla $self = $_[0];
+ return Xerl::Foo::Bla::IAMSTATIC( $self->get_somevalue() );
+ }
+
+- Static private subs start with _ and are written in CAPITAL letters
+
+ sub _IAMSTATICPRIVATE() {
+ .
+ .
+ }
+
+- Use Pidy to automaically restyle the code! (make pidy)
+
+- Mark things which are still to do with TODO: at any place in the source
+ tree. (Can be searched for using 'make todo').
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..e28d513
--- /dev/null
+++ b/TODO
@@ -0,0 +1,10 @@
+Hint: Run 'make todo' to see everything in every file what is to do!
+
+TODO: - Caching of config.xml
+TODO: - Documentation of all features/options
+TODO: - Fix <foo><bar></bar></foo> bug
+TODO: - Global conf.txt -> config.xml, host specific config is in XML already
+TODO: - Include new config.xml in config.xml if exists <includeifexists file="foo.xml" />
+TODO: - Inline perl in template.xml!
+TODO: - Login area (cookies are working already)
+TODO: - Rename Plugins -> Extensions
diff --git a/Xerl.pm b/Xerl.pm
new file mode 100644
index 0000000..bade547
--- /dev/null
+++ b/Xerl.pm
@@ -0,0 +1,98 @@
+# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl;
+
+use strict;
+use warnings;
+
+use CGI::Carp 'fatalsToBrowser';
+use Time::HiRes 'gettimeofday';
+
+use Xerl::Base;
+use Xerl::Main::Global;
+use Xerl::Page::Configure;
+use Xerl::Page::Document;
+use Xerl::Page::Parameter;
+use Xerl::Page::Request;
+use Xerl::Page::Templates;
+use Xerl::Plugins::Session;
+
+sub run($) {
+ my Xerl $self = $_[0];
+ my $time = [gettimeofday];
+
+ my Xerl::Page::Request $request =
+ Xerl::Page::Request->new( request => $ENV{REQUEST_URI} );
+
+ $request->parse();
+ my Xerl::Page::Configure $config =
+ Xerl::Page::Configure->new( config => $self->get_config(), %$request );
+
+ $config->parse();
+
+ # TODO: Plugin API
+ unless ( $config->sessionsdisable_exists() ) {
+ my Xerl::Plugins::Session $session =
+ Xerl::Plugins::Session->new( config => $config );
+
+ $session->process();
+ $config->set_session($session);
+ }
+
+ my Xerl::Page::Parameter $parameter =
+ Xerl::Page::Parameter->new( config => $config );
+
+ $parameter->parse();
+
+ if ( $config->document_exists() ) {
+ my Xerl::Page::Document $document =
+ Xerl::Page::Document->new( config => $config );
+
+ $document->parse();
+
+ }
+ else {
+ my Xerl::Page::Templates $templates =
+ Xerl::Page::Templates->new( config => $config );
+
+ $templates->parse();
+ $templates->print($time);
+ }
+
+
+ # This function gets always called if the scripts ends.
+ # The script may also end on another location.
+ Xerl::Main::Global::SHUTDOWN();
+
+ # Never reach this point
+ return undef;
+}
+
+1;
diff --git a/Xerl/.htaccess b/Xerl/.htaccess
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Xerl/.htaccess
diff --git a/Xerl/Base.pm b/Xerl/Base.pm
new file mode 100644
index 0000000..ebb1494
--- /dev/null
+++ b/Xerl/Base.pm
@@ -0,0 +1,130 @@
+# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package UNIVERSAL;
+
+use strict;
+use warnings;
+
+sub new ($;) {
+ my $self = shift;
+
+ bless {@_} => $self;
+}
+
+sub setval($$$) {
+ my UNIVERSAL $self = $_[0];
+
+ $self->{ $_[1] } = $_[2];
+
+ return undef;
+}
+
+sub getval($$) {
+ my UNIVERSAL $self = $_[0];
+
+ return defined $self->{ $_[1] } ? $self->{ $_[1] } : '';
+}
+
+sub exists($$) {
+ my UNIVERSAL $self = $_[0];
+
+ return exists $self->{ $_[1] } ? 1 : 0;
+}
+
+sub AUTOLOAD {
+ my UNIVERSAL $self = $_[0];
+ my $auto = our $AUTOLOAD;
+ return $self if $auto =~ /DESTROY/;
+
+ if ( $auto =~ /.*::set_(.+)$/ ) {
+ $self->{$1} = $_[1];
+
+ }
+ elsif ( $auto =~ /.*::get_(.+)_ref$/ ) {
+ return defined $self->{$1} ? \$self->{$1} : [''];
+
+ }
+ elsif ( $auto =~ /.*::get_(.+)$/ ) {
+ return defined $self->{$1} ? $self->{$1} : '';
+
+ }
+ elsif ( $auto =~ /.*::undef_(.+)$/ ) {
+ return '' unless defined $self->{$1};
+
+ my $retval = $self->{$1};
+ undef $self->{$1};
+ return $retval;
+
+ }
+ elsif ( $auto =~ /.*::append_(.+)$/ ) {
+ if ( defined $self->{$1} ) {
+ $self->{$1} .= $_[1];
+
+ }
+ else {
+ $self->{$1} = $_[1];
+ }
+
+ }
+ elsif ( $auto =~ /.*::push_(.+)$/ ) {
+ if ( exists $self->{$1} ) {
+ push @{ $self->{$1} }, $_[1];
+
+ }
+ else {
+ $self->{$1} = [ $_[1] ];
+ }
+
+ }
+ elsif ( $auto =~ /.*::first_(.+)$/ ) {
+ return exists $self->{$1} ? ${ $self->{$1} }[0] : '';
+
+ }
+ elsif ( $auto =~ /.*::(.+)_exists$/ ) {
+ return exists $self->{$1} ? 1 : 0;
+
+ }
+ elsif ( $auto =~ /.*::(.+)_length$/ ) {
+ return ( ref $self->{$1} eq 'ARRAY' ) ? scalar @{ $self->{$1} } : 0;
+
+ }
+ elsif ( $auto =~ /.*::(.+)_isset$/ ) {
+ return exists $self->{$1} ? $self->{ $_[0] } : 0;
+
+ }
+ else {
+ print "$auto is not a method of $self or UNIVERSAL\n";
+ }
+
+ return $self;
+}
+
+1;
+
diff --git a/Xerl/Main/Global.pm b/Xerl/Main/Global.pm
new file mode 100644
index 0000000..0ca2357
--- /dev/null
+++ b/Xerl/Main/Global.pm
@@ -0,0 +1,97 @@
+# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Main::Global;
+
+sub SHUTDOWN {
+ exit 0;
+
+ # Never reach this point
+ return undef;
+}
+
+sub DEBUG {
+ print 'Debug::', @_, "\n";
+
+ return undef;
+}
+
+sub ERROR {
+ print "Content-Type: text/plain\n\nXerl runtime error: ",
+ join( ' ', time, @_ );
+
+ Xerl::Main::Global::SHUTDOWN();
+
+ # Never reach this point
+ return undef;
+}
+
+sub PLAIN {
+ print "Content-Type: text/plain\n\n";
+
+ DEBUG(@_) if @_;
+
+ return undef;
+}
+
+sub REDIRECT ($) {
+ my $location = shift;
+ print "Status: 301 Moved Permanantly\n";
+ print "Location: $location\n\n";
+
+ Xerl::Main::Global::SHUTDOWN();
+
+ return undef;
+}
+
+sub _HTTP_DESCR ($) {
+ my $status = shift;
+
+ if ( $status == 404 ) {
+ "Status: 404 Not Found\015\012\n\n"
+
+ }
+ else {
+ "Status: 405 Method not allowed\015\012\n\n";
+ }
+}
+
+sub HTTP {
+ my $descr = _HTTP_DESCR(shift);
+ print $descr;
+ local $, = ' ';
+ print $descr;
+
+ Xerl::Main::Global::SHUTDOWN();
+
+ # Never reach this point
+ return undef;
+}
+
+1;
diff --git a/Xerl/Page/Configure.pm b/Xerl/Page/Configure.pm
new file mode 100644
index 0000000..a1a5e74
--- /dev/null
+++ b/Xerl/Page/Configure.pm
@@ -0,0 +1,165 @@
+# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Configure;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::Tools::FileIO;
+use Xerl::XML::Element;
+
+sub parse($) {
+ my Xerl::Page::Configure $self = $_[0];
+
+ my Xerl::Tools::FileIO $file =
+ Xerl::Tools::FileIO->new( 'path' => $self->get_config() );
+
+ $file->fslurp();
+
+ my $re = qr/^(.+?) *=(.+?) *\n?$/;
+
+ for ( @{ $file->get_array() } ) {
+ next if /^ *#/;
+
+ $self->setval( $1, $self->eval($2) ) if $_ =~ $re;
+ }
+
+ return $self;
+}
+
+sub defaults($) {
+ my Xerl::Page::Configure $self = $_[0];
+
+ $self->set_proto('https') if exists $ENV{HTTPS};
+
+ $self->set_site( $self->get_defaultcontent() )
+ unless $self->site_exists();
+
+ $self->set_nsite( $self->get_site() =~ /^(?:\d*\.)?(.*)/ );
+
+ $self->set_template( $self->get_defaulttemplate() )
+ unless $self->template_exists();
+
+ $self->set_style( $self->get_defaultstyle() )
+ unless $self->style_exists();
+
+ $self->set_proto( $self->get_defaultproto() )
+ unless $self->proto_exists();
+
+ $self->set_host( lc $ENV{HTTP_HOST} )
+ unless $self->host_exists();
+
+ unless ( -d $self->get_hostroot() . $self->get_host() ) {
+ my $redirect = $self->get_hostroot() . 'redirect:' . $self->get_host();
+ if ( -f $redirect ) {
+ my Xerl::Tools::FileIO $file =
+ Xerl::Tools::FileIO->new( 'path' => $redirect );
+ $file->fslurp();
+ my $location = $file->shift();
+ Xerl::Main::Global::REDIRECT($location);
+ }
+ my $alias = $self->get_hostroot() . 'alias:' . $self->get_host();
+ if ( -f $alias ) {
+ my Xerl::Tools::FileIO $file =
+ Xerl::Tools::FileIO->new( 'path' => $alias );
+ $file->fslurp();
+ $self->set_host( $file->shift() );
+ }
+ }
+
+ $self->set_outputformat( $self->get_defaultoutputformat() )
+ unless $self->outputformat_exists();
+
+ if ( $self->format_exists() ) {
+ $self->set_outputformat( $self->get_format() );
+ $self->set_template( $self->get_format() );
+ $self->set_site( $self->get_format() );
+ $self->set_nocache(1)
+ if $self->get_format() =~ /\.feed$/;
+ }
+
+ $self->set_host( $self->getval( $self->get_host() ) )
+ if $self->exists( $self->get_host() );
+
+ $self->set_host( $self->getval( $self->get_host() ) )
+ if $self->exists( $self->get_host() );
+
+ my $request_subdir = $self->get_request_subdir();
+ $self->set_hostpath(
+ $self->get_hostroot() . $self->get_host() . $request_subdir . "/" );
+
+ $self->set_defaulthostpath(
+ $self->get_hostroot() . $self->get_defaulthost() . '/' );
+
+ $self->set_cachepath(
+ $self->get_cacheroot() . $self->get_host() . $request_subdir . '/' );
+
+ $self->set_htdocspath( $self->get_hostpath() . 'htdocs/' );
+
+ $self->set_templatespath( $self->get_hostpath() . 'templates/' );
+
+ $self->set_contentpath( $self->get_hostpath() . 'content/' );
+
+ return undef;
+}
+
+sub eval($$) {
+ my Xerl::Page::Configure $self = $_[0];
+ my $val = $_[1];
+
+ $val =~ s/^!(.+)/`$1`/eo;
+ return $val;
+}
+
+sub insertxmlvars($$) {
+ my Xerl::Page::Configure $self = $_[0];
+ my Xerl::XML::Element $element = $_[1];
+
+ $element = $element->starttag('variables');
+
+ return $self
+ unless defined $element
+ or $element->get_array() eq 'ARRAY';
+
+ my $text;
+ for ( @{ $element->get_array() } ) {
+ $text = $_->get_text();
+ chomp $text;
+
+ $text =~ s/%%(.*?)%%/$self->getval($1)/eg;
+ $self->setval( $_->get_name(), $text );
+ }
+
+ return $self;
+}
+
+1;
+
diff --git a/Xerl/Page/Content.pm b/Xerl/Page/Content.pm
new file mode 100644
index 0000000..bea97c7
--- /dev/null
+++ b/Xerl/Page/Content.pm
@@ -0,0 +1,226 @@
+# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Content;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+
+use Xerl::XML::Reader;
+use Xerl::XML::Element;
+use Xerl::Page::Rules;
+use Xerl::Page::Configure;
+
+sub parse($) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ my Xerl::XML::Reader $xmlcontent = Xerl::XML::Reader->new(
+ path => $config->get_templatepath(),
+ config => $config
+ );
+
+ $xmlcontent->open();
+ $xmlcontent->parse();
+
+ my Xerl::Page::Rules $rules = Xerl::Page::Rules->new( config => $config );
+ $rules->parse( $config->get_xmlconfigrootobj() )
+ unless $config->exists('noparse');
+
+ $config->insertxmlvars( $config->get_xmlconfigrootobj() );
+ $self->insertrules( $rules, $xmlcontent->get_root() );
+
+ return undef;
+}
+
+sub insertrules($$$$) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Rules $rules = $_[1];
+ my Xerl::XML::Element $element = $_[2];
+
+ # Start inserting rules at <content>
+ $element = $element->starttag('content');
+
+ # If there is no <content>-tag, dont use a rule!
+ return unless defined $element;
+
+ my @content;
+ my $params = $element->get_params();
+
+ unshift @content, "Content-Type: $params->{type}\n\n"
+ if ref $params eq 'HASH' and exists $params->{type};
+
+ push @content, $self->_insertrules( $rules, $element );
+ $self->set_content( \@content );
+
+ return undef;
+}
+
+sub _insertrules($$$) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Rules $rules = $_[1];
+ my Xerl::XML::Element $element = $_[2];
+ my Xerl::Page::Configure $config = $self->get_config();
+ my $nonewlines = 0;
+
+ #$element->print();
+ #
+ # Don't interate through the XML childs if we have a leaf node.
+ return () unless ref $element->get_array() eq 'ARRAY';
+ my ( $name, $rule, @content, $text, $params );
+
+ for my $succ ( @{ $element->get_array() } ) {
+ $name = $succ->get_name();
+ $text = $succ->get_text();
+ $params = $succ->get_params();
+
+ # Remove leading and ending whitespaces, also ending newlines.
+ $text =~ s/^ *(.*)( |\n)*$/$1/g;
+ unless ( ref( $rule = $rules->getval($name) ) eq 'ARRAY' ) {
+ if ( lc $name eq 'noop' ) {
+ if ( ref $succ->get_array() eq 'ARRAY' ) {
+ push @content, $self->_insertrules( $rules, $succ );
+
+ }
+ else {
+ push @content, "$text\n";
+ }
+
+ }
+ elsif ( lc $name eq 'tag' ) {
+ push @content, "<$text>\n";
+
+ }
+ elsif ( lc $name eq 'perl' ) {
+
+ # Perl content will be interpreted by Xerl::Page::Templates::print later
+ push @content, '<perl>', $text, '</perl>';
+
+ }
+ elsif ( lc $name eq 'navigation' ) {
+ my $menus = $config->get_menuobj()->get_array();
+
+ if ( ref $menus eq 'ARRAY' ) {
+ push @content, $self->_insertrules( $rules, $_ )
+ for @$menus;
+ }