From 4998381b7a45529502ad0a9432de4df932ba6ad2 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 14:25:02 +0200 Subject: disable sessions by default --- Xerl.pm | 1 - config.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Xerl.pm b/Xerl.pm index 12f6095..6abd615 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -58,7 +58,6 @@ sub run($) { $config->parse(); return undef if $config->finish_request_exists(); - # TODO: Plugin API unless ( $config->sessionsdisable_exists() ) { my Xerl::Plugins::Session $session = Xerl::Plugins::Session->new( config => $config ); diff --git a/config.txt b/config.txt index c87afb6..a3a98e1 100644 --- a/config.txt +++ b/config.txt @@ -22,4 +22,5 @@ hidesubhome=1 hostroot=/usr/local/www/xerlhosts/branches/stable/hosts/ statsroot=/usr/local/www/xerlstats/ hyperion.buetow.org=ssl.buetow.org +sessiondisable=1 404=http://www.buetow.org -- cgit v1.2.3 From dc3d6277fd08ab70f2f7c3cf8df6fe785ba61cf6 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 14:27:15 +0200 Subject: new brainstorming --- TODO | 5 ----- 1 file changed, 5 deletions(-) diff --git a/TODO b/TODO index e28d513..6244cec 100644 --- a/TODO +++ b/TODO @@ -3,8 +3,3 @@ 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 bug -TODO: - Global conf.txt -> config.xml, host specific config is in XML already -TODO: - Include new config.xml in config.xml if exists -TODO: - Inline perl in template.xml! -TODO: - Login area (cookies are working already) -TODO: - Rename Plugins -> Extensions -- cgit v1.2.3 From 6a10e933c16378307d389f8b7d78af887476cacd Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 14:29:16 +0200 Subject: new brainstorming --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 6244cec..b403300 100644 --- a/TODO +++ b/TODO @@ -3,3 +3,4 @@ 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 bug +TODO: - Rename config.txt into xerl.conf -- cgit v1.2.3 From 84940ae5e4d0f603f0eb2df51e3a24f2e2da3d24 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 14:40:08 +0200 Subject: add info msg --- Xerl/Main/Global.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Xerl/Main/Global.pm b/Xerl/Main/Global.pm index a6582b1..6672ef0 100644 --- a/Xerl/Main/Global.pm +++ b/Xerl/Main/Global.pm @@ -67,15 +67,17 @@ sub REDIRECT ($) { return undef; } -sub _HTTP_DESCR ($) { - my $status = shift; +sub _HTTP_DESCR ($;$) { + my ($status, $infomsg) = @_; + + $infomsg //= ''; if ( $status == 404 ) { - "Status: 404 Not Found\015\012\n\n" + "Status: 404 Not Found $infomsg\015\012\n\n" } else { - "Status: 405 Method not allowed\015\012\n\n"; + "Status: 405 Method not allowed $infomsg\015\012\n\n"; } } -- cgit v1.2.3 From da938a661f38c6740f41e6fd585c2f2054ebc0c0 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 14:55:22 +0200 Subject: add configdev config --- Xerl/Page/Templates.pm | 1 + configdev-pluto.buetow.org.txt | 24 ++++++++++++++++++++++++ index.pl | 5 +++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 configdev-pluto.buetow.org.txt diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm index 53e2a12..8b7c6d1 100644 --- a/Xerl/Page/Templates.pm +++ b/Xerl/Page/Templates.pm @@ -97,6 +97,7 @@ sub parse($) { $config->set_finish_request(1); return undef; } + $xmlconfigreader->parse(); $config->set_xmlconfigrootobj( $xmlconfigreader->get_root() ); diff --git a/configdev-pluto.buetow.org.txt b/configdev-pluto.buetow.org.txt new file mode 100644 index 0000000..f347af8 --- /dev/null +++ b/configdev-pluto.buetow.org.txt @@ -0,0 +1,24 @@ +# TODO: Allow comments behind the options! +# defaultproto will be used if not ENV(HTTPS)==on +#nocache=defined +#nocache=1 +cacheroot=/home/pb/xerl/cache +cookievals=nocache,plain,devel,style,template +sessiondisable=1 +ctype.asc=text/plain +ctype.css=text/css +ctype.jpg=image/jpg +ctype.pdf=application/pdf +ctype.png=image/png +ctype.txt=text/plain +ctype.xml=text/plain +defaultcontent=home +defaulthost=default +defaultoutputformat=xhtml +defaultproto=http +defaultstyle=default.css +defaulttemplate=xhtml +hidesubhome=1 +hostroot=/home/pb/xerl/hosts/ +statsroot=/home/pb/xerl/stats/ +404=http://www.buetow.org diff --git a/index.pl b/index.pl index 985af29..4442648 100755 --- a/index.pl +++ b/index.pl @@ -9,8 +9,9 @@ use Socket; use Sys::Hostname; my $host = hostname(); -my $config = -e "config-$host.txt" ? "config-$host.txt" : 'config.txt'; +my $config = -e "configdev-$host.txt" ? "configdev-$host.txt" : ( + -e "config-$host.txt" ? "config-$host.txt" : 'config.txt' +); my Xerl $xerl = Xerl->new( config => $config ); $xerl->run(); - -- cgit v1.2.3 From f8a84bc3c997ec43d500666327ecd8417f31a097 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:06:50 +0200 Subject: foo --- configdev-pluto.buetow.org.txt | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 configdev-pluto.buetow.org.txt diff --git a/configdev-pluto.buetow.org.txt b/configdev-pluto.buetow.org.txt deleted file mode 100644 index f347af8..0000000 --- a/configdev-pluto.buetow.org.txt +++ /dev/null @@ -1,24 +0,0 @@ -# TODO: Allow comments behind the options! -# defaultproto will be used if not ENV(HTTPS)==on -#nocache=defined -#nocache=1 -cacheroot=/home/pb/xerl/cache -cookievals=nocache,plain,devel,style,template -sessiondisable=1 -ctype.asc=text/plain -ctype.css=text/css -ctype.jpg=image/jpg -ctype.pdf=application/pdf -ctype.png=image/png -ctype.txt=text/plain -ctype.xml=text/plain -defaultcontent=home -defaulthost=default -defaultoutputformat=xhtml -defaultproto=http -defaultstyle=default.css -defaulttemplate=xhtml -hidesubhome=1 -hostroot=/home/pb/xerl/hosts/ -statsroot=/home/pb/xerl/stats/ -404=http://www.buetow.org -- cgit v1.2.3 From 366c463a2265ac3360286aa8450c721c3c28a60b Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:07:51 +0200 Subject: fix --- Xerl.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Xerl.pm b/Xerl.pm index 6abd615..e61c58b 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -42,7 +42,6 @@ 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]; @@ -58,10 +57,10 @@ sub run($) { $config->parse(); return undef if $config->finish_request_exists(); - unless ( $config->sessionsdisable_exists() ) { - my Xerl::Plugins::Session $session = - Xerl::Plugins::Session->new( config => $config ); + my Xerl::Plugins::Session $session = + Xerl::Plugins::Session->new( config => $config ); + unless ( $config->sessionsdisable_exists() ) { $session->process(); $config->set_session($session); } -- cgit v1.2.3 From 5aeb8c969a65fd2abf0d9f3dd4d010a7a3b558bd Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:09:12 +0200 Subject: fix --- Xerl.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/Xerl.pm b/Xerl.pm index e61c58b..6fbc6d1 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -42,6 +42,7 @@ 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]; -- cgit v1.2.3 From 30221aa2a5ba578e21cf2fd99748d59c23fede39 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:21:06 +0200 Subject: remove cookies/sessions --- Xerl.pm | 10 +--- Xerl/Page/Templates.pm | 1 - Xerl/Plugins/Session.pm | 127 ------------------------------------------------ config.txt | 1 - 4 files changed, 2 insertions(+), 137 deletions(-) delete mode 100644 Xerl/Plugins/Session.pm diff --git a/Xerl.pm b/Xerl.pm index 6fbc6d1..cc10ea0 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -42,7 +42,6 @@ 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]; @@ -58,13 +57,7 @@ sub run($) { $config->parse(); return undef if $config->finish_request_exists(); - my Xerl::Plugins::Session $session = - Xerl::Plugins::Session->new( config => $config ); - - unless ( $config->sessionsdisable_exists() ) { - $session->process(); - $config->set_session($session); - } + $config->defaults(); my Xerl::Page::Parameter $parameter = Xerl::Page::Parameter->new( config => $config ); @@ -72,6 +65,7 @@ sub run($) { $parameter->parse(); return undef if $config->finish_request_exists(); + if ( $config->document_exists() ) { my Xerl::Page::Document $document = Xerl::Page::Document->new( config => $config ); diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm index 8b7c6d1..7c31a27 100644 --- a/Xerl/Page/Templates.pm +++ b/Xerl/Page/Templates.pm @@ -84,7 +84,6 @@ sub parse($) { } else { - my $xmlconfigpath = $config->get_hostpath() . 'config.xml'; $xmlconfigpath = $config->get_defaulthostpath() . 'config.xml' diff --git a/Xerl/Plugins/Session.pm b/Xerl/Plugins/Session.pm deleted file mode 100644 index 2ecc9b0..0000000 --- a/Xerl/Plugins/Session.pm +++ /dev/null @@ -1,127 +0,0 @@ -# Xerl (c) 2005-2011, 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 buetow.org 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::Plugins::Session; - -use strict; -use warnings; - -use CGI; -use CGI::Session; - -use Xerl::Base; -use Xerl::Main::Global; -use Xerl::Page::Configure; - -sub process($) { - my Xerl::Plugins::Session $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); - - my CGI $cgi = CGI->new(); - - my CGI::Session $session = do { - my $cookie = $cgi->cookie( -name => 'session' ); - $cookie ? $self->_get_session($cookie) : $self->_create_session(); - }; - - $self->set_session($session); - - my @cookievals = split ',', $config->get_cookievals(); - my @ignore = $self->_store_cookie_vals( \@cookievals ); - $self->_restore_cookie_vals( \@cookievals, \@ignore ); - $config->defaults(); - - my ( $sessionid, $host ) = ( $session->id(), $config->get_host() ); - print "Set-Cookie: session=$sessionid; domain=$host; path=/\n"; - - return undef; -} - -sub _create_session($) { - my Xerl::Plugins::Session $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); - - return CGI::Session->new( 'driver:File', undef ); -} - -sub _get_session($$) { - my Xerl::Plugins::Session $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); - my $cookie = $_[1]; - - CGI::Session->name($cookie); - return CGI::Session->new( 'driver:File', $cookie ); -} - -sub _store_cookie_vals($$) { - my Xerl::Plugins::Session $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); - my CGI::Session $session = $self->get_session(); - my $cookievals = $_[1]; - - my @set; - - for my $key (@$cookievals) { - if ( $config->exists($key) ) { - my $val = $config->getval($key); - $session->param( $key => $val ); - push @set, $key; - - } - elsif ( $config->exists("not$key") ) { - $session->clear($key); - push @set, "not$key"; - } - } - - return grep !/\.feed/, @set; -} - -sub _restore_cookie_vals($$$) { - my Xerl::Plugins::Session $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); - my CGI::Session $session = $self->get_session(); - my ( $cookievals, $ignore ) = @_[ 1 .. 2 ]; - - KEY: for my $key (@$cookievals) { - for my $ig (@$ignore) { - next KEY if $key eq $ig; - } - - if ( defined( my $val = $session->param($key) ) ) { - $val =~ s#/\.\.##g; - $config->setval( $key => $val ) if $val; - } - } - - return undef; -} - -1; - diff --git a/config.txt b/config.txt index a3a98e1..c87afb6 100644 --- a/config.txt +++ b/config.txt @@ -22,5 +22,4 @@ hidesubhome=1 hostroot=/usr/local/www/xerlhosts/branches/stable/hosts/ statsroot=/usr/local/www/xerlstats/ hyperion.buetow.org=ssl.buetow.org -sessiondisable=1 404=http://www.buetow.org -- cgit v1.2.3 From 000ef5277dbb4cd12959d59530cdc1fd1182d959 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:22:18 +0200 Subject: new brainstorming --- TODO | 1 - 1 file changed, 1 deletion(-) diff --git a/TODO b/TODO index b403300..1a0ed4b 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ 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 bug TODO: - Rename config.txt into xerl.conf -- cgit v1.2.3 From f7e49d8f7e7d4b68e44fe8b29baa57921893bf96 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:25:30 +0200 Subject: enhance replace.sh --- scripts/replace.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/replace.sh b/scripts/replace.sh index c6f9d4c..3520624 100755 --- a/scripts/replace.sh +++ b/scripts/replace.sh @@ -1,6 +1,3 @@ #!/bin/sh -sed "s/$2/$3/g" $1 > temp -mv -f temp $1 - - +exec sed -i "s/$2/$3/g" $1 -- cgit v1.2.3 From 48dbcd72995845b1e9d6fb69bdccf196c15234ef Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:26:18 +0200 Subject: enhance replace.sh --- scripts/mreplace.sh | 3 +-- scripts/replace.sh | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100755 scripts/replace.sh diff --git a/scripts/mreplace.sh b/scripts/mreplace.sh index 1ef5cc4..32f2c17 100755 --- a/scripts/mreplace.sh +++ b/scripts/mreplace.sh @@ -5,8 +5,7 @@ do for i in `find . -name "*.$j"` do echo $i - sed "s/$1/$2/g" $i > temp - mv -f temp $i + sed -i "s/$1/$2/g" $i > temp done done diff --git a/scripts/replace.sh b/scripts/replace.sh deleted file mode 100755 index 3520624..0000000 --- a/scripts/replace.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec sed -i "s/$2/$3/g" $1 -- cgit v1.2.3 From 3dc7fe892fb0d8910c56624599058b170a573af2 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:27:24 +0200 Subject: modify copyright header --- Xerl.pm | 2 +- Xerl/Base.pm | 2 +- Xerl/Main/Global.pm | 2 +- Xerl/Page/Configure.pm | 2 +- Xerl/Page/Content.pm | 2 +- Xerl/Page/Document.pm | 2 +- Xerl/Page/Menu.pm | 2 +- Xerl/Page/Parameter.pm | 2 +- Xerl/Page/Request.pm | 2 +- Xerl/Page/Rules.pm | 2 +- Xerl/Page/Templates.pm | 2 +- Xerl/Tools/FileIO.pm | 2 +- Xerl/XML/Element.pm | 2 +- Xerl/XML/Reader.pm | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Xerl.pm b/Xerl.pm index cc10ea0..648a24d 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Base.pm b/Xerl/Base.pm index ddaf918..53368a9 100644 --- a/Xerl/Base.pm +++ b/Xerl/Base.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Main/Global.pm b/Xerl/Main/Global.pm index 6672ef0..83beb73 100644 --- a/Xerl/Main/Global.pm +++ b/Xerl/Main/Global.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Configure.pm b/Xerl/Page/Configure.pm index d527b2b..dfe4ec4 100644 --- a/Xerl/Page/Configure.pm +++ b/Xerl/Page/Configure.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Content.pm b/Xerl/Page/Content.pm index e404430..da70139 100644 --- a/Xerl/Page/Content.pm +++ b/Xerl/Page/Content.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Document.pm b/Xerl/Page/Document.pm index e5a16fe..bb58016 100644 --- a/Xerl/Page/Document.pm +++ b/Xerl/Page/Document.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Menu.pm b/Xerl/Page/Menu.pm index c0dcde3..0ba9568 100644 --- a/Xerl/Page/Menu.pm +++ b/Xerl/Page/Menu.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Parameter.pm b/Xerl/Page/Parameter.pm index 47e1d28..72c44c9 100644 --- a/Xerl/Page/Parameter.pm +++ b/Xerl/Page/Parameter.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Request.pm b/Xerl/Page/Request.pm index 4493be3..94c6037 100644 --- a/Xerl/Page/Request.pm +++ b/Xerl/Page/Request.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Rules.pm b/Xerl/Page/Rules.pm index e61d000..4a08d19 100644 --- a/Xerl/Page/Rules.pm +++ b/Xerl/Page/Rules.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm index 7c31a27..e706840 100644 --- a/Xerl/Page/Templates.pm +++ b/Xerl/Page/Templates.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/Tools/FileIO.pm b/Xerl/Tools/FileIO.pm index c0e1e0e..807cb10 100644 --- a/Xerl/Tools/FileIO.pm +++ b/Xerl/Tools/FileIO.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/XML/Element.pm b/Xerl/XML/Element.pm index 33b58e7..13c963f 100644 --- a/Xerl/XML/Element.pm +++ b/Xerl/XML/Element.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # diff --git a/Xerl/XML/Reader.pm b/Xerl/XML/Reader.pm index 7b5f8d4..2562fea 100644 --- a/Xerl/XML/Reader.pm +++ b/Xerl/XML/Reader.pm @@ -1,4 +1,4 @@ -# Xerl (c) 2005-2011, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # # E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # -- cgit v1.2.3 From b8b183de719931e6d95c99a4aa2a697435c0fb1d Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:27:53 +0200 Subject: new brainstorming --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 1a0ed4b..51acded 100644 --- a/TODO +++ b/TODO @@ -3,3 +3,4 @@ Hint: Run 'make todo' to see everything in every file what is to do! TODO: - Documentation of all features/options TODO: - Fix bug TODO: - Rename config.txt into xerl.conf +TODO: - Remove logging -- cgit v1.2.3 From d53f89f0f82527e010a5a194b9977556c68f8b1e Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:28:27 +0200 Subject: remove obsolete scripts --- scripts/modules/file.pm | 54 ---------------------------- scripts/stats.pl | 92 ------------------------------------------------ scripts/stats/calc.sh | 38 -------------------- scripts/stats/clean.sh | 49 -------------------------- scripts/stats/replace.sh | 11 ------ scripts/stats/stats.sh | 61 -------------------------------- 6 files changed, 305 deletions(-) delete mode 100644 scripts/modules/file.pm delete mode 100644 scripts/stats.pl delete mode 100755 scripts/stats/calc.sh delete mode 100755 scripts/stats/clean.sh delete mode 100755 scripts/stats/replace.sh delete mode 100755 scripts/stats/stats.sh diff --git a/scripts/modules/file.pm b/scripts/modules/file.pm deleted file mode 100644 index 4727f8e..0000000 --- a/scripts/modules/file.pm +++ /dev/null @@ -1,54 +0,0 @@ -# Xerl Copyright (c) 2005 2006 2007 2008, Paul Buetow (http://www.buetow.org) -# -# 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 buetow.org 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 BY Paul 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 SHALL Paul 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. - -sub dopen { - my $shift = shift; - opendir DIR, $shift or die "$shift: $!\n"; - my @dir = readdir(DIR); - closedir DIR; - return @dir; -} - -sub fopen { - my $shift = shift; - open FILE, $shift or die "$shift: $!\n"; - my @file = ; - close FILE; - return @file; -} - -sub fwrite { - my $shift = shift; - my @file = @_; - open FILE, ">$shift" or die "$shift: $!\n"; - print FILE @file; - close FILE; -} - -1; diff --git a/scripts/stats.pl b/scripts/stats.pl deleted file mode 100644 index 425261f..0000000 --- a/scripts/stats.pl +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/perl - -# The yChat Project (2003, 2004) -# The Xerl Project (2005, 2006) -# -# This script generates source code and project statistics - -use strict; - -use scripts::modules::file; - -my %stats; -my $param = shift; - -recursive('.'); - -$stats{"Lines total"} = - $stats{"Lines of source"} + - $stats{"Lines of scripts"} + - $stats{"Lines of text"} + - $stats{"Lines of CSS"} + - $stats{"Lines of XML"}; - -unless ( defined $param ) { - print "$_ = " . $stats{$_} . "\n" for sort keys %stats; - -} -else { - print $stats{$_} . ' ' for sort keys %stats; -} - -print "\n"; - -sub recursive { - my $shift = shift; - return unless -d $shift; - my @dir = dopen($shift); - - foreach (@dir) { - next if /^\.$/o or /^\.{2}$/o; - - if ( -f "$shift/$_" ) { - ++$stats{"Number of files total"}; - filestats("$shift/$_"); - - } - elsif ( -d "$shift/$_" ) { - ++$stats{"Number of dirs total"}; - recursive("$shift/$_"); - } - } -} - -sub filestats { - my $shift = shift; - if ( $shift =~ /\.(cpp|h|tmpl)$/o ) { - ++$stats{"Number of source files"}; - $stats{"Lines of source"} += countlines($shift); - - } - elsif ( $shift =~ /\.css$/o ) { - ++$stats{"Number of CSS files"}; - $stats{"Lines of CSS"} += countlines($shift); - - } - elsif ( $shift =~ /\.(gif|png|jpg)$/o ) { - ++$stats{"Number of gfx files"}; - - } - elsif ( $shift =~ /(\.xml)$/o ) { - ++$stats{"Number of XML files"}; - $stats{"Lines of XML"} += countlines($shift); - - } - elsif ( $shift =~ /(\.pl|\.pm|\.sh|configure.*|Makefile.*)$/o ) { - ++$stats{"Number of script files"}; - $stats{"Lines of scripts"} += countlines($shift); - - } - elsif ( $shift =~ /(\.txt|[A-Z]+)$/o ) { - ++$stats{"Number of text files"}; - $stats{"Lines of text"} += countlines($shift); - - } - elsif ( $shift =~ /\.so$/o ) { - ++$stats{"Number of compiled module files"}; - } -} - -sub countlines { - return scalar fopen shift; -} diff --git a/scripts/stats/calc.sh b/scripts/stats/calc.sh deleted file mode 100755 index 85e5e85..0000000 --- a/scripts/stats/calc.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# By Paul C. Buetow (http://www.buetow.org) - -perl=' - /.*? (.*?) (.*?) /o - && ++$ip{$2}{$1} && ++$p{$1} - && ++$h{$2} && ++$t - for <>; - $l = do { $_ = length $t; $_ < 4 ? 4 : $_ }; - printf " # %$l"."s%4s %$l"."s%4s %24s\n", - "HITS", "%", "UNIQ", "%", "SITE ADDRESS"; - printf "%2.d %$l.d%4.f %$l.d%4.f %24s\n", - ++$i, $h{$_}, 100*$h{$_}/$t, - ($n = keys %{$ip{$_}}), 100*$n/(keys %p),$_ - and $i==15 && last - for sort { $h{$b} <=> $h{$a} } keys %h' - -ls=`ls *.log` -cat << STATS | less -Weekly top list: - -`echo "$ls" | tail -n 7 | xargs cat | perl -e "$perl"` - -Monthly top list: - -`echo "$ls" | tail -n 28 | xargs cat | perl -e "$perl"` - -Yearly top list: - -`echo "$ls" | tail -n 356 | xargs cat | perl -e "$perl"` - -Forever top list: - -`echo "$ls" | xargs cat | perl -e "$perl"` - -This stats are powered by Perl, GNU AWK and Bourne Shell -STATS - diff --git a/scripts/stats/clean.sh b/scripts/stats/clean.sh deleted file mode 100755 index ba0f0e8..0000000 --- a/scripts/stats/clean.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -# 2006 - 2008 The Xerl Project - -for log in *.log -do - re='' - for remove in \ - Charlotte \ - Exabot \ - Mnogo \ - Netcraft \ - Perl \ - Python \ - SurveyBot \ - VoilaBot \ - Yandex \ - Yeti \ - ajSitemap \ - archiver \ - crawler \ - feed \ - findlinks \ - fulltext \ - googlebot \ - grabber \ - jeeves \ - msnbot \ - pear \ - pingdom \ - rss2 \ - sagool \ - sbider \ - slurp \ - spider \ - tagsdir \ - validator \ - walhello \ - ;do - if [ -z "$re" ] - then - re="($remove)" - else - re="$re|($remove)" - fi - done - grep -E -i -v "$re" $log > $log.new - mv -f $log.new $log -done diff --git a/scripts/stats/replace.sh b/scripts/stats/replace.sh deleted file mode 100755 index 1624364..0000000 --- a/scripts/stats/replace.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -from="vs.buetow.org" -to="vs-sim.buetow.org" - -for log in *.log -do - sed "s/$from/$to/" $log > $log.new - mv -f $log.new $log -done - diff --git a/scripts/stats/stats.sh b/scripts/stats/stats.sh deleted file mode 100755 index 0f1c070..0000000 --- a/scripts/stats/stats.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh - -# 2007 (C) Paul C. Buetow (http://paul.buetow.org) - -if [ "$1" != "xerl" ] -then - perl=' - /.*? (.*?) (.*?) /o - && ++$ip{$2}{$1} && ++$p{$1} - && ++$h{$2} && ++$t - for <>; - $l = do { $_ = length $t; $_ < 4 ? 4 : $_ }; - printf " # %$l"."s%4s %$l"."s%4s %24s\n", - "HITS", "%", "UNIQ", "%", "SITE ADDRESS"; - printf "%2.d %$l.d%4.f %$l.d%4.f %24s\n", - ++$i, $h{$_}, 100*$h{$_}/$t, - ($n = keys %{$ip{$_}}), 100*$n/(keys %p),$_ - and $i==20 && last - for sort { $h{$b} <=> $h{$a} } keys %h' -else - perl=' - /.*? (.*?) (.*?) /o - && ++$ip{$2}{$1} && ++$p{$1} - && ++$h{$2} && ++$t - for <>; - $l = do { $_ = length $t; $_ < 4 ? 4 : $_ }; - printf "%02.d %0$l.d %02.f %0$l.d %02.f %24s\n", - ++$i, $h{$_}, 100*$h{$_}/$t, - ($n = keys %{$ip{$_}}), 100*$n/(keys %p), "!!URL(http://$_)!!" - and $i==20 && last - for sort { $h{$b} <=> $h{$a} } keys %h' -fi - -#./clean.sh - -ls=`ls $path*.log` - -cat << STATS -No IP addresses are being logged by Xerl! - - -Yesterdays top list (pos, total hits, total %, unique hits, unique %): - -`echo "$ls" | tail -n 2 | head -n 1 | xargs cat | perl -e "$perl"` - -Last 7 days top list (pos, total hits, total %, unique hits, unique %): - -`echo "$ls" | tail -n 8 | head -n 7 | xargs cat | perl -e "$perl"` - -Last 30 days top list (pos, total hits, total %, unique hits, unique %): - -`echo "$ls" | tail -n 31 | head -n 30 | xargs cat | perl -e "$perl"` - -Last 365 days top list (pos, total hits, total %, unique hits, unique %): - -`echo "$ls" | tail -n 366 | head -n 365 | xargs cat | perl -e "$perl"` - -Overall top list (pos, total hits, total %, unique hits, unique %): - -`echo "$ls" | xargs cat | perl -e "$perl"` -STATS -- cgit v1.2.3 From 65b3c6841f3fcddaedcef9b2ad6b46c35dd61839 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 15:28:53 +0200 Subject: remove obsolete scripts --- scripts/mreplace.sh | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100755 scripts/mreplace.sh diff --git a/scripts/mreplace.sh b/scripts/mreplace.sh deleted file mode 100755 index 32f2c17..0000000 --- a/scripts/mreplace.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -for j in pm pl xml txt css -do - for i in `find . -name "*.$j"` - do - echo $i - sed -i "s/$1/$2/g" $i > temp - done -done - -- cgit v1.2.3 From e9b840ee20c12f9b5698eb1403ce38eb18ead62f Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 17:44:24 +0200 Subject: rename config.txt into xerl.conf --- Makefile | 4 ++-- config.txt | 25 ------------------------- index.fpl | 4 +++- index.pl | 4 ++-- xerl.conf | 25 +++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 30 deletions(-) delete mode 100644 config.txt create mode 100644 xerl.conf diff --git a/Makefile b/Makefile index 6bfaecf..2151b3e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ clean: stats: clean perl scripts/stats.pl replace: - for i in index.pl Xerl.pm config.txt; \ + for i in index.pl Xerl.pm xerl.conf; \ do \ sed -n "s/$(FROM)/$(INTO)/g; \ w .tmp" $$i && mv -f .tmp $$i; \ @@ -23,7 +23,7 @@ pidy: find . -name \*.pm | xargs perltidy -b find . -name \*.bak | xargs rm -f todo: - grep -R TODO . | grep -v Makefile | grep -v .svn + grep -R TODO . | grep -v Makefile | grep -v .git warn: perl index.pl 2> warnings less warnings diff --git a/config.txt b/config.txt deleted file mode 100644 index c87afb6..0000000 --- a/config.txt +++ /dev/null @@ -1,25 +0,0 @@ -# TODO: Allow comments behind the options! -# defaultproto will be used if not ENV(HTTPS)==on -#nocache=defined -#nocache=1 -cacheroot=/usr/local/www/xerlcache/ -cookievals=nocache,plain,devel,style,template -ctype.asc=text/plain -ctype.css=text/css -ctype.jpg=image/jpg -ctype.pdf=application/pdf -ctype.png=image/png -ctype.txt=text/plain -ctype.xml=text/plain -defaultcontent=home -defaulthost=default -defaultoutputformat=xhtml -defaultproto=http -defaultstyle=default.css -defaulttemplate=xhtml -dslvpnrouter.buetow.org=vpndslrouter.buetow.org -hidesubhome=1 -hostroot=/usr/local/www/xerlhosts/branches/stable/hosts/ -statsroot=/usr/local/www/xerlstats/ -hyperion.buetow.org=ssl.buetow.org -404=http://www.buetow.org diff --git a/index.fpl b/index.fpl index a7d41b4..3ac017c 100755 --- a/index.fpl +++ b/index.fpl @@ -10,7 +10,9 @@ use Socket; use Sys::Hostname; my $host = hostname(); -my $config = -e "config-$host.txt" ? "config-$host.txt" : 'config.txt'; +my $config = -e "xerldev-$host.conf" ? "xerldev-$host.conf" : ( + -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' +); while (FCGI::accept >= 0) { my Xerl $xerl = Xerl->new( config => $config ); diff --git a/index.pl b/index.pl index 4442648..f1f5531 100755 --- a/index.pl +++ b/index.pl @@ -9,8 +9,8 @@ use Socket; use Sys::Hostname; my $host = hostname(); -my $config = -e "configdev-$host.txt" ? "configdev-$host.txt" : ( - -e "config-$host.txt" ? "config-$host.txt" : 'config.txt' +my $config = -e "xerldev-$host.conf" ? "xerldev-$host.conf" : ( + -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' ); my Xerl $xerl = Xerl->new( config => $config ); diff --git a/xerl.conf b/xerl.conf new file mode 100644 index 0000000..c87afb6 --- /dev/null +++ b/xerl.conf @@ -0,0 +1,25 @@ +# TODO: Allow comments behind the options! +# defaultproto will be used if not ENV(HTTPS)==on +#nocache=defined +#nocache=1 +cacheroot=/usr/local/www/xerlcache/ +cookievals=nocache,plain,devel,style,template +ctype.asc=text/plain +ctype.css=text/css +ctype.jpg=image/jpg +ctype.pdf=application/pdf +ctype.png=image/png +ctype.txt=text/plain +ctype.xml=text/plain +defaultcontent=home +defaulthost=default +defaultoutputformat=xhtml +defaultproto=http +defaultstyle=default.css +defaulttemplate=xhtml +dslvpnrouter.buetow.org=vpndslrouter.buetow.org +hidesubhome=1 +hostroot=/usr/local/www/xerlhosts/branches/stable/hosts/ +statsroot=/usr/local/www/xerlstats/ +hyperion.buetow.org=ssl.buetow.org +404=http://www.buetow.org -- cgit v1.2.3 From b89757bad726bb9869e9a8492c0b2de89a35a43b Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 17:49:45 +0200 Subject: remove obsolete file --- README | 68 ------------------------------------------------------------------ TODO | 1 - 2 files changed, 69 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index 7a6d984..0000000 --- a/README +++ /dev/null @@ -1,68 +0,0 @@ -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/TODO b/TODO index 51acded..e159ca7 100644 --- a/TODO +++ b/TODO @@ -2,5 +2,4 @@ Hint: Run 'make todo' to see everything in every file what is to do! TODO: - Documentation of all features/options TODO: - Fix bug -TODO: - Rename config.txt into xerl.conf TODO: - Remove logging -- cgit v1.2.3 From c82cde6765f3422db2e6035bcc9dc585d7f66cfb Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 17:52:27 +0200 Subject: update header file --- COPYING | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/COPYING b/COPYING index be5ae5e..bf161b3 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,6 @@ -# Xerl (c) 2005-2009, Dipl.-Inform. (FH) Paul C. Buetow +# Xerl (c) 2005-2009,2013 Dipl.-Inform. (FH) Paul C. Buetow # -# E-Mail: xerl@dev.buetow.org WWW: http://xerl.perl9.org +# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # # All rights reserved. # -- cgit v1.2.3 From bbd7d09cb0bd3e3675a8521d70c69581b007579a Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 17:55:51 +0200 Subject: remove stat logging --- Makefile | 6 +----- TODO | 1 - Xerl/Page/Parameter.pm | 1 - Xerl/Page/Templates.pm | 26 -------------------------- 4 files changed, 1 insertion(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 2151b3e..cbc8d84 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,4 @@ -all: stats -clean: - rm -Rf cache/* -stats: clean - perl scripts/stats.pl +all: replace: for i in index.pl Xerl.pm xerl.conf; \ do \ diff --git a/TODO b/TODO index e159ca7..377e018 100644 --- a/TODO +++ b/TODO @@ -2,4 +2,3 @@ Hint: Run 'make todo' to see everything in every file what is to do! TODO: - Documentation of all features/options TODO: - Fix bug -TODO: - Remove logging diff --git a/Xerl/Page/Parameter.pm b/Xerl/Page/Parameter.pm index 72c44c9..3f580a7 100644 --- a/Xerl/Page/Parameter.pm +++ b/Xerl/Page/Parameter.pm @@ -55,7 +55,6 @@ sub parse($) { } if ( $config->devel_exists() ) { - $config->set_nolog(1); $config->set_nocache(1); } diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm index e706840..efe7321 100644 --- a/Xerl/Page/Templates.pm +++ b/Xerl/Page/Templates.pm @@ -161,32 +161,6 @@ sub parse($) { $io->fwrite(); } - unless ( $config->nolog_exists() ) { - my @time = localtime; - my $ctx = Digest::MD5->new(); - $ctx->add( $ENV{REMOTE_ADDR} ); - - my Xerl::Tools::FileIO $stats = Xerl::Tools::FileIO->new( - path => $config->get_statsroot(), - filename => sprintf( - "\%02d%02d%02d", $time[5] - 100, $time[4] + 1, $time[3] - ) - . '.log', - array => [ - time() . ' ' - . $ctx->hexdigest() . ' ' - - #. $ENV{REMOTE_ADDR} . ' ' - . $config->get_host() - . $config->get_request_subdir() . ' ' - . $config->get_site() . ' ' - . $ENV{HTTP_USER_AGENT} . "\n" - ], - ); - - $stats->fwriteappend(); - } - $self->parsetemplate('$$'); # Parsing dynamic vars. return undef; } -- cgit v1.2.3 From 5bed23b6131c189062b7bb82ca9d50882b0ef0ef Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 17:56:22 +0200 Subject: new brainstorming --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 377e018..2b747b2 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,4 @@ Hint: Run 'make todo' to see everything in every file what is to do! TODO: - Documentation of all features/options TODO: - Fix bug +TIDI: - Support a Debian package -- cgit v1.2.3 From 6c19d749604e37c7b75f120a5bf00af2a9dc5963 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 18:02:19 +0200 Subject: cleanup --- xerl.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/xerl.conf b/xerl.conf index c87afb6..5873c22 100644 --- a/xerl.conf +++ b/xerl.conf @@ -3,7 +3,6 @@ #nocache=defined #nocache=1 cacheroot=/usr/local/www/xerlcache/ -cookievals=nocache,plain,devel,style,template ctype.asc=text/plain ctype.css=text/css ctype.jpg=image/jpg @@ -20,6 +19,5 @@ defaulttemplate=xhtml dslvpnrouter.buetow.org=vpndslrouter.buetow.org hidesubhome=1 hostroot=/usr/local/www/xerlhosts/branches/stable/hosts/ -statsroot=/usr/local/www/xerlstats/ hyperion.buetow.org=ssl.buetow.org 404=http://www.buetow.org -- cgit v1.2.3 From 862679a92e2d853390d84ade4003f3c2e0f13bea Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sat, 7 Sep 2013 18:05:44 +0200 Subject: perltidy --- Makefile | 2 +- Xerl.pm | 1 - Xerl/Main/Global.pm | 2 +- index.pl | 7 ++++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index cbc8d84..1172a39 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ replace: find ./Xerl -name '*.xml' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \ w .tmp" {} && mv -f .tmp {}' \; chmod 755 index.pl -pidy: +perltidy: find . -name \*.pl | xargs perltidy -b find . -name \*.pm | xargs perltidy -b find . -name \*.bak | xargs rm -f diff --git a/Xerl.pm b/Xerl.pm index 648a24d..8844e85 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -65,7 +65,6 @@ sub run($) { $parameter->parse(); return undef if $config->finish_request_exists(); - if ( $config->document_exists() ) { my Xerl::Page::Document $document = Xerl::Page::Document->new( config => $config ); diff --git a/Xerl/Main/Global.pm b/Xerl/Main/Global.pm index 83beb73..bd2b140 100644 --- a/Xerl/Main/Global.pm +++ b/Xerl/Main/Global.pm @@ -68,7 +68,7 @@ sub REDIRECT ($) { } sub _HTTP_DESCR ($;$) { - my ($status, $infomsg) = @_; + my ( $status, $infomsg ) = @_; $infomsg //= ''; diff --git a/index.pl b/index.pl index f1f5531..1846180 100755 --- a/index.pl +++ b/index.pl @@ -9,9 +9,10 @@ use Socket; use Sys::Hostname; my $host = hostname(); -my $config = -e "xerldev-$host.conf" ? "xerldev-$host.conf" : ( - -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' -); +my $config = + -e "xerldev-$host.conf" + ? "xerldev-$host.conf" + : ( -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' ); my Xerl $xerl = Xerl->new( config => $config ); $xerl->run(); -- cgit v1.2.3 From 0663db22aea0342e9ecaf0257e9c7ebb67537022 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 8 Sep 2013 09:19:05 +0200 Subject: rename STYLEGUIDE --- README | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STYLEGUIDE | 71 -------------------------------------------------------------- 2 files changed, 71 insertions(+), 71 deletions(-) create mode 100644 README delete mode 100644 STYLEGUIDE diff --git a/README b/README new file mode 100644 index 0000000..e6dd3c9 --- /dev/null +++ b/README @@ -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/STYLEGUIDE b/STYLEGUIDE deleted file mode 100644 index e6dd3c9..0000000 --- a/STYLEGUIDE +++ /dev/null @@ -1,71 +0,0 @@ -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'). -- cgit v1.2.3 From 43b907a0e59da5e1c3cf5e86e80909184d1441f9 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 8 Sep 2013 09:19:52 +0200 Subject: retab --- README | 98 ++++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/README b/README index e6dd3c9..b9257fc 100644 --- a/README +++ b/README @@ -1,71 +1,73 @@ +STYLEGUIDE: + Always do: -- Pragmatic modules ALWAYS to use in ALL packages: +Pragmatic modules ALWAYS to use in ALL packages: - use strict; - use warnings; +use strict; +use warnings; -- Only for packages for including package UNIVERSAL definitions +Only for packages for including package UNIVERSAL definitions - use Xerl::Page::Base; +use Xerl::Page::Base; -- Object oriented coding style +Object oriented coding style -- Always use method prototypes if possible +Always use method prototypes if possible - sub foo($;$) { .... } +sub foo($;$) { .... } -- Explicit object typing if possible +Explicit object typing if possible - my Class::Name::Here $foo = Class::Name::Here->new(); +my Class::Name::Here $foo = Class::Name::Here->new(); -- If no real ret val, set undef; explicitly +If no real ret val, set undef; explicitly - sub foo() { - # Do some stuff - ... - # Set explicit undef ret value - return undef; - } +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. +Private subs use _ as its prefix and are called only from the current package. - package Xerl::Foo::Bla; - . - . +package Xerl::Foo::Bla; +. +. - sub _iamprivate($) { - my Xerl::Foo:Bla $self = $_[0]; - . - . - } +sub _iamprivate($) { +my Xerl::Foo:Bla $self = $_[0]; +. +. +} - sub iampublic($) { - my Xerl::Foo:Bla $self = $_[0]; - $self->_iamprivate(); - return undef; - } +sub iampublic($) { +my Xerl::Foo:Bla $self = $_[0]; +$self->_iamprivate(); +return undef; +} -- Static subs (not OOP) are in CAPITAL letters. +Static subs (not OOP) are in CAPITAL letters. - sub IAMSTATIC($) { - print shift; - return 'Hello World'; - } +sub IAMSTATIC($) { +print shift; +return 'Hello World'; +} - sub iamdynamic($) { - my Xerl::Foo:Bla $self = $_[0]; - return Xerl::Foo::Bla::IAMSTATIC( $self->get_somevalue() ); - } +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 +Static private subs start with _ and are written in CAPITAL letters - sub _IAMSTATICPRIVATE() { - . - . - } +sub _IAMSTATICPRIVATE() { +. +. +} -- Use Pidy to automaically restyle the code! (make pidy) +Use Pidy to automaically restyle the code! (make perltidy) -- Mark things which are still to do with TODO: at any place in the source - tree. (Can be searched for using 'make todo'). +Mark things which are still to do with TODO: at any place in the source +tree. (Can be searched for using 'make todo'). -- cgit v1.2.3 From 7c8a3f5acce9708684ba5d8bf917cd5503f0204d Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 8 Sep 2013 09:26:05 +0200 Subject: new brainstorming --- TODO | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 2b747b2..c8feee7 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ Hint: Run 'make todo' to see everything in every file what is to do! TODO: - Documentation of all features/options -TODO: - Fix bug -TIDI: - Support a Debian package +TODO: - Fix XML bug +TODO: - Use Template Tool Kit +TODO: - Use X?HTML5 by default +TODO: - Support a Debian package -- cgit v1.2.3 From c183faa4d53b6e4f091d6b38397847e55b5d2251 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 8 Sep 2013 09:29:56 +0200 Subject: perltidy also fast cgi perl scripts --- Makefile | 1 + index.fpl | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 1172a39..1fd9f8d 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ replace: w .tmp" {} && mv -f .tmp {}' \; chmod 755 index.pl perltidy: + find . -name \*.fpl | xargs perltidy -b find . -name \*.pl | xargs perltidy -b find . -name \*.pm | xargs perltidy -b find . -name \*.bak | xargs rm -f diff --git a/index.fpl b/index.fpl index 3ac017c..11be5fc 100755 --- a/index.fpl +++ b/index.fpl @@ -10,11 +10,12 @@ use Socket; use Sys::Hostname; my $host = hostname(); -my $config = -e "xerldev-$host.conf" ? "xerldev-$host.conf" : ( - -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' -); +my $config = + -e "xerldev-$host.conf" + ? "xerldev-$host.conf" + : ( -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' ); -while (FCGI::accept >= 0) { - my Xerl $xerl = Xerl->new( config => $config ); - $xerl->run(); +while ( FCGI::accept >= 0 ) { + my Xerl $xerl = Xerl->new( config => $config ); + $xerl->run(); } -- cgit v1.2.3 From 6aa12ae5f556ab884b7705379c41a566df86d028 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 15 Sep 2013 11:51:10 +0200 Subject: temp remove includedirs tag, perltidy indention set to 2, initial XML::LibXML --- Makefile | 6 +- Xerl.pm | 56 +++++----- Xerl/Base.pm | 116 ++++++++++---------- Xerl/Main/Global.pm | 64 +++++------ Xerl/Page/Configure.pm | 188 ++++++++++++++++----------------- Xerl/Page/Content.pm | 280 ++++++++++++++++++++++++------------------------ Xerl/Page/Document.pm | 50 ++++----- Xerl/Page/Menu.pm | 136 ++++++++++++------------ Xerl/Page/Parameter.pm | 44 ++++---- Xerl/Page/Request.pm | 40 +++---- Xerl/Page/Rules.pm | 86 +++++++-------- Xerl/Page/Templates.pm | 282 ++++++++++++++++++++++++------------------------- Xerl/Tools/FileIO.pm | 172 +++++++++++++++--------------- Xerl/XML/Element.pm | 98 ++++++++--------- Xerl/XML/Reader.pm | 282 +++++++++++++++++++++---------------------------- index.fpl | 4 +- 16 files changed, 932 insertions(+), 972 deletions(-) diff --git a/Makefile b/Makefile index 1fd9f8d..757c3fc 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,9 @@ replace: w .tmp" {} && mv -f .tmp {}' \; chmod 755 index.pl perltidy: - find . -name \*.fpl | xargs perltidy -b - find . -name \*.pl | xargs perltidy -b - find . -name \*.pm | xargs perltidy -b + find . -name \*.fpl | xargs perltidy -i=2 -b + find . -name \*.pl | xargs perltidy -i=2 -b + find . -name \*.pm | xargs perltidy -i=2 -b find . -name \*.bak | xargs rm -f todo: grep -R TODO . | grep -v Makefile | grep -v .git diff --git a/Xerl.pm b/Xerl.pm index 8844e85..c8d816a 100644 --- a/Xerl.pm +++ b/Xerl.pm @@ -44,45 +44,45 @@ use Xerl::Page::Request; use Xerl::Page::Templates; sub run($) { - my Xerl $self = $_[0]; - my $time = [gettimeofday]; + my Xerl $self = $_[0]; + my $time = [gettimeofday]; - my Xerl::Page::Request $request = - Xerl::Page::Request->new( request => $ENV{REQUEST_URI} ); + 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 ); + $request->parse(); + my Xerl::Page::Configure $config = + Xerl::Page::Configure->new( config => $self->get_config(), %$request ); - $config->parse(); - return undef if $config->finish_request_exists(); + $config->parse(); + return undef if $config->finish_request_exists(); - $config->defaults(); + $config->defaults(); - my Xerl::Page::Parameter $parameter = - Xerl::Page::Parameter->new( config => $config ); + my Xerl::Page::Parameter $parameter = + Xerl::Page::Parameter->new( config => $config ); - $parameter->parse(); - return undef if $config->finish_request_exists(); + $parameter->parse(); + return undef if $config->finish_request_exists(); - if ( $config->document_exists() ) { - my Xerl::Page::Document $document = - Xerl::Page::Document->new( config => $config ); + if ( $config->document_exists() ) { + my Xerl::Page::Document $document = + Xerl::Page::Document->new( config => $config ); - $document->parse(); - return undef if $config->finish_request_exists(); + $document->parse(); + return undef if $config->finish_request_exists(); - } - else { - my Xerl::Page::Templates $templates = - Xerl::Page::Templates->new( config => $config ); + } + else { + my Xerl::Page::Templates $templates = + Xerl::Page::Templates->new( config => $config ); - $templates->parse(); - return undef if $config->finish_request_exists(); - $templates->print($time); - } + $templates->parse(); + return undef if $config->finish_request_exists(); + $templates->print($time); + } - return undef; + return undef; } 1; diff --git a/Xerl/Base.pm b/Xerl/Base.pm index 53368a9..6b71565 100644 --- a/Xerl/Base.pm +++ b/Xerl/Base.pm @@ -33,97 +33,97 @@ use strict; use warnings; sub new ($;) { - my $self = shift; + my $self = shift; - bless {@_} => $self; + bless {@_} => $self; } sub setval($$$) { - my UNIVERSAL $self = $_[0]; + my UNIVERSAL $self = $_[0]; - $self->{ $_[1] } = $_[2]; + $self->{ $_[1] } = $_[2]; - return undef; + return undef; } sub getval($$) { - my UNIVERSAL $self = $_[0]; + my UNIVERSAL $self = $_[0]; - return defined $self->{ $_[1] } ? $self->{ $_[1] } : ''; + return defined $self->{ $_[1] } ? $self->{ $_[1] } : ''; } sub exists($$) { - my UNIVERSAL $self = $_[0]; + my UNIVERSAL $self = $_[0]; - return exists $self->{ $_[1] } ? 1 : 0; + return exists $self->{ $_[1] } ? 1 : 0; } sub AUTOLOAD { - my UNIVERSAL $self = $_[0]; - my $auto = our $AUTOLOAD; - return $self if $auto =~ /DESTROY/; + my UNIVERSAL $self = $_[0]; + my $auto = our $AUTOLOAD; + return $self if $auto =~ /DESTROY/; - if ( $auto =~ /.*::set_(.+)$/ ) { - $self->{$1} = $_[1]; + 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 =~ /.*::get_(.+)_ref$/ ) { + return defined $self->{$1} ? \$self->{$1} : ['']; - } - elsif ( $auto =~ /.*::undef_(.+)$/ ) { - return '' unless defined $self->{$1}; + } + elsif ( $auto =~ /.*::get_(.+)$/ ) { + return defined $self->{$1} ? $self->{$1} : ''; - my $retval = $self->{$1}; - undef $self->{$1}; - return $retval; + } + elsif ( $auto =~ /.*::undef_(.+)$/ ) { + return '' unless defined $self->{$1}; - } - elsif ( $auto =~ /.*::append_(.+)$/ ) { - if ( defined $self->{$1} ) { - $self->{$1} .= $_[1]; + my $retval = $self->{$1}; + undef $self->{$1}; + return $retval; - } - else { - $self->{$1} = $_[1]; - } + } + elsif ( $auto =~ /.*::append_(.+)$/ ) { + if ( defined $self->{$1} ) { + $self->{$1} .= $_[1]; } - elsif ( $auto =~ /.*::push_(.+)$/ ) { - if ( exists $self->{$1} ) { - push @{ $self->{$1} }, $_[1]; + else { + $self->{$1} = $_[1]; + } - } - else { - $self->{$1} = [ $_[1] ]; - } + } + elsif ( $auto =~ /.*::push_(.+)$/ ) { + if ( exists $self->{$1} ) { + push @{ $self->{$1} }, $_[1]; } - elsif ( $auto =~ /.*::first_(.+)$/ ) { - return exists $self->{$1} ? ${ $self->{$1} }[0] : ''; - + else { + $self->{$1} = [ $_[1] ]; } - elsif ( $auto =~ /.*::(.+)_exists$/ ) { - return exists $self->{$1} ? 1 : 0; - } - elsif ( $auto =~ /.*::(.+)_length$/ ) { - return ( ref $self->{$1} eq 'ARRAY' ) ? scalar @{ $self->{$1} } : 0; + } + elsif ( $auto =~ /.*::first_(.+)$/ ) { + return exists $self->{$1} ? ${ $self->{$1} }[0] : ''; - } - elsif ( $auto =~ /.*::(.+)_isset$/ ) { - return exists $self->{$1} ? $self->{ $_[0] } : 0; + } + elsif ( $auto =~ /.*::(.+)_exists$/ ) { + return exists $self->{$1} ? 1 : 0; - } - else { - print "$auto is not a method of $self or UNIVERSAL\n"; - } + } + 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; + return $self; } 1; diff --git a/Xerl/Main/Global.pm b/Xerl/Main/Global.pm index bd2b140..f70ef6d 100644 --- a/Xerl/Main/Global.pm +++ b/Xerl/Main/Global.pm @@ -30,67 +30,67 @@ package Xerl::Main::Global; sub SHUTDOWN { - exit 0; + exit 0; - # Never reach this point - return undef; + # Never reach this point + return undef; } sub DEBUG { - print 'Debug::', @_, "\n"; + print 'Debug::', @_, "\n"; - return undef; + return undef; } sub ERROR { - print "Content-Type: text/plain\n\nXerl runtime error: ", - join( ' ', time, @_ ); + print "Content-Type: text/plain\n\nXerl runtime error: ", + join( ' ', time, @_ ); - Xerl::Main::Global::SHUTDOWN(); + Xerl::Main::Global::SHUTDOWN(); - # Never reach this point - return undef; + # Never reach this point + return undef; } sub PLAIN { - print "Content-Type: text/plain\n\n"; + print "Content-Type: text/plain\n\n"; - DEBUG(@_) if @_; + DEBUG(@_) if @_; - return undef; + return undef; } sub REDIRECT ($) { - my $location = shift; - print "Status: 301 Moved Permanantly\n"; - print "Location: $location\n\n"; - return undef; + my $location = shift; + print "Status: 301 Moved Permanantly\n"; + print "Location: $location\n\n"; + return undef; } sub _HTTP_DESCR ($;$) { - my ( $status, $infomsg ) = @_; + my ( $status, $infomsg ) = @_; - $infomsg //= ''; + $infomsg //= ''; - if ( $status == 404 ) { - "Status: 404 Not Found $infomsg\015\012\n\n" + if ( $status == 404 ) { + "Status: 404 Not Found $infomsg\015\012\n\n" - } - else { - "Status: 405 Method not allowed $infomsg\015\012\n\n"; - } + } + else { + "Status: 405 Method not allowed $infomsg\015\012\n\n"; + } } sub HTTP { - my $descr = _HTTP_DESCR(shift); - print $descr; - local $, = ' '; - print $descr; + my $descr = _HTTP_DESCR(shift); + print $descr; + local $, = ' '; + print $descr; - Xerl::Main::Global::SHUTDOWN(); + Xerl::Main::Global::SHUTDOWN(); - # Never reach this point - return undef; + # Never reach this point + return undef; } 1; diff --git a/Xerl/Page/Configure.pm b/Xerl/Page/Configure.pm index dfe4ec4..1a9ecde 100644 --- a/Xerl/Page/Configure.pm +++ b/Xerl/Page/Configure.pm @@ -37,134 +37,134 @@ use Xerl::Tools::FileIO; use Xerl::XML::Element; sub parse($) { - my Xerl::Page::Configure $self = $_[0]; + my Xerl::Page::Configure $self = $_[0]; - my Xerl::Tools::FileIO $file = - Xerl::Tools::FileIO->new( 'path' => $self->get_config() ); + my Xerl::Tools::FileIO $file = + Xerl::Tools::FileIO->new( 'path' => $self->get_config() ); - if ( -1 == $file->fslurp() ) { - $self->set_finish_request(1); - return undef; - } + if ( -1 == $file->fslurp() ) { + $self->set_finish_request(1); + return undef; + } - my $re = qr/^(.+?) *=(.+?) *\n?$/; + my $re = qr/^(.+?) *=(.+?) *\n?$/; - for ( @{ $file->get_array() } ) { - next if /^ *#/; + for ( @{ $file->get_array() } ) { + next if /^ *#/; - $self->setval( $1, $self->eval($2) ) if $_ =~ $re; - } + $self->setval( $1, $self->eval($2) ) if $_ =~ $re; + } - return $self; + 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); - $self->set_finish_request(1); - } - 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() ); - } - } + 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_outputformat( $self->get_defaultoutputformat() ) - unless $self->outputformat_exists(); + $self->set_style( $self->get_defaultstyle() ) + unless $self->style_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_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); + $self->set_finish_request(1); } + 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_host( $self->getval( $self->get_host() ) ) - if $self->exists( $self->get_host() ); + $self->set_outputformat( $self->get_defaultoutputformat() ) + unless $self->outputformat_exists(); - $self->set_host( $self->getval( $self->get_host() ) ) - if $self->exists( $self->get_host() ); + 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$/; + } - my $request_subdir = $self->get_request_subdir(); - $self->set_hostpath( - $self->get_hostroot() . $self->get_host() . $request_subdir . "/" ); + $self->set_host( $self->getval( $self->get_host() ) ) + if $self->exists( $self->get_host() ); - $self->set_defaulthostpath( - $self->get_hostroot() . $self->get_defaulthost() . '/' ); + $self->set_host( $self->getval( $self->get_host() ) ) + if $self->exists( $self->get_host() ); - $self->set_cachepath( - $self->get_cacheroot() . $self->get_host() . $request_subdir . '/' ); + my $request_subdir = $self->get_request_subdir(); + $self->set_hostpath( + $self->get_hostroot() . $self->get_host() . $request_subdir . "/" ); - $self->set_htdocspath( $self->get_hostpath() . 'htdocs/' ); + $self->set_defaulthostpath( + $self->get_hostroot() . $self->get_defaulthost() . '/' ); - $self->set_templatespath( $self->get_hostpath() . 'templates/' ); + $self->set_cachepath( + $self->get_cacheroot() . $self->get_host() . $request_subdir . '/' ); - $self->set_contentpath( $self->get_hostpath() . 'content/' ); + $self->set_htdocspath( $self->get_hostpath() . 'htdocs/' ); - # $self->set_ipv6( $ENV{REMOTE_ADDR} =~ /:/ ? 1 : 0 ); + $self->set_templatespath( $self->get_hostpath() . 'templates/' ); - return undef; + $self->set_contentpath( $self->get_hostpath() . 'content/' ); + + # $self->set_ipv6( $ENV{REMOTE_ADDR} =~ /:/ ? 1 : 0 ); + + return undef; } sub eval($$) { - my Xerl::Page::Configure $self = $_[0]; - my $val = $_[1]; + my Xerl::Page::Configure $self = $_[0]; + my $val = $_[1]; - $val =~ s/^!(.+)/`$1`/eo; - return $val; + $val =~ s/^!(.+)/`$1`/eo; + return $val; } sub insertxmlvars($$) { - my Xerl::Page::Configure $self = $_[0]; - my Xerl::XML::Element $element = $_[1]; + my Xerl::Page::Configure $self = $_[0]; + my Xerl::XML::Element $element = $_[1]; - $element = $element->starttag('variables'); + $element = $element->starttag('variables'); - return $self - unless defined $element - or $element->get_array() eq 'ARRAY'; + return $self + unless defined $element + or $element->get_array() eq 'ARRAY'; - my $text; - for ( @{ $element->get_array() } ) { - $text = $_->get_text(); - chomp $text; + my $text; + for ( @{ $element->get_array() } ) { + $text = $_->get_text(); + chomp $text; - $text =~ s/%%(.*?)%%/$self->getval($1)/eg; - $self->setval( $_->get_name(), $text ); - } + $text =~ s/%%(.*?)%%/$self->getval($1)/eg; + $self->setval( $_->get_name(), $text ); + } - return $self; + return $self; } 1; diff --git a/Xerl/Page/Content.pm b/Xerl/Page/Content.pm index da70139..bd3e8ee 100644 --- a/Xerl/Page/Content.pm +++ b/Xerl/Page/Content.pm @@ -40,190 +40,188 @@ 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::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 - ); + my Xerl::XML::Reader $xmlcontent = Xerl::XML::Reader->new( + path => $config->get_templatepath(), + config => $config + ); - if ( -1 == $xmlcontent->open() ) { - $config->set_finish_request(1); - return undef; - } + if ( -1 == $xmlcontent->open() ) { + $config->set_finish_request(1); + return undef; + } - $xmlcontent->parse(); + $xmlcontent->parse(); - my Xerl::Page::Rules $rules = Xerl::Page::Rules->new( config => $config ); - $rules->parse( $config->get_xmlconfigrootobj() ) - unless $config->exists('noparse'); + 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() ); + $config->insertxmlvars( $config->get_xmlconfigrootobj() ); + $self->insertrules( $rules, $xmlcontent->get_root() ); - return undef; + 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::Content $self = $_[0]; + my Xerl::Page::Rules $rules = $_[1]; + my Xerl::XML::Element $element = $_[2]; - # Start inserting rules at - $element = $element->starttag('content'); + # Start inserting rules at + $element = $element->starttag('content'); - # If there is no -tag, dont use a rule! - return unless defined $element; + # If there is no -tag, dont use a rule! + return unless defined $element; - my @content; - my $params = $element->get_params(); + my @content; + my $params = $element->get_params(); - unshift @content, "Content-Type: $params->{type}\n\n" - if ref $params eq 'HASH' and exists $params->{type}; + 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 ); + push @content, $self->_insertrules( $rules, $element ); + $self->set_content( \@content ); - return undef; + 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' ) { + 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, '', $text, ''; - - } - elsif ( lc $name eq 'navigation' ) { - my $menus = $config->get_menuobj()->get_array(); - - if ( ref $menus eq 'ARRAY' ) { - push @content, $self->_insertrules( $rules, $_ ) - for @$menus; - } - - } - else { - - # No rule available, use the tag unmodified! - $name =~ s/^=//o; # Remove the leading = - if ( $succ->get_single() ) { - push @content, - "<$name" . ( $succ->params_str() || '' ) . " />\n" - - } - else { - push @content, - "<$name" . ( $succ->params_str() || '' ) . '>', - $self->_insertrules( $rules, $succ ), $text, "\n"; - } - } + push @content, '', $text, ''; + + } + elsif ( lc $name eq 'navigation' ) { + my $menus = $config->get_menuobj()->get_array(); + if ( ref $menus eq 'ARRAY' ) { + push @content, $self->_insertrules( $rules, $_ ) for @$menus; } - else { - # Get a local copy of lrule, because orule may be modified. - # And then insert special vars if required: - # @@text@@ => Text content of the current tag. + } + else { - my $ruleparams = $rule->[2]; - $nonewlines = 1 if exists $ruleparams->{nonewlines}; + # No rule available, use the tag unmodified! + $name =~ s/^=//o; # Remove the leading = + if ( $succ->get_single() ) { + push @content, "<$name" . ( $succ->params_str() || '' ) . " />\n" - my ( $orule, $crule ) = ( $rule->[0], $rule->[1] ); + } + else { + push @content, + "<$name" . ( $succ->params_str() || '' ) . '>', + $self->_insertrules( $rules, $succ ), $text, "\n"; + } + } - $self->_insert_special_vars( $rules, $succ, \$orule ); - $self->_insert_special_vars( $rules, $succ, \$crule ); - chomp $orule; + } + else { - # Parse for known tag params. - if ( ref $params eq 'HASH' ) { - Xerl::Page::Templates::PARSELINE( $config, '%%', \$text ); + # Get a local copy of lrule, because orule may be modified. + # And then insert special vars if required: + # @@text@@ => Text content of the current tag. - # path/to/file.bla => file.bla - $text =~ s#.*/(.*)$#$1# if lc $params->{basename} eq 'yes'; + my $ruleparams = $rule->[2]; + $nonewlines = 1 if exists $ruleparams->{nonewlines}; - # foo.bar.tld?options => ?options - if ( exists $params->{cut} ) { - my $cut = quotemeta $params->{cut}; - $text =~ s/.*$cut(.*)$/$1/o; - } + my ( $orule, $crule ) = ( $rule->[0], $rule->[1] ); - $text .= $params->{addback} - if exists $params->{addback}; - $text = $params->{addfront} . $text - if exists $params->{addfront}; - } + $self->_insert_special_vars( $rules, $succ, \$orule ); + $self->_insert_special_vars( $rules, $succ, \$crule ); + chomp $orule; - my $oadd = - exists $ruleparams->{addfront} - ? '<' . $ruleparams->{addfront} - : ''; + # Parse for known tag params. + if ( ref $params eq 'HASH' ) { + Xerl::Page::Templates::PARSELINE( $config, '%%', \$text ); - my $cadd = - exists $ruleparams->{addback} ? $ruleparams->{addback} . '>' : ''; + # path/to/file.bla => file.bla + $text =~ s#.*/(.*)$#$1# if lc $params->{basename} eq 'yes'; - push @content, $orule, $oadd, $self->_insertrules( $rules, $succ ), - $text, $cadd, $crule; + # foo.bar.tld?options => ?options + if ( exists $params->{cut} ) { + my $cut = quotemeta $params->{cut}; + $text =~ s/.*$cut(.*)$/$1/o; } + + $text .= $params->{addback} + if exists $params->{addback}; + $text = $params->{addfront} . $text + if exists $params->{addfront}; + } + + my $oadd = + exists $ruleparams->{addfront} + ? '<' . $ruleparams->{addfront} + : ''; + + my $cadd = + exists $ruleparams->{addback} ? $ruleparams->{addback} . '>' : ''; + + push @content, $orule, $oadd, $self->_insertrules( $rules, $succ ), + $text, $cadd, $crule; } + } - return $nonewlines ? map { s/\n/ /go; $_ } @content : @content; + return $nonewlines ? map { s/\n/ /go; $_ } @content : @content; } sub _insert_special_vars($$$$) { - 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 $rtext = $_[3]; + 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 $rtext = $_[3]; - $$rtext =~ s/@\@text\@\@/$_=$element->get_text();chomp;$_/geo; - $$rtext =~ s/@\@ln\@\@//go; + $$rtext =~ s/@\@text\@\@/$_=$element->get_text();chomp;$_/geo; + $$rtext =~ s/@\@ln\@\@//go; - #$$rtext =~ s/@\@link\@\@/$element->get_params()->{link}.'$$params$$'/geo; + #$$rtext =~ s/@\@link\@\@/$element->get_params()->{link}.'$$params$$'/geo; - if ( $$rtext =~ /@\@(.*?)\@\@/ ) { - my $params = $element->get_params(); - return unless ref $params eq 'HASH'; - $$rtext =~ s/@\@(.*?)\@\@/$params->{$1}||''/geo; - } + if ( $$rtext =~ /@\@(.*?)\@\@/ ) { + my $params = $element->get_params(); + return unless ref $params eq 'HASH'; + $$rtext =~ s/@\@(.*?)\@\@/$params->{$1}||''/geo; + } - return undef; + return undef; } 1; diff --git a/Xerl/Page/Document.pm b/Xerl/Page/Document.pm index bb58016..afc4da3 100644 --- a/Xerl/Page/Document.pm +++ b/Xerl/Page/Document.pm @@ -38,38 +38,38 @@ use Xerl::Page::Configure; use Xerl::Tools::FileIO; sub parse($) { - my Xerl::Page::Document $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); + my Xerl::Page::Document $self = $_[0]; + my Xerl::Page::Configure $config = $self->get_config(); - return undef unless $config->document_exists(); + return undef unless $config->document_exists(); - my $document = $config->get_document(); - my ($filename) = $document =~ m#([^/]+)$#; - my ($postfix) = $document =~ /\.(.+)$/; - my $path; + my $document = $config->get_document(); + my ($filename) = $document =~ m#([^/]+)$#; + my ($postfix) = $document =~ /\.(.+)$/; + my $path; - print 'Content-Type: '; - print $config->getval( 'ctype.' . lc($postfix) ), "\n"; - print "Content-Disposition: attachment; filename=\"$filename\"\n\n"; + print 'Content-Type: '; + print $config->getval( 'ctype.' . lc($postfix) ), "\n"; + print "Content-Disposition: attachment; filename=\"$filename\"\n\n"; - $path = $config->get_hostpath() . "/htdocs/$document"; - unless ( -f $path ) { - $path = - $config->get_hostroot() - . $config->get_defaulthost() - . "/htdocs/$document"; - } + $path = $config->get_hostpath() . "/htdocs/$document"; + unless ( -f $path ) { + $path = + $config->get_hostroot() + . $config->get_defaulthost() + . "/htdocs/$document"; + } - my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new( path => $path ); + my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new( path => $path ); - if ( -1 == $io->fslurp() ) { - $config->set_finish_request(1); - } - else { - $io->print(); - } + if ( -1 == $io->fslurp() ) { + $config->set_finish_request(1); + } + else { + $io->print(); + } - return undef; + return undef; } 1; diff --git a/Xerl/Page/Menu.pm b/Xerl/Page/Menu.pm index 0ba9568..3bd158b 100644 --- a/Xerl/Page/Menu.pm +++ b/Xerl/Page/Menu.pm @@ -37,95 +37,95 @@ use Xerl::Tools::FileIO; use Xerl::XML::Element; sub generate($;$) { - my Xerl::Page::Menu $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); + my Xerl::Page::Menu $self = $_[0]; + my Xerl::Page::Configure $config = $self->get_config(); - my @site = split /\//, $config->get_site(); - my @compare = @site; - my $site = pop @site; + my @site = split /\//, $config->get_site(); + my @compare = @site; + my $site = pop @site; - my ( $content, $siteadd ) = ( 'content/', '' ); + my ( $content, $siteadd ) = ( 'content/', '' ); - my Xerl::XML::Element $menuelem = - $self->get_menu( $content, $siteadd, shift @compare ); + my Xerl::XML::Element $menuelem = + $self->get_menu( $content, $siteadd, shift @compare ); + $self->push_array($menuelem) + if $menuelem->first_array()->array_length() > 1; + + for my $s (@site) { + $content .= "$s.sub/"; + $siteadd .= "$s/"; + $menuelem = $self->get_menu( $content, $siteadd, shift @compare ); $self->push_array($menuelem) if $menuelem->first_array()->array_length() > 1; + } - for my $s (@site) { - $content .= "$s.sub/"; - $siteadd .= "$s/"; - $menuelem = $self->get_menu( $content, $siteadd, shift @compare ); - $self->push_array($menuelem) - if $menuelem->first_array()->array_length() > 1; - } - - return undef; + return undef; } sub get_menu($$$$) { - my Xerl::Page::Menu $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); - my ( $content, $siteadd, $compare ) = ( @_[ 1 ... 2 ], lc $_[3] ); - my $issubsection = $content =~ m{\.sub/$}; - my $pattern = qr/\.(?:xml)|(?:sub)$/; - - my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new( - path => $config->get_hostpath() . $content, - basename => 1, - ); - - unless ( $io->exists() ) { - Xerl::Main::Global::REDIRECT( $config->get_404() ); - $config->set_finish_request(1); + my Xerl::Page::Menu $self = $_[0]; + my Xerl::Page::Configure $config = $self->get_config(); + my ( $content, $siteadd, $compare ) = ( @_[ 1 ... 2 ], lc $_[3] ); + my $issubsection = $content =~ m{\.sub/$}; + my $pattern = qr/\.(?:xml)|(?:sub)$/; + + my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new( + path => $config->get_hostpath() . $content, + basename => 1, + ); + + unless ( $io->exists() ) { + Xerl::Main::Global::REDIRECT( $config->get_404() ); + $config->set_finish_request(1); + } + + $io->dslurp(); + my $dir = $io->get_array(); + + my ( @prec, @dir ); + map { + if (/^\d+\..+\./) { push @prec, $_ } + else { push @dir, $_ } } + grep { + $_ !~ /^home\.xml$/i + && $_ !~ /\.feed\.xml$/i + && $_ !~ /\.hide\.xml$/i + } @$dir; - $io->dslurp(); - my $dir = $io->get_array(); + my Xerl::XML::Element $root = Xerl::XML::Element->new(); + my Xerl::XML::Element $menu = Xerl::XML::Element->new(); - my ( @prec, @dir ); - map { - if (/^\d+\..+\./) { push @prec, $_ } - else { push @dir, $_ } - } - grep { - $_ !~ /^home\.xml$/i - && $_ !~ /\.feed\.xml$/i - && $_ !~ /\.hide\.xml$/i - } @$dir; + $menu->set_name('menu'); - my Xerl::XML::Element $root = Xerl::XML::Element->new(); - my Xerl::XML::Element $menu = Xerl::XML::Element->new(); + for ( $issubsection ? ( @dir, @prec ) : ( 'home.xml', @dir, @prec ) ) { + my ($site) = /(.*)$pattern/o; - $menu->set_name('menu'); + $site =~ s#\.$#/home#o; + $site =~ s/^\d+\.//; - for ( $issubsection ? ( @dir, @prec ) : ( 'home.xml', @dir, @prec ) ) { - my ($site) = /(.*)$pattern/o; + my $linkname = $site; + $linkname =~ s/(?:\d+\.)?(.)/\U$1/o; + $compare .= '/' if $linkname =~ s#(.*/)[^/]+$#$1#; - $site =~ s#\.$#/home#o; - $site =~ s/^\d+\.//; - - my $linkname = $site; - $linkname =~ s/(?:\d+\.)?(.)/\U$1/o; - $compare .= '/' if $linkname =~ s#(.*/)[^/]+$#$1#; - - my Xerl::XML::Element $item = Xerl::XML::Element->new( - params => { link => "?site=$siteadd$site" }, - text => $linkname - ); + my Xerl::XML::Element $item = Xerl::XML::Element->new( + params => { link => "?site=$siteadd$site" }, + text => $linkname + ); - $compare =~ s/^(\d+\.)//; - $item->set_name( - lc $linkname eq lc $compare ? 'activemenuitem' : 'menuitem' ); + $compare =~ s/^(\d+\.)//; + $item->set_name( + lc $linkname eq lc $compare ? 'activemenuitem' : 'menuitem' ); - $item->set_prev($menu); - $menu->push_array($item); - } + $item->set_prev($menu); + $menu->push_array($item); + } - $root->push_array($menu); - $menu->set_prev($root); + $root->push_array($menu); + $menu->set_prev($root); - return $root; + return $root; } 1; diff --git a/Xerl/Page/Parameter.pm b/Xerl/Page/Parameter.pm index 3f580a7..ba0a6cd 100644 --- a/Xerl/Page/Parameter.pm +++ b/Xerl/Page/Parameter.pm @@ -38,33 +38,33 @@ use Xerl::Page::Configure; use Xerl::Tools::FileIO; sub parse($) { - my Xerl::Page::Parameter $self = $_[0]; - my Xerl::Page::Configure $config = $self->get_config(); + my Xerl::Page::Parameter $self = $_[0]; + my Xerl::Page::Configure $config = $self->get_config(); - print "Content-Type: text/plain\n\n" - if $config->plain_exists(); + print "Content-Type: text/plain\n\n" + if $config->plain_exists(); - if ( $config->href_exists() ) { - print "Location: ", $config->get_href(), "\n\n"; - $config->set_finish_request(1); - } - elsif ( $config->env_exists() ) { - print "Content-Type: text/plain\n\n"; - print "$_=", $ENV{$_}, "\n" for keys %ENV; - $config->set_finish_request(1); - } + if ( $config->href_exists() ) { + print "Location: ", $config->get_href(), "\n\n"; + $config->set_finish_request(1); + } + elsif ( $config->env_exists() ) { + print "Content-Type: text/plain\n\n"; + print "$_=", $ENV{$_}, "\n" for keys %ENV; + $config->set_finish_request(1); + } - if ( $config->devel_exists() ) { - $config->set_nocache(1); - } + if ( $config->devel_exists() ) { + $config->set_nocache(1); + } - if ( $config->conf_exists() ) { - print "Content-Type: text/plain\n\n"; - print "$_=", $config->{$_}, "\n" for keys %$config; - $config->set_finish_request(1); - } + if ( $config->conf_exists() ) { + print "Content-Type: text/plain\n\n"; + print "$_=", $config->{$_}, "\n" for keys %$config; + $config->set_finish_request(1); + } - return $self; + return $self; } 1; diff --git a/Xerl/Page/Request.pm b/Xerl/Page/Request.pm index 94c6037..11106ec 100644 --- a/Xerl/Page/Request.pm +++ b/Xerl/Page/Request.pm @@ -35,35 +35,35 @@ use warnings; use Xerl::Base; sub parse($) { - my Xerl::Page::Request $self = $_[0]; - my $request = $self->get_request(); + my Xerl::Page::Request $self = $_[0]; + my $request = $self->get_request(); - # Secure it! - $request =~ s#/\.\.##g; + # Secure it! + $request =~ s#/\.\.##g; - # Remove last / - $request =~ s#/$##; + # Remove last / + $request =~ s#/$##; - my $request_subdir = $request; - $request_subdir =~ s#/\?.*##; - $self->set_request_subdir($request_subdir); + my $request_subdir = $request; + $request_subdir =~ s#/\?.*##; + $self->set_request_subdir($request_subdir); - # List context returns $1 - ($_) = $request =~ /\?(.+)/; + # List context returns $1 + ($_) = $request =~ /\?(.+)/; - return $self unless defined; + return $self unless defined; - my $params = ''; - for ( split /&/ ) { + my $params = ''; + for ( split /&/ ) { - # List context uses ($1,$2) as method args - $self->setval(/(.+?)=(.+)/); - $params .= "&$1=$2" if $1 ne 'site'; - } + # List context uses ($1,$2) as method args + $self->setval(/(.+?)=(.+)/); + $params .= "&$1=$2" if $1 ne 'site'; + } - $self->set_params($params); + $self->set_params($params); - return undef; + return undef; } 1; diff --git a/Xerl/Page/Rules.pm b/Xerl/Page/Rules.pm index 4a08d19..3895f4e 100644 --- a/Xerl/Page/Rules.pm +++ b/Xerl/Page/Rules.pm @@ -37,59 +37,59 @@ use Xerl::XML::Element; use Xerl::Page::Configure; sub parse($) { - my Xerl::Page::Rules $self = $_[0]; - my Xerl::XML::Element $element = $_[1]; - my Xerl::Page::Configure $config = $self->get_config(); + my Xerl::Page::Rules $self = $_[0]; + my Xerl::XML::Element $element = $_[1]; + my Xerl::Page::Configure $config = $self->get_config(); - $element = $element->starttag2( 'rules', $config->get_outputformat() ); - return unless defined $element; + $element = $element->starttag2( 'rules', $config->get_outputformat() ); + return unless defined $element; - # Open and close rules: - my ( $orule, $crule ); + # Open and close rules: + my ( $orule, $crule ); - # For all available rules in config.xml - for my $rule ( @{ $element->get_array() } ) { - my $params = $rule->get_params(); + # For all available rules in config.xml + for my $rule ( @{ $element->get_array() } ) { + my $params = $rule->get_params(); - $orule = $rule->get_text(); - chomp $orule; + $orule = $rule->get_text(); + chomp $orule; - $orule =~ s/\[//go; + $orule =~ s/\[//go; - unless ( - ref $params eq 'HASH' - && ( lc $params->{end} eq 'yes' - || lc $params->{start} eq 'yes' ) - ) - { - $crule = join '><', reverse split /> *"; - $crule =~ s/<>/>/go; - $crule =~ s//>/go; - $crule .= "\n"; + unless ( + ref $params eq 'HASH' + && ( lc $params->{end} eq 'yes' + || lc $params->{start} eq 'yes' ) + ) + { + $crule = join '><', reverse split /> *"; + $crule =~ s/<>/>/go; + $crule =~ s//>/go; + $crule .= "\n"; - } - else { - if ( lc $$params{start} eq 'yes' ) { - $crule = ''; - - } - else { - $crule = $orule; - $orule = ''; - } - $crule .= "\n"; - } + } + else { + if ( lc $$params{start} eq 'yes' ) { + $crule = ''; - $params = {} unless ref $params eq 'HASH'; - $self->setval( $rule->get_name(), [ "$orule\n", $crule, $params ] ); + } + else { + $crule = $orule; + $orule = ''; + } + $crule .= "\n"; } - return undef; + $params = {} unless ref $params eq 'HASH'; + $self->setval( $rule->get_name(), [ "$orule\n", $crule, $params ] ); + } + + return undef; } 1; 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/((?:.|\n)*?)<\/perl>/eval $1/ego; - - if ( !$flag and $line =~ s/(.*)$//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#!!URL\((.+?)\)!!#$1#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/((?:.|\n)*?)<\/perl>/eval $1/ego; + + if ( !$flag and $line =~ s/(.*)$//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#!!URL\((.+?)\)!!#$1#g; + print $line; + } - return undef; + return undef; } 1; diff --git a/Xerl/Tools/FileIO.pm b/Xerl/Tools/FileIO.pm index 807cb10..72239ee 100644 --- a/Xerl/Tools/FileIO.pm +++ b/Xerl/Tools/FileIO.pm @@ -36,153 +36,153 @@ use Xerl::Base; use Xerl::Main::Global; sub dslurp($;$) { - my Xerl::Tools::FileIO $self = $_[0]; + my Xerl::Tools::FileIO $self = $_[0]; - my $path = $self->get_path(); + my $path = $self->get_path(); - $path .= '/' unless $path =~ /\/$/; - opendir my $dir, $path or Xerl::Main::Global::ERROR( $!, $path, caller() ); + $path .= '/' unless $path =~ /\/$/; + opendir my $dir, $path or Xerl::Main::Global::ERROR( $!, $path, caller() ); - my @dir = sort - map { $path . $_ } - grep { /^[^\.]/o } readdir($dir); + my @dir = sort + map { $path . $_ } + grep { /^[^\.]/o } readdir($dir); - @dir = map { s#.*/([^/]+\..+)$#$1#o; $_ } @dir - if $self->basename_exists(); + @dir = map { s#.*/([^/]+\..+)$#$1#o; $_ } @dir + if $self->basename_exists(); - closedir $dir; - $self->set_array( \@dir ); + closedir $dir; + $self->set_array( \@dir ); - return undef; + return undef; } sub fslurp($) { - my Xerl::Tools::FileIO $self = $_[0]; - my $path = SECUREPATH( $self->get_path() ); + my Xerl::Tools::FileIO $self = $_[0]; + my $path = SECUREPATH( $self->get_path() ); - unless ( -f $path ) { - Xerl::Main::Global::HTTP( 404, "Not found: $path" ); - return -1; - } + unless ( -f $path ) { + Xerl::Main::Global::HTTP( 404, "Not found: $path" ); + return -1; + } - open my $file, $path or Xerl::Main::Global::ERROR( $!, $path, caller() ); - flock $file, 2; + open my $file, $path or Xerl::Main::Global::ERROR( $!, $path, caller() ); + flock $file, 2; - my @slurp = <$file>; + my @slurp = <$file>; - flock $file, 3; - close $file; + flock $file, 3; + close $file; - $self->set_array( \@slurp ); + $self->set_array( \@slurp ); - return 0; + return 0; } sub exists($) { - my Xerl::Tools::FileIO $self = $_[0]; - my $path = SECUREPATH( $self->get_path() ); + my Xerl::Tools::FileIO $self = $_[0]; + my $path = SECUREPATH( $self->get_path() ); - return -e $path; + return -e $path; } sub fwrite($) { - my Xerl::Tools::FileIO $self = $_[0]; - $self->_fwrite(0); + my Xerl::Tools::FileIO $self = $_[0]; + $self->_fwrite(0); - return undef; + return undef; } sub fwriteappend($) { - my Xerl::Tools::FileIO $self = $_[0]; + my Xerl::Tools::FileIO $self = $_[0]; - $self->_fwrite(1); + $self->_fwrite(1); - return undef; + return undef; } sub _fwrite($;$) { - my Xerl::Tools::FileIO $self = $_[0]; - my $append = $_[1]; - - my ( $path, $filename ) = - ( SECUREPATH( $self->get_path() ), SECUREPATH( $self->get_filename() ) ); - - my $path_ = ''; - for ( split /\//, $path ) { - $path_ .= $_ . '/'; - mkdir $path_ - or Xerl::Main::Global::ERROR( $!, $path_, caller() ) - unless -d $path_; - } - - my $f; - if ( $append == 0 ) { - open $f, ">$path$filename" - or Xerl::Main::Global::ERROR( $!, $path . $filename, caller() ); - - } - else { - open $f, ">>$path$filename" - or Xerl::Main::Global::ERROR( $!, $path . $filename, caller() ); - } - - flock $f, 2; - print $f @{ $self->get_array() }; - flock $f, 3; - close $f; - - return undef; + my Xerl::Tools::FileIO $self = $_[0]; + my $append = $_[1]; + + my ( $path, $filename ) = + ( SECUREPATH( $self->get_path() ), SECUREPATH( $self->get_filename() ) ); + + my $path_ = ''; + for ( split /\//, $path ) { + $path_ .= $_ . '/'; + mkdir $path_ + or Xerl::Main::Global::ERROR( $!, $path_, caller() ) + unless -d $path_; + } + + my $f; + if ( $append == 0 ) { + open $f, ">$path$filename" + or Xerl::Main::Global::ERROR( $!, $path . $filename, caller() ); + + } + else { + open $f, ">>$path$filename" + or Xerl::Main::Global::ERROR( $!, $path . $filename, caller() ); + } + + flock $f, 2; + print $f @{ $self->get_array() }; + flock $f, 3; + close $f; + + return undef; } sub print($) { - my Xerl::Tools::FileIO $self = $_[0]; + my Xerl::Tools::FileIO $self = $_[0]; - print @{ $self->get_array() }; + print @{ $self->get_array() }; - return undef; + return undef; } sub reverse_array($) { - my Xerl::Tools::FileIO $self = $_[0]; + my Xerl::Tools::FileIO $self = $_[0]; - my @array = reverse @{ $self->get_array() }; - $self->set_array( \@array ); + my @array = reverse @{ $self->get_array() }; + $self->set_array( \@array ); - return undef; + return undef; } sub merge($$) { - my Xerl::Tools::FileIO( $self, $other ) = @_; + my Xerl::Tools::FileIO( $self, $other ) = @_; - my @merged = ( @{ $self->get_array() }, @{ $other->get_array() } ); - my Xerl::Tools::FileIO $fio = Xerl::Tools::FileIO->new(); + my @merged = ( @{ $self->get_array() }, @{ $other->get_array() } ); + my Xerl::Tools::FileIO $fio = Xerl::Tools::FileIO->new(); - $fio->set_array( \@merged ); - return $fio; + $fio->set_array( \@merged ); + return $fio; } sub shift($) { - my Xerl::Tools::FileIO $self = $_[0]; - chomp( my $shift = shift @{ $self->get_array() } ); + my Xerl::Tools::FileIO $self = $_[0]; + chomp( my $shift = shift @{ $self->get_array() } ); - return $shift; + return $shift; } sub pop($) { - my Xerl::Tools::FileIO $self = $_[0]; - chomp( my $pop = pop @{ $self->get_array() } ); + my Xerl::Tools::FileIO $self = $_[0]; + chomp( my $pop = pop @{ $self->get_array() } ); - return $pop; + return $pop; } use overload '+' => \&merge; sub SECUREPATH($) { - my $path = $_[0]; + my $path = $_[0]; - $path =~ s/\.\.+\/?//g; + $path =~ s/\.\.+\/?//g; - return $path; + return $path; } 1; diff --git a/Xerl/XML/Element.pm b/Xerl/XML/Element.pm index 13c963f..ba94807 100644 --- a/Xerl/XML/Element.pm +++ b/Xerl/XML/Element.pm @@ -35,77 +35,77 @@ use warnings; use Xerl::Base; sub starttag($$) { - my Xerl::XML::Element $self = $_[0]; - my ( $name, $temp ) = ( $_[1], undef ); + my Xerl::XML::Element $self = $_[0]; + my ( $name, $temp ) = ( $_[1], undef ); - return $self if $self->get_name() eq $name; - return undef if ref $self->get_array() ne 'ARRAY'; + return $self if $self->get_name() eq $name; + return undef if ref $self->get_array() ne 'ARRAY'; - for ( @{ $self->get_array() } ) { - $temp = $_->starttag($name); - return $temp if defined $temp; - } + for ( @{ $self->get_array() } ) { + $temp = $_->starttag($name); + return $temp if defined $temp; + } - return undef; + return undef; } sub starttag2($$$) { - my Xerl::XML::Element $self = $_[0]; - my ( $name, $after ) = @_[ 1 ... 2 ]; + my Xerl::XML::Element $self = $_[0]; + my ( $name, $after ) = @_[ 1 ... 2 ]; - my Xerl::XML::Element $element = $self->starttag($name); - return $element->starttag($after) if defined $element; + my Xerl::XML::Element $element = $self->starttag($name); + return $element->starttag($after) if defined $element; - return undef; + return undef; } sub params_str($) { - my Xerl::XML::Element $self = $_[0]; - my $params = $self->get_params(); + my Xerl::XML::Element $self = $_[0]; + my $params = $self->get_params(); - return if $params eq ''; + return if $params eq ''; - return join '', map { " $_=\"" . $params->{$_} . '"' } keys %$params; + return join '', map { " $_=\"" . $params->{$_} . '"' } keys %$params; } # Only for testing sub print($) { - my Xerl::XML::Element $self = $_[0]; - print $self. "::print(\$)\n"; - - my $sub; - $sub = sub { - my ( $element, $spaceing ) = @_; - my $spaces = ' ' x $spaceing; - - print $spaces, '<', $element->get_name(), ">\n"; - print "$spaces [$_=", _no_newline( $$element{$_} ), "]\n" - for keys %$element; - - #if ($element->exists('params')) { - if ( $element->params_exists() ) { - print "$spaces Params:\n"; - while ( my ( $key, $val ) = each %{ $element->get_params() } ) { - print "$spaces $key=$val\n"; - } - } - - return unless ref $element->get_array() eq 'ARRAY'; - $sub->( $_, $spaceing + 1 ) for @{ $element->get_array() }; - }; - - $sub->( $self, 0 ); - print $self. "::print(\$)::END\n"; - - return undef; + my Xerl::XML::Element $self = $_[0]; + print $self. "::print(\$)\n"; + + my $sub; + $sub = sub { + my ( $element, $spaceing ) = @_; + my $spaces = ' ' x $spaceing; + + print $spaces, '<', $element->get_name(), ">\n"; + print "$spaces [$_=", _no_newline( $$element{$_} ), "]\n" + for keys %$element; + + #if ($element->exists('params')) { + if ( $element->params_exists() ) { + print "$spaces Params:\n"; + while ( my ( $key, $val ) = each %{ $element->get_params() } ) { + print "$spaces $key=$val\n"; + } + } + + return unless ref $element->get_array() eq 'ARRAY'; + $sub->( $_, $spaceing + 1 ) for @{ $element->get_array() }; + }; + + $sub->( $self, 0 ); + print $self. "::print(\$)::END\n"; + + return undef; } sub _no_newline($) { - my $line = $_[0]; + my $line = $_[0]; - $line =~ s/\n//g; + $line =~ s/\n//g; - return $line; + return $line; } 1; diff --git a/Xerl/XML/Reader.pm b/Xerl/XML/Reader.pm index 2562fea..e31ef11 100644 --- a/Xerl/XML/Reader.pm +++ b/Xerl/XML/Reader.pm @@ -1,6 +1,6 @@ # Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # -# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org +# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # # All rights reserved. # @@ -12,8 +12,8 @@ # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of buetow.org nor the names of its contributors may -# be used to endorse or promote products derived from this software -# without specific prior written permission. +# 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 @@ -32,172 +32,136 @@ package Xerl::XML::Reader; use strict; use warnings; +use XML::LibXML; + use Xerl::Base; use Xerl::XML::Element; +sub newparse($) { + my Xerl::XML::Reader $self = shift; + + return undef; +} + sub open($) { - my Xerl::XML::Reader $self = $_[0]; + my Xerl::XML::Reader $self = $_[0]; - my Xerl::Tools::FileIO $xmlfile = - Xerl::Tools::FileIO->new( path => $self->get_path() ); + my Xerl::Tools::FileIO $xmlfile = + Xerl::Tools::FileIO->new( path => $self->get_path() ); - return -1 if -1 == $xmlfile->fslurp(); - $self->set_array( $xmlfile->get_array() ); + return -1 if -1 == $xmlfile->fslurp(); + $self->set_array( $xmlfile->get_array() ); - return 0; + return 0; } sub parse($) { - my Xerl::XML::Reader $self = $_[0]; - - my $rarray = $self->get_array(); - return $self unless ref $rarray eq 'ARRAY'; - - my Xerl::XML::Element $element = Xerl::XML::Element->new(); - my Xerl::XML::Element( $root, $next, $prev, $insert ); - - # Prove and remove XML Header. - Xerl::Main::Global::ERROR( 'No valid XML header', caller() ) - unless $rarray->[0] =~ s/<\?xml .*?version.+?\?>//io; - - my ( $newlineadd, $linecount, $notrim ) = ( 0, 0, 0 ); - - #for my $line (@$rarray) { - for my $line (@$rarray) { - $newlineadd = 1 if length $line == 1 and $linecount > 3; - ++$linecount; - - $line =~ s/\\/!!GT!!/g; - - # Allow - my $is_single_tag = $line =~ s#<([^/].+?)( (.*?))? ?/ *>#<$1 $3>#o; - - my $flag = 0; - - do { - - # Open XML tag - if ( $line =~ s#<([^/].+?)( (.*?))? *>##o ) { - my ( $name, $params ) = ( $1, $3 ); - $flag = 1; - - # Ignore XML comments - next if $name =~ /^!--/o; - - $next = Xerl::XML::Element->new(); - $next->set_name($name); - $next->set_prev($element); - $next->set_single($is_single_tag); - - # Handle tag parameters - if ( defined $params ) { - my %params = $params =~ / - (?: ( [^\s]+? ) \s*=\s* ( - (?: '(?:.|(?:\\'))*?' ) | - (?: "(?:.|(?:\\"))*?" ) | - (?: [^\s]+ ) ) ) - /gox; - - # Remove " and ' - $params{$_} =~ s/^(?:"|')|(?:"|')$//go for keys %params; - $next->set_params( \%params ); - $notrim = 1 if exists $params{notrim}; - } - - $element->push_array($next); - - $root = $element unless defined $root; - $element = $next; - $insert = $element; - - redo; - } - - # Close XML tag - if ( $line =~ s#<(/.+?)>##o ) { - $flag = 1; - - #print "XML::<$1>\n"; - if ( $element->get_name() eq 'includefiles' ) { - my $config = $self->get_config(); - my $params = $element->get_params(); - my $path = - $config->get_hostpath() . 'content/' . $params->{reldir}; - my $pattern = $params->{pattern}; - my $maxitems = - exists $params->{maxitems} ? $params->{maxitems} : 100; - my $startindex = - exists $params->{startindex} ? $params->{startindex} : 0; - - my Xerl::Tools::FileIO $io = - Xerl::Tools::FileIO->new( path => $path ); - - $io->dslurp(); - $io->reverse_array() if exists $params->{reversed}; - - for - my $include ( grep { /$pattern/o } @{ $io->get_array() } ) - { - last unless $maxitems--; - next if 0 < $startindex--; - - my Xerl::XML::Reader $reader = Xerl::XML::Reader->new( - path => $include, - config => $config - ); - - if ( -1 == $reader->open() ) { - $config->set_finish_request(1); - return undef; - } - $reader->parse(); - - my Xerl::XML::Element $starttag = - $reader->get_root()->starttag('content'); - - my $sep = - exists $params->{separator} - ? $params->{separator} - : 'noop'; - $starttag->set_name($sep); - $element->set_name('noop'); - $element->push_array($starttag); - } - } - - $insert = $element; - $prev = $element->get_prev(); - $element = $prev if defined $prev; - $notrim = 0 if $notrim; - - redo; - } - - # XML text - if ( defined $insert - and $line =~ s/^( *)(.+?) *$/$notrim ? $1.$2 : $2/oe ) - { - - if ($newlineadd) { - $insert->append_text("\n"); - $newlineadd = 0; - } - - $line =~ s/!!LT!!//g; - - $insert->append_text($line); - } - } while ( $flag == 1 ); - } - - $root->set_name('root'); - - # $root->print(); - $self->set_root($root); - - return undef; + my Xerl::XML::Reader $self = $_[0]; + + $self->newparse( $self->get_path() ); + + my $rarray = $self->get_array(); + return $self unless ref $rarray eq 'ARRAY'; + + my Xerl::XML::Element $element = Xerl::XML::Element->new(); + my Xerl::XML::Element( $root, $next, $prev, $insert ); + + # Prove and remove XML Header. + Xerl::Main::Global::ERROR( 'No valid XML header', caller() ) + unless $rarray->[0] =~ s/<\?xml .*?version.+?\?>//io; + + my ( $newlineadd, $linecount, $notrim ) = ( 0, 0, 0 ); + + #for my $line (@$rarray) { + for my $line (@$rarray) { + $newlineadd = 1 if length $line == 1 and $linecount > 3; + ++$linecount; + + $line =~ s/\\/!!GT!!/g; + + # Allow + my $is_single_tag = $line =~ s#<([^/].+?)( (.*?))? ?/ *>#<$1 $3>#o; + + my $flag = 0; + + do { + + # Open XML tag + if ( $line =~ s#<([^/].+?)( (.*?))? *>##o ) { + my ( $name, $params ) = ( $1, $3 ); + $flag = 1; + + # Ignore XML comments + next if $name =~ /^!--/o; + + $next = Xerl::XML::Element->new(); + $next->set_name($name); + $next->set_prev($element); + $next->set_single($is_single_tag); + + # Handle tag parameters + if ( defined $params ) { + my %params = $params =~ / + (?: ( [^\s]+? ) \s*=\s* ( + (?: '(?:.|(?:\\'))*?' ) | + (?: "(?:.|(?:\\"))*?" ) | + (?: [^\s]+ ) ) ) + /gox; + + # Remove " and ' + $params{$_} =~ s/^(?:"|')|(?:"|')$//go for keys %params; + $next->set_params( \%params ); + $notrim = 1 if exists $params{notrim}; + } + + $element->push_array($next); + + $root = $element unless defined $root; + $element = $next; + $insert = $element; + + redo; + } + + # Close XML tag + if ( $line =~ s#<(/.+?)>##o ) { + $flag = 1; + + #print "XML::<$1>\n"; + + $insert = $element; + $prev = $element->get_prev(); + $element = $prev if defined $prev; + $notrim = 0 if $notrim; + + redo; + } + + # XML text + if ( defined $insert + and $line =~ s/^( *)(.+?) *$/$notrim ? $1.$2 : $2/oe ) + { + + if ($newlineadd) { + $insert->append_text("\n"); + $newlineadd = 0; + } + + $line =~ s/!!LT!!//g; + + $insert->append_text($line); + } + } while ( $flag == 1 ); + } + + $root->set_name('root'); + + # $root->print(); + $self->set_root($root); + + return undef; } 1; diff --git a/index.fpl b/index.fpl index 11be5fc..d13cd6f 100755 --- a/index.fpl +++ b/index.fpl @@ -16,6 +16,6 @@ my $config = : ( -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' ); while ( FCGI::accept >= 0 ) { - my Xerl $xerl = Xerl->new( config => $config ); - $xerl->run(); + my Xerl $xerl = Xerl->new( config => $config ); + $xerl->run(); } -- cgit v1.2.3 From 1b8eb9cbb10cd4dc4902b41aa2ff88d4f18aa7e5 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 15 Sep 2013 12:38:41 +0200 Subject: No XML error with external XML parser --- Xerl/XML/Reader.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Xerl/XML/Reader.pm b/Xerl/XML/Reader.pm index e31ef11..c349443 100644 --- a/Xerl/XML/Reader.pm +++ b/Xerl/XML/Reader.pm @@ -37,9 +37,11 @@ use XML::LibXML; use Xerl::Base; use Xerl::XML::Element; -sub newparse($) { +sub process($) { my Xerl::XML::Reader $self = shift; + my $doc = XML::LibXML->load_xml(location => $self->get_path()); + return undef; } @@ -58,7 +60,7 @@ sub open($) { sub parse($) { my Xerl::XML::Reader $self = $_[0]; - $self->newparse( $self->get_path() ); + my $process = $self->process(); my $rarray = $self->get_array(); return $self unless ref $rarray eq 'ARRAY'; @@ -92,14 +94,20 @@ sub parse($) { my ( $name, $params ) = ( $1, $3 ); $flag = 1; + my $DEBUG = $name =~ /^=/ ? 1 : 0; + $self->debug($name, $params) if $DEBUG; + # Ignore XML comments next if $name =~ /^!--/o; + $next = Xerl::XML::Element->new(); $next->set_name($name); $next->set_prev($element); $next->set_single($is_single_tag); + $next->print() if $DEBUG; + # Handle tag parameters if ( defined $params ) { my %params = $params =~ / -- cgit v1.2.3 From af4ddb3afc5e0fe4c77b9df3bcb4ea4aa2d33c8d Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 15 Sep 2013 12:39:16 +0200 Subject: add universal debug method --- Xerl/Base.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Xerl/Base.pm b/Xerl/Base.pm index 6b71565..589e325 100644 --- a/Xerl/Base.pm +++ b/Xerl/Base.pm @@ -118,6 +118,11 @@ sub AUTOLOAD { elsif ( $auto =~ /.*::(.+)_isset$/ ) { return exists $self->{$1} ? $self->{ $_[0] } : 0; + } + elsif ( $auto =~ /.*::debug$/ ) { + print "DEBUG: @_\n"; + return undef; + } else { print "$auto is not a method of $self or UNIVERSAL\n"; -- cgit v1.2.3 From 1b9b7434445e84eef29ccfda9a80b54c19343df5 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (pluto.buetow.org)" Date: Sun, 15 Sep 2013 12:56:45 +0200 Subject: remove libXML --- Xerl/Page/Content.pm | 2 -- Xerl/Page/Templates.pm | 10 +++++----- Xerl/XML/Reader.pm | 12 ------------ 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/Xerl/Page/Content.pm b/Xerl/Page/Content.pm index bd3e8ee..d9d7d34 100644 --- a/Xerl/Page/Content.pm +++ b/Xerl/Page/Content.pm @@ -213,8 +213,6 @@ sub _insert_special_vars($$$$) { $$rtext =~ s/@\@text\@\@/$_=$element->get_text();chomp;$_/geo; $$rtext =~ s/@\@ln\@\@//go; - #$$rtext =~ s/@\@link\@\@/$element->get_params()->{link}.'$$params$$'/geo; - if ( $$rtext =~ /@\@(.*?)\@\@/ ) { my $params = $element->get_params(); return unless ref $params eq 'HASH'; diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm index 3b7d13f..e018682 100644 --- a/Xerl/Page/Templates.pm +++ b/Xerl/Page/Templates.pm @@ -1,6 +1,6 @@ # Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow # -# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org +# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org # # All rights reserved. # @@ -12,8 +12,8 @@ # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of buetow.org nor the names of its contributors may -# be used to endorse or promote products derived from this software -# without specific prior written permission. +# 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 @@ -188,8 +188,8 @@ sub PARSELINE($$$;$) { $$line =~ s/$sep(!)?(.+?)$sep/ defined $1 ? `$2` : (ref $config->getval($2) eq 'ARRAY') - ? join '', @{$config->getval($2)} : - $config->getval($2)/eg and $$foundflag = 1; + ? join '', @{$config->getval($2)} : + $config->getval($2)/eg and $$foundflag = 1; return undef; } diff --git a/Xerl/XML/Reader.pm b/Xerl/XML/Reader.pm index c349443..3605c04 100644 --- a/Xerl/XML/Reader.pm +++ b/Xerl/XML/Reader.pm @@ -32,19 +32,9 @@ package Xerl::XML::Reader; use strict; use warnings; -use XML::LibXML; - use Xerl::Base; use Xerl::XML::Element; -sub process($) { - my Xerl::XML::Reader $self = shift; - - my $doc = XML::LibXML->load_xml(location => $self->get_path()); - - return undef; -} - sub open($) { my Xerl::XML::Reader $self = $_[0]; @@ -60,8 +50,6 @@ sub open($) { sub parse($) { my Xerl::XML::Reader $self = $_[0]; - my $process = $self->process(); - my $rarray = $self->get_array(); return $self unless ref $rarray eq 'ARRAY'; -- cgit v1.2.3