Authentication/Store/Minimal.pm

filter: Statementstmt 65.7% 25 / 38 Branchbran 62.5% 5 / 8 Conditioncond 42.8% 6 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 62.5% 5 / 8 Podpod 100% 5 / 5 totaltotal 56.7% 46 / 81 CC 10 SCAR 18.5
CC
10
Cov
60%
find_user
10.6
from_session
6.0
new
2.0
CRAP 6.4
« Authentication/Realm.pm ↑ Summary Authentication/Realm/Progressive.pm »
1 package Catalyst::Authentication::Store::Minimal;
2 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 with 'MooseX::Emulate::Class::Accessor::Fast';
6 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 __PACKAGE__->mk_accessors(qw/userhash userclass/);
9  
10 6 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
11 6 my ( $class, $config, $app, $realm) = @_;
12  
13 my $self = bless {
14 userhash => $config->{'users'},
15 6 ▶ userclass => $config->{'user_class'} || "Catalyst::Authentication::User::Hash",
Condition50%1/2
$config->{'user_class'} || 'Catalyst::Authentication::User::Hash'
l!l
06
MC/DC0%0/1
$config->{'user_class'} || 'Catalyst::Authentication::User::Hash'
$config->{'user_class'}
Truth table50%1/2
A
A= $config->{'user_class'}
Aresult
11
00
16 }, $class;
17  
18 6 Catalyst::Utils::ensure_class_loaded( $self->userclass );
19  
20 6 return $self;
21 }
22  
23 0 ▶sub from_session {
Subroutine from_session: not called CC=2 SCAR=17.9
Pod documented
24 0 my ( $self, $c, $id ) = @_;
25  
26 0 ▶ return $id if ref $id;
Branch: 1 branch
BranchTrueFalseTotal
if ref $id 0 0 0
27  
28 0 $self->find_user( { id => $id } );
29 }
30  
31 ## this is not necessarily a good example of what find_user can do, since all we do is
32 ## look up with the id anyway. find_user can be used to locate a user based on other
33 ## combinations of data. See C::P::Authentication::Store::DBIx::Class for a better example
34 14 ▶sub find_user {
Subroutine find_user: called CC=8 SCAR=23.6
Pod documented
35 14 my ( $self, $userinfo, $c ) = @_;
36  
37 14 my $id = $userinfo->{'id'};
38  
39 14 ▶ $id ||= $userinfo->{'username'};
Condition66%2/3
$id ||= $userinfo->{"username"}
l!l&&r!l&&!r
770
MC/DC0%0/2
$id ||= $userinfo->{"username"}
$id $userinfo->{"username"}
Truth table66%2/3
A ||= B
A= $idB= $userinfo->{"username"}
ABresult
1X1
011
000
40  
41 14 ▶ return unless exists $self->userhash->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->userhash->{$id} 1 13 14
42  
43 13 my $user = $self->userhash->{$id};
44  
45 13 ▶ if ( ref($user) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $user eq 'HASH') { } 12 1 13
elsif (ref $user and builtin::blessed($user) and $user->isa('Catalyst::Authentication::User::Hash')) { } 1 0 1
46 12 ▶ $user->{id} ||= $id;
Condition33%1/3
$user->{"id"} ||= $id
l!l&&r!l&&!r
0120
MC/DC0%0/2
$user->{"id"} ||= $id
$user->{"id"} $id
Truth table33%1/3
A ||= B
A= $user->{"id"}B= $id
ABresult
1X1
011
000
47 12 return bless $user, $self->userclass;
48 ▶ } elsif ( ref($user) && blessed($user) && $user->isa('Catalyst::Authentication::User::Hash')) {
Condition33%2/6
ref $user and builtin::blessed($user) and $user->isa("Catalyst::Authentication::User::Hash")
!ll&&!rl&&r
001
ref $user and builtin::blessed($user)
!ll&&!rl&&r
001
MC/DC0%0/3
ref $user and builtin::blessed($user) and $user->isa("Catalyst::Authentication::User::Hash")
ref $user builtin::blessed($user) $user->isa("Catalyst::Authentication::User::Hash")
Truth table25%1/4
A and B and C
A= ref $userB= builtin::blessed($user)C= $user->isa("Catalyst::Authentication::User::Hash")
ABCresult
0XX0
10X0
1100
1111
49 1 return $user;
50 } else {
51 0 Catalyst::Exception->throw( "The user '$id' must be a hash reference or an " .
52 "object of class Catalyst::Authentication::User::Hash");
53 }
54 0 return $user;
55 }
56  
57 0 ▶sub user_supports {
Subroutine user_supports: not called CC=1 SCAR=6.9
Pod documented
58 0 my $self = shift;
59  
60 # choose a random user
61 0 scalar keys %{ $self->userhash };
62 0 ( undef, my $user ) = each %{ $self->userhash };
63  
64 0 $user->supports(@_);
65 }
66  
67 ## Backwards compatibility
68 #
69 # This is a backwards compatible routine. get_user is specifically for loading a user by it's unique id
70 # find_user is capable of doing the same by simply passing { id => $id }
71 # no new code should be written using get_user as it is deprecated.
72 0 ▶sub get_user {
Subroutine get_user: not called CC=1 SCAR=6.9
Pod documented
73 0 my ( $self, $id ) = @_;
74 0 $self->find_user({id => $id});
75 }
76  
77 4 __PACKAGE__;
78  
79 __END__
« Authentication/Realm.pm ↑ Summary Authentication/Realm/Progressive.pm »