NAME

CGI::Session::Auth::Mouse::Role - CGI::Session::Auth をMouseのRoleで作ってみました。Mouse勉強用でしたw

VERSION

This document describes CGI::Session::Auth::Mouse::Role version 0.0.3

SYNOPSIS

BEGIN {
    package MyApp::Auth;

    use Mouse;

    with qw/CGI::Session::Auth::Mouse::Role/;

    has 'user_info' => ( is => 'ro', isa => 'HashRef',
        default => sub {
            return {
                hoge => {
                    password => 'huga',
                    age      => 20,
                    favorite => 'orange',
                },
                moge => {
                    password => 'moga',
                    age      => 30,
                    favorite => 'apple',
                }
            };
        },
    );
    has 'profiles' => ( is => 'rw', isa => 'HashRef' );

    sub login {
        my $self = shift;
        my ( $username, $password ) = @_;
        if ( exists $self->user_info->{$username} ) {
            $self->_set_profile($self->user_info->{$username});
            return 1 if ( $self->user_info->{$username}->{password} eq $password );
        }
        return;
    }
    sub _set_profile {
        my ( $self, $info ) = @_;
        delete $info->{password};
        $self->profile( $info );
    }
    sub load_profile { return shift->profile; }
}
my $auth = MyApp::Auth->new(
    cgi     => new CGI,
    session => new Session,
);
$auth->authenticate();
if ( $auth->logged_in ) {
    ## show secret page
}
else {
    ## show login page
}

SAMPLE HTML

<form method="POST" action="sample.cgi">
    <input type="text" name="login_username" />
    <input type="password" name="login_password" />
    <input type="submit" value="submit" />
</form>

METHODS

authenticate

authenticate method

logged_in

Returns a boolean value representing the current visitors authentication status.

logout

logout method

BUGS AND LIMITATIONS

Please report any bugs or feature requests to bug-cgi-session-auth-mouse-role@rt.cpan.org, or through the web interface at http://rt.cpan.org.

DEPENDENCIES

Mouse Mouse::Role CGI::Session

SEE ALSO

CGI::Session CGI::Session::Auth Mouse Mouse::Role

AUTHOR

<noblejasper> <<nobjas@gmail.com>>

LICENCE AND COPYRIGHT

Copyright (c) 2009, <noblejasper> <<nobjas@gmail.com>>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.