PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|Authen|Simple|Adapter.pm =

page 1 of 3



package Authen::Simple::Adapter;

use strict;
use warnings;
use base qw[Class::Accessor::Fast Class::Data::Inheritable];

use Authen::Simple::Log      qw[];
use Authen::Simple::Password qw[];
use Carp                     qw[];
use Params::Validate         qw[];

__PACKAGE__->mk_classdata( _options => { } );
__PACKAGE__->mk_accessors( qw[ cache callback log ] );

sub new {
    my $proto  = shift;
    my $class  = ref($proto) || $proto;

    my $params = Params::Validate::validate_with(
        params => \@_,
        spec   => $class->options,
        called => "$class\::new"
    );

    return $class->SUPER::new->init($params);
}

sub init {
    my ( $self, $params ) = @_;

    while ( my ( $method, $value ) = each( %{ $params } ) ) {
        $self->$method($value);
    }

    return $self;
}

sub authenticate {
    my $self  = shift;
    my $class = ref($self) || $self;

    my ( $username, $password ) = Params::Validate::validate_with(
        params => \@_,
        spec   => [
            {
                type => Params::Validate::SCALAR
            },
            {
                type => Params::Validate::SCALAR
            }
        ],
        called => "$class\::authenticate"
    );

    my $status;

    if ( $self->callback ) {

        $status = $self->callback->( \$username, \$password );

        if ( defined $status ) {

            my $boolean = $status ? 'true' : 'false';

            $self->log->debug( qq/Callback returned a $boolean value '$status' for user '$username'./ )
              if $self->log;

            return $status;
        }
    }

    if ( $self->cache ) {

        $status = $self->cache->get("$username:$password");

        if ( defined $status ) {

            $self->log->debug( qq/Successfully authenticated user '$username' from cache./ )
              if $self->log;

            return $status;
        }
    }

    $status = $self->check( $username, $password );

    if ( $self->cache && $status ) {

        $self->cache->set( "$username:$password" => $status );
        
        $self->log->debug( qq/Caching successful authentication status '$status' for user '$username'./ )
          if $self->log;
    }

    return $status;
}

sub check {
    Carp::croak( __PACKAGE__ . qq/->check is an abstract method/ );
}
=1=

= PAGE 1 = NEXT > |2|3

UP TO ROOT | UP TO DIR

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.0052948 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)