| 1 | package Authen::Simple::Adapter; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use base qw[Class::Accessor::Fast Class::Data::Inheritable]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Authen::Simple::Log qw[]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Authen::Simple::Password qw[]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Carp qw[]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Params::Validate qw[]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | __PACKAGE__->mk_classdata( _options => { } ); | |||||||||||||||||||||||||||
| 13 | 5 | __PACKAGE__->mk_accessors( qw[ cache callback log ] ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 5 | my $proto = shift; | |||||||||||||||||||||||||||
| 17 | 5 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | my $params = Params::Validate::validate_with( | |||||||||||||||||||||||||||
| 20 | params => \@_, | ||||||||||||||||||||||||||||
| 21 | spec => $class->options, | ||||||||||||||||||||||||||||
| 22 | called => "$class\::new" | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | return $class->SUPER::new->init($params); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 5 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 5 | ▶ | while ( my ( $method, $value ) = each( %{ $params } ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 11 | $self->$method($value); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | return $self; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 13 | ▶ | sub authenticate { | ||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 13 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 13 | my ( $username, $password ) = Params::Validate::validate_with( | |||||||||||||||||||||||||||
| 43 | params => \@_, | ||||||||||||||||||||||||||||
| 44 | spec => [ | ||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | type => Params::Validate::SCALAR | ||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | type => Params::Validate::SCALAR | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | ], | ||||||||||||||||||||||||||||
| 52 | called => "$class\::authenticate" | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 13 | my $status; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 13 | ▶ | if ( $self->callback ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | $status = $self->callback->( \$username, \$password ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | if ( defined $status ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | my $boolean = $status ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | $self->log->debug( qq/Callback returned a $boolean value '$status' for user '$username'./ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | if $self->log; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | return $status; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 11 | ▶ | if ( $self->cache ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | $status = $self->cache->get("$username:$password"); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | if ( defined $status ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | $self->log->debug( qq/Successfully authenticated user '$username' from cache./ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | if $self->log; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | return $status; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 10 | $status = $self->check( $username, $password ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 10 | ▶ | if ( $self->cache && $status ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->cache and $status
MC/DC100%2/2
$self->cache and $status
$self->cache
$status
Truth table100%3/3
A and B
A= $self->cacheB= $status
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | $self->cache->set( "$username:$password" => $status ); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | ▶ | $self->log->debug( qq/Caching successful authentication status '$status' for user '$username'./ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | if $self->log; | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 10 | return $status; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 0 | Carp::croak( __PACKAGE__ . qq/->check is an abstract method/ ); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub check_password { | ||||||||||||||||||||||||||
|
Subroutine
check_password: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | 0 | return Authen::Simple::Password->check(@_); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 9 | ▶ | sub options { | ||||||||||||||||||||||||||
|
Subroutine
options: called CC=7 SCAR=20.3
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 9 | my $proto = shift; | |||||||||||||||||||||||||||
| 109 | 9 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 9 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 4 | my ($options) = Params::Validate::validate_pos( @_, { type => Params::Validate::HASHREF } ); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 4 | ▶ | if ( my @create = grep { ! $class->can($_) } keys %{ $options } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 4 | $class->mk_accessors(@create); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | $options->{cache} ||= { | ||||||||||||||||||||||||||||
| 120 | 4 | ▶ | type => Params::Validate::OBJECT, | ||||||||||||||||||||||||||
|
Condition50%1/2
$options->{"cache"} ||= {"type", 512, "can", ["get", "set"], "optional", 1}
MC/DC0%0/1
$options->{"cache"} ||= {"type", 512, "can", ["get", "set"], "optional", 1}
$options->{"cache"}
Truth table50%1/2
A
A= $options->{"cache"}
| |||||||||||||||||||||||||||||
| 121 | can => [ qw[get set] ], | ||||||||||||||||||||||||||||
| 122 | optional => 1 | ||||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | $options->{callback} ||= { | ||||||||||||||||||||||||||||
| 126 | 4 | ▶ | type => Params::Validate::CODEREF, | ||||||||||||||||||||||||||
|
Condition50%1/2
$options->{"callback"} ||= {"type", 8, "optional", 1}
MC/DC0%0/1
$options->{"callback"} ||= {"type", 8, "optional", 1}
$options->{"callback"}
Truth table50%1/2
A
A= $options->{"callback"}
| |||||||||||||||||||||||||||||
| 127 | optional => 1 | ||||||||||||||||||||||||||||
| 128 | }; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | $options->{log} ||= { | ||||||||||||||||||||||||||||
| 131 | 4 | ▶ | type => Params::Validate::OBJECT, | ||||||||||||||||||||||||||
|
Condition50%1/2
$options->{"log"} ||= {"type", 512, "can", ["debug", "info", "error", "warn"], "default", "Authen::Simple::Log"->new, "optional", 1}
MC/DC0%0/1
$options->{"log"} ||= {"type", 512, "can", ["debug", "info", "error", "warn"], "default", "Authen::Simple::Log"->new, "optional", 1}
$options->{"log"}
Truth table50%1/2
A
A= $options->{"log"}
| |||||||||||||||||||||||||||||
| 132 | can => [ qw[debug info error warn] ], | ||||||||||||||||||||||||||||
| 133 | default => Authen::Simple::Log->new, | ||||||||||||||||||||||||||||
| 134 | optional => 1 | ||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 4 | $class->_options($options); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 9 | return $class->_options; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 5 | 1; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||