From 5c70ffb3e08998d2324add1c2ad8606a975274f9 Mon Sep 17 00:00:00 2001 From: Patrick Donelan Date: Sun, 18 Apr 2010 14:51:24 -0400 Subject: [PATCH] Minor improvements Updated TODO Enabled preloading Added defaultPSGI to WebGUI::Paths Added example of testing site via Plack::Test --- TODO | 3 ++- app.psgi | 7 ++----- lib/WebGUI/Paths.pm | 1 + lib/WebGUI/Session/ErrorHandler.pm | 2 +- lib/WebGUI/Session/Form.pm | 5 +---- t/PSGI/default-site.t | 23 +++++++++++++++++++++++ var/site.psgi | 8 -------- 7 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 t/PSGI/default-site.t diff --git a/TODO b/TODO index b61b64347..e771de9ba 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,9 @@ TODO * Deprecate WebGUI::Session::HTTP - replace with WebGUI::Request/Response * Investigate moving Cookie handling into middleware -* Replace WebGUI::authen with something equivalent +* Reinstate WebGUI::authen with something equivalent * Refactor assets to use streaming response +* Fix WebGUI::Form::param DONE * $session->request is now a Plack::Request object diff --git a/app.psgi b/app.psgi index b18377b1b..09c4498e3 100644 --- a/app.psgi +++ b/app.psgi @@ -1,16 +1,13 @@ use strict; use Plack::Builder; -use WebGUI::Paths -inc; +use WebGUI::Paths -preload; use WebGUI::Config; -use File::Spec; - -my $standard_psgi = File::Spec->catfile(WebGUI::Paths->var, 'site.psgi'); builder { my $first_app; for my $config_file (WebGUI::Paths->siteConfigs) { my $config = WebGUI::Config->new($config_file); - my $psgi = $config->get('psgiFile') || $standard_psgi; + my $psgi = $config->get('psgiFile') || WebGUI::Paths->defaultPsgi; my $app = do { $ENV{WEBGUI_CONFIG} = $config_file; Plack::Util::load_psgi($psgi); diff --git a/lib/WebGUI/Paths.pm b/lib/WebGUI/Paths.pm index ef2dfc446..22238e932 100644 --- a/lib/WebGUI/Paths.pm +++ b/lib/WebGUI/Paths.pm @@ -107,6 +107,7 @@ BEGIN { defaultUploads => catdir($root, 'www', 'uploads'), defaultCreateSQL => catdir($root, 'docs', 'create.sql'), var => catdir($root, 'var'), + defaultPSGI => catdir($root, 'var', 'site.psgi'), ); my $meta = Class::MOP::Class->initialize(__PACKAGE__); for my $sub (keys %paths) { diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index 19c0d5a4a..c6b8770cc 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -207,7 +207,7 @@ sub new { # Thanks to Plack, wG has been decoupled from Log4Perl # However when called outside a web context, we currently still fall back to Log4perl # (pending a better idea) - Log::Log4perl->init_once( $session->config->getWebguiRoot . "/etc/log.conf" ); + Log::Log4perl->init_once( WebGUI::Paths->logConfig ); my $log4perl = Log::Log4perl->get_logger( $session->config->getFilename ); $logger = sub { my $args = shift; diff --git a/lib/WebGUI/Session/Form.pm b/lib/WebGUI/Session/Form.pm index e773ed408..d2e79038b 100644 --- a/lib/WebGUI/Session/Form.pm +++ b/lib/WebGUI/Session/Form.pm @@ -78,10 +78,7 @@ Returns true if the param is part of the submitted form data, or a URL param. sub hasParam { my $self = shift; my $param = shift; - return undef unless $param; - return undef unless $self->session->request; - my $hashRef = $self->session->request->param(); - return exists $hashRef->{$param}; + return $param && $self->session->request && exists $self->session->request->parameters->{$param}; } diff --git a/t/PSGI/default-site.t b/t/PSGI/default-site.t new file mode 100644 index 000000000..b2799756d --- /dev/null +++ b/t/PSGI/default-site.t @@ -0,0 +1,23 @@ +use strict; +use warnings; +use Test::More tests => 4; + +use Plack::Test; +use Plack::Util; +use HTTP::Request::Common; +use WebGUI::Paths; + +my $app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI ); + +test_psgi $app, sub { + my $cb = shift; + + my $res = $cb->( GET "/" ); + is $res->code, 200; + like $res->content, qr/My Company/; + + $res = $cb->( GET "/?op=editSettings" ); + is $res->code, 401; + like $res->content, qr/Administrative Function/; + +}; diff --git a/var/site.psgi b/var/site.psgi index 9176aa277..232cb562c 100644 --- a/var/site.psgi +++ b/var/site.psgi @@ -2,16 +2,8 @@ use strict; use Plack::Builder; use Plack::App::File; use WebGUI; - -# Temporary preload hack -use WebGUI::Paths -preload; -use DBI; -DBI->install_driver("mysql"); -# end hack - use WebGUI::Middleware::Debug::Performance; -my $config = $ENV{WEBGUI_CONFIG}; builder { my $wg = WebGUI->new( site => $ENV{WEBGUI_CONFIG} ); my $config = $wg->config;