Apache-Session-Generate-UUID

 view release on metacpan or  search on metacpan

lib/Apache/Session/Generate/UUID.pm  view on Meta::CPAN


use Data::UUID;

our $VERSION = '0.2';

sub generate {
    my ($session) = @_;
    return $session->{'data'}->{'_session_id'} = Data::UUID->new->create_str();
}

sub validate {
    my ($session) = @_;
    if ($session->{'data'}->{'_session_id'} !~ /^[a-fA-F0-9\-]+$/xm) { die; }
    return 1;
}

1;
__END__

=pod

lib/Apache/Session/Generate/UUID.pm  view on Meta::CPAN

better using RDBMS like MySQL for its storage.

=head1 CONFIGURATION

There are no configuration options.

=head1 FUNCTIONS

=head2 generate

=head2 validate

=head1 AUTHOR

Nick Gerakines, C<< <nick at socklabs.com> >>

=head1 BUGS

Please report any bugs or feature requests to
C<bug-apache-session-generate-uuid at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache-Session-Generate-UUID>.

t/11-new.t  view on Meta::CPAN

    $id = $session->{'data'}->{'_session_id'};
};

test 'session uniqueness' => sub {
    Apache::Session::Generate::UUID::generate($session);
    isnt $id, $session->{'data'}->{'_session_id'}, 'old session id does not match new one';
};

test 'session validation' => sub {
    Apache::Session::Generate::UUID::generate($session);
    ok Apache::Session::Generate::UUID::validate($session), 'session id validates';
    $session->{'data'}->{'_session_id'} = 'asdasd' . time;
    dies_ok { Apache::Session::Generate::UUID::validate($session); } 'session id does not validate';
};



( run in 0.302 second using v1.01-cache-2.11-cpan-4d50c553e7e )