Apache-Hendrix

 view release on metacpan or  search on metacpan

lib/Apache/Hendrix/Session.pm  view on Meta::CPAN

    my ($options) = @_;
    __PACKAGE__->options($options) if $options;
    return __PACKAGE__->options();
}

sub session_start {
    my $r = Apache::Hendrix->request;

    # Extract old session ID.  If not found we create a new one below
    my $id;
    if ( $r->headers_in->get('Cookie') =~ m/SESSION_ID=(\w*)/ ) {
        $id = $1;
    }

    my %session;
    try {
	tie %session, __PACKAGE__->type, $id, __PACKAGE__->options;
    } catch ($e) {
	if ($e =~ /Object does not exist in the data store/) {
	    tie %session, __PACKAGE__->type, undef, __PACKAGE__->options;
	}
	else {
	    croak $e;
	}
    }

    # Might be a new session, so lets give them their cookie back
    my $session_cookie = "SESSION_ID=$session{_session_id};";
    $r->headers_out->set( 'Set-Cookie' => $session_cookie );
    return \%session;
}

__PACKAGE__->meta->make_immutable;

1;

__END__

=pod



( run in 0.555 second using v1.01-cache-2.11-cpan-e9199f4ba4c )