Simple/Adapter.pm

filter: Statementstmt 95.6% 66 / 69 Branchbran 83.3% 20 / 24 Conditioncond 50.0% 9 / 18 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 84.6% 11 / 13 Podpod 100% 6 / 6 totaltotal 80.8% 114 / 141 CC 20 SCAR 19.2
CC
20
Cov
86%
authenticate
12.2
options
7.6
new
2.1
CRAP 6.8
« Simple/Password.pm ↑ Summary Simple.pm »
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
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (() = each %{$params;}) 11 5 16
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
l!l&&r!l&&!r
1300
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($self->callback) 3 10 13
58  
59 3 $status = $self->callback->( \$username, \$password );
60  
61 3 ▶ if ( defined $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $status) 2 1 3
62  
63 2 ▶ my $boolean = $status ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 1 1 2
64  
65 2 ▶ $self->log->debug( qq/Callback returned a $boolean value '$status' for user '$username'./ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->log 2 0 2
66 if $self->log;
67  
68 2 return $status;
69 }
70 }
71  
72 11 ▶ if ( $self->cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache) 4 7 11
73  
74 4 $status = $self->cache->get("$username:$password");
75  
76 4 ▶ if ( defined $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $status) 1 3 4
77  
78 1 ▶ $self->log->debug( qq/Successfully authenticated user '$username' from cache./ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->log 1 0 1
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
BranchTrueFalseTotal
if ($self->cache and $status) 1 9 10
Condition100%3/3
$self->cache and $status
!ll&&!rl&&r
721
MC/DC100%2/2
$self->cache and $status
$self->cache $status
Truth table100%3/3
A and B
A= $self->cacheB= $status
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $self->log 1 0 1
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
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
110  
111 9 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 5 9
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
BranchTrueFalseTotal
if (my(@create) = grep({not $class->can($_);} keys %{$options;})) 4 0 4
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}
l!l
04
MC/DC0%0/1
$options->{"cache"} ||= {"type", 512, "can", ["get", "set"], "optional", 1}
$options->{"cache"}
Truth table50%1/2
A
A= $options->{"cache"}
Aresult
11
00
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}
l!l
04
MC/DC0%0/1
$options->{"callback"} ||= {"type", 8, "optional", 1}
$options->{"callback"}
Truth table50%1/2
A
A= $options->{"callback"}
Aresult
11
00
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}
l!l
04
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"}
Aresult
11
00
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__
« Simple/Password.pm ↑ Summary Simple.pm »