From d332726d5726e639bc597493c3db9e79fe5a0174 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Mon, 2 Mar 2015 16:05:33 +0200 Subject: [PATCH] Call init at first request to allow --preload-app --- lib/Plack/Middleware/Auth/Complex.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Plack/Middleware/Auth/Complex.pm b/lib/Plack/Middleware/Auth/Complex.pm index 758e0c2..ac70da6 100644 --- a/lib/Plack/Middleware/Auth/Complex.pm +++ b/lib/Plack/Middleware/Auth/Complex.pm @@ -43,7 +43,6 @@ sub new { my %self = $class->default_opts; %self = (%self, %$opts); my $self = bless \%self, $class; - $self->init; $self } @@ -232,6 +231,12 @@ sub call_reset { sub call { my ($self, $env) = @_; + + unless ($self->{init_done}) { + $self->init; + $self->{init_done} = 1; + } + my $auth = $env->{HTTP_AUTHORIZATION}; if ($auth && $auth =~ /^Basic (.*)$/i) { my ($user, $pass) = split /:/, decode_base64($1), 2; @@ -420,7 +425,7 @@ Creates a new AuthComplex object. =item B -Called at the end of the constructor. The default implementation +Called when the first request is received. The default implementation connects to the database, calls C and prepares the SQL statements. -- 2.39.2