Minor improvements

Updated TODO
Enabled preloading
Added defaultPSGI to WebGUI::Paths
Added example of testing site via Plack::Test
This commit is contained in:
Patrick Donelan 2010-04-18 14:51:24 -04:00
parent f99f672b06
commit 5c70ffb3e0
7 changed files with 30 additions and 19 deletions

3
TODO
View file

@ -1,8 +1,9 @@
TODO TODO
* Deprecate WebGUI::Session::HTTP - replace with WebGUI::Request/Response * Deprecate WebGUI::Session::HTTP - replace with WebGUI::Request/Response
* Investigate moving Cookie handling into middleware * Investigate moving Cookie handling into middleware
* Replace WebGUI::authen with something equivalent * Reinstate WebGUI::authen with something equivalent
* Refactor assets to use streaming response * Refactor assets to use streaming response
* Fix WebGUI::Form::param
DONE DONE
* $session->request is now a Plack::Request object * $session->request is now a Plack::Request object

View file

@ -1,16 +1,13 @@
use strict; use strict;
use Plack::Builder; use Plack::Builder;
use WebGUI::Paths -inc; use WebGUI::Paths -preload;
use WebGUI::Config; use WebGUI::Config;
use File::Spec;
my $standard_psgi = File::Spec->catfile(WebGUI::Paths->var, 'site.psgi');
builder { builder {
my $first_app; my $first_app;
for my $config_file (WebGUI::Paths->siteConfigs) { for my $config_file (WebGUI::Paths->siteConfigs) {
my $config = WebGUI::Config->new($config_file); 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 { my $app = do {
$ENV{WEBGUI_CONFIG} = $config_file; $ENV{WEBGUI_CONFIG} = $config_file;
Plack::Util::load_psgi($psgi); Plack::Util::load_psgi($psgi);

View file

@ -107,6 +107,7 @@ BEGIN {
defaultUploads => catdir($root, 'www', 'uploads'), defaultUploads => catdir($root, 'www', 'uploads'),
defaultCreateSQL => catdir($root, 'docs', 'create.sql'), defaultCreateSQL => catdir($root, 'docs', 'create.sql'),
var => catdir($root, 'var'), var => catdir($root, 'var'),
defaultPSGI => catdir($root, 'var', 'site.psgi'),
); );
my $meta = Class::MOP::Class->initialize(__PACKAGE__); my $meta = Class::MOP::Class->initialize(__PACKAGE__);
for my $sub (keys %paths) { for my $sub (keys %paths) {

View file

@ -207,7 +207,7 @@ sub new {
# Thanks to Plack, wG has been decoupled from Log4Perl # Thanks to Plack, wG has been decoupled from Log4Perl
# However when called outside a web context, we currently still fall back to Log4perl # However when called outside a web context, we currently still fall back to Log4perl
# (pending a better idea) # (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 ); my $log4perl = Log::Log4perl->get_logger( $session->config->getFilename );
$logger = sub { $logger = sub {
my $args = shift; my $args = shift;

View file

@ -78,10 +78,7 @@ Returns true if the param is part of the submitted form data, or a URL param.
sub hasParam { sub hasParam {
my $self = shift; my $self = shift;
my $param = shift; my $param = shift;
return undef unless $param; return $param && $self->session->request && exists $self->session->request->parameters->{$param};
return undef unless $self->session->request;
my $hashRef = $self->session->request->param();
return exists $hashRef->{$param};
} }

23
t/PSGI/default-site.t Normal file
View file

@ -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/;
};

View file

@ -2,16 +2,8 @@ use strict;
use Plack::Builder; use Plack::Builder;
use Plack::App::File; use Plack::App::File;
use WebGUI; use WebGUI;
# Temporary preload hack
use WebGUI::Paths -preload;
use DBI;
DBI->install_driver("mysql");
# end hack
use WebGUI::Middleware::Debug::Performance; use WebGUI::Middleware::Debug::Performance;
my $config = $ENV{WEBGUI_CONFIG};
builder { builder {
my $wg = WebGUI->new( site => $ENV{WEBGUI_CONFIG} ); my $wg = WebGUI->new( site => $ENV{WEBGUI_CONFIG} );
my $config = $wg->config; my $config = $wg->config;