Call init at first request to allow --preload-app
[plack-middleware-auth-complex.git] / lib / Plack / Middleware / Auth / Complex.pm
index 057bfd7fbe96a343a8cb712a4e74555358829982..ac70da693554a5aec710f194b3e386ba93fcf874 100644 (file)
@@ -4,7 +4,7 @@ use 5.014000;
 use strict;
 use warnings;
 
-our $VERSION = '0.000_001';
+our $VERSION = '0.001';
 
 use parent qw/Plack::Middleware/;
 use re '/s';
@@ -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<init>
 
-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<post_connect_cb> and prepares the
 SQL statements.
 
@@ -486,19 +491,19 @@ Returns a 401 Authorization required response.
 
 =item B<call_register>(I<$req>)
 
-Handles the C</register> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/register> endpoint. I<$req> is a Plack::Request object.
 
 =item B<call_passwd>(I<$req>)
 
-Handles the C</passwd> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/passwd> endpoint. I<$req> is a Plack::Request object.
 
 =item B<call_request_reset>(I<$req>)
 
-Handles the C</request-reset> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/request-reset> endpoint. I<$req> is a Plack::Request object.
 
 =item B<call_reset>(I<$req>)
 
-Handles the C</reset> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/reset> endpoint. I<$req> is a Plack::Request object.
 
 =back
 
This page took 0.011642 seconds and 4 git commands to generate.