Permalink
Browse files

fix to load and hack app class only once

  • Loading branch information...
1 parent ce6fa03 commit 3c0ccaf0502b359a4a6cc4a779c94cea7dc0b6b4 @miyagawa committed Oct 1, 2009
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/Maypole/PSGI.pm
View
14 lib/Maypole/PSGI.pm
@@ -6,8 +6,8 @@ our $VERSION = '0.01';
use UNIVERSAL::require;
-sub run {
- my($class, $module, $env) = @_;
+sub new {
+ my($class, $module) = @_;
$module->require or die "Couldn't load $module: $@";
@@ -18,7 +18,12 @@ sub run {
$_ = "Maypole::PSGI::Application" if $_ eq 'CGI::Maypole';
}
- $module->run_psgi($env);
+ bless { module => $module }, $class;
+}
+
+sub run {
+ my($self, $env) = @_;
+ $self->{module}->run_psgi($env);
}
package Maypole::PSGI::Application;
@@ -110,7 +115,8 @@ Maypole::PSGI - Runs Maypole application as PSGI application
use BeerDB;
use Maypole::PSGI;
- my $handler = sub { Maypole::PSGI->run('BeerDB', @_) };
+ my $app = Maypole::PSGI->new('BeerDB');
+ my $handler = sub { $app->run(@_) };
=head1 DESCRIPTION

0 comments on commit 3c0ccaf

Please sign in to comment.