Apache2::Controller::Log::SessionSave - Log phase handler to save


Apache2-Controller documentation Contained in the Apache2-Controller distribution.

Index


Code Index:

NAME

Top

Apache2::Controller::Log::SessionSave - Log phase handler to save session data from Apache2::Controller::Session hook.

VERSION

Top

Version 1.000.111

SYNOPSIS

Top

Don't do anything with this handler. It's set by Apache2::Controller::Session to save your session.

METHODS

Top

process

If aborted connection, don't save, and return.

If status >- 300 and not set $r->pnotes->{a2c}{session_force_save}, don't save, and return.

If session object is not tied, throw an error. This may not do anything noticible to the user since the request response is finished, but you'll see it in the log.

Update the top-level timestamp in the session if the directive A2C_Session_Always_Save is set.

Untie the session so Apache::Session saves it or not.

SEE ALSO

Top

Apache2::Controller::Session

Apache2::Controller

Apache::Session

AUTHOR

Top

Mark Hedges, <hedges at formdata.biz>

COPYRIGHT & LICENSE

Top


Apache2-Controller documentation Contained in the Apache2-Controller distribution.
package Apache2::Controller::Log::SessionSave;

use version;
our $VERSION = version->new('1.000.111');

use strict;
use warnings FATAL => 'all';
use English '-no_match_vars';

use base qw( 
    Apache2::Controller::NonResponseBase 
    Apache2::Controller::Methods 
);

use YAML::Syck;
use Log::Log4perl qw(:easy);

use Apache2::Const -compile => qw( OK HTTP_MULTIPLE_CHOICES );
use Apache2::RequestUtil ();
use Apache2::Controller::X;
use Apache2::Controller::Const qw( $DEFAULT_SESSION_SECRET );

sub process {
    my ($self) = @_;
    my $r = $self->{r};

    DEBUG "A2C session cleanup: start handler sub";

    my $pnotes_a2c = $r->pnotes->{a2c};

    # just return if connection was detected as aborted in Log phase
    # while the connection was still open
    if ($pnotes_a2c->{connection_aborted}) {
        DEBUG "Connection aborted.  NOT saving session.";
        return Apache2::Const::OK;
    }

    # don't save if the status code >= 300 and they have not
    # set the special force-save flag.
    my $http_status = $r->status;
    if ($http_status >= Apache2::Const::HTTP_MULTIPLE_CHOICES) {
        if ($pnotes_a2c->{session_force_save}) {
            DEBUG "status $http_status, but pnotes->{a2c}{session_force_save} is set."
        }
        else {
            DEBUG "status $http_status, not saving session.";
            return Apache2::Const::OK;
        }
    }

    DEBUG "connection not aborted, saving session...";

    # connection finished successfully thru whole cycle, so save session
    my $tied_session = $pnotes_a2c->{_tied_session};
    a2cx 'no tied session in pnotes when saving' if !defined $tied_session;
    a2cx 'pnotes->{a2c}{_tied_session} is not actually tied when saving'
        if !tied %{$tied_session};
    DEBUG "ref of pnotes tied_session is '$tied_session'.";

    my $session_copy = $pnotes_a2c->{session};
    a2cx 'no pnotes->{a2c}{session}' if !defined $session_copy;

    # set the top-level timestamp to force Apache::Session to save
    # if our flag is set in directives.
    $session_copy->{a2c_timestamp} = time
        if $self->get_directive('A2C_Session_Always_Save');

    DEBUG sub{
        "putting copy data back into tied session:\n".Dump($session_copy)
    };
    %{$tied_session} = %{$session_copy}; 

    DEBUG sub {
        my %debug_sess = %{$tied_session};
        "real session is now:\n".Dump(\%debug_sess);
    };

    DEBUG "untying session to save it";
    untie %{$tied_session};
    undef $tied_session;

    DEBUG "Done saving session in PerlLogHandler";
    return Apache2::Const::OK;
};


1;