Authentication/User.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 5 / 5 totaltotal 81.2% 52 / 64 CC 8 SCAR 9.9
CC
8
Cov
81%
supports
4.1
get
3.6
AUTOLOAD
3.1
CRAP 2.7
« Authentication/Credential/NoPassword.pm ↑ Summary Plugin/Authentication/User.pm »
1 package Catalyst::Authentication::User;
2 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 with 'MooseX::Emulate::Class::Accessor::Fast';
6 7 ▶use Scalar::Util qw/refaddr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 ## auth_realm is the realm this user came from.
9 7 __PACKAGE__->mk_accessors(qw/auth_realm store/);
10  
11 ## THIS IS NOT A COMPLETE CLASS! it is intended to provide base functionality only.
12 ## translation - it won't work if you try to use it directly.
13  
14 ## chances are you want to override this.
15 0 ▶sub id { shift->get('id'); }
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
16  
17 ## this relies on 'supported_features' being implemented by the subclass..
18 ## but it is not an error if it is not. it just means you support nothing.
19 ## nihilist user objects are welcome here.
20 4 ▶sub supports {
Subroutine supports: called CC=4 SCAR=14.0
Pod documented
21 4 my ( $self, @spec ) = @_;
22  
23 4 my $cursor = undef;
24 4 ▶ if ($self->can('supported_features')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("supported_features")) 4 0 4
25 4 $cursor = $self->supported_features;
26  
27 # traverse the feature list,
28 4 for (@spec) {
29 #die "bad feature spec: @spec" if ref($cursor) ne "HASH";
30 6 ▶ return if ref($cursor) ne "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $cursor ne "HASH" 0 6 6
31  
32 6 $cursor = $cursor->{$_};
33 }
34 }
35  
36 4 return $cursor;
37 }
38  
39 ## REQUIRED.
40 ## get should return the value of the field specified as it's single argument from the underlying
41 ## user object. This is here to provide a simple, standard way of accessing individual elements of a user
42 ## object - ensuring no overlap between C::P::A::User methods and actual fieldnames.
43 ## this is not the most effecient method, since it uses introspection. If you have an underlying object
44 ## you most likely want to write this yourself.
45 6 ▶sub get {
Subroutine get: called CC=3 SCAR=12.7
Pod documented
46 6 my ($self, $field) = @_;
47  
48 6 my $object;
49 6 ▶ if ($object = $self->get_object and $object->can($field)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object = $self->get_object and $object->can($field)) { } 6 0 6
Condition33%1/3
$object = $self->get_object and $object->can($field)
!ll&&!rl&&r
006
MC/DC0%0/2
$object = $self->get_object and $object->can($field)
$object = $self->get_object $object->can($field)
Truth table33%1/3
A and B
A= $object = $self->get_objectB= $object->can($field)
ABresult
0X0
100
111
50 6 return $object->$field();
51 } else {
52 0 return undef;
53 }
54 }
55  
56 ## REQUIRED.
57 ## get_object should return the underlying user object. This is for when more advanced uses of the
58 ## user is required. Modifications to the existing user, etc. Changes in the object returned
59 ## by this routine may not be reflected in the C::P::A::User object - if this is required, re-authenticating
60 ## the user is probably the best route to take.
61 ## note that it is perfectly acceptable to return $self in cases where there is no underlying object.
62 6 ▶sub get_object {
Subroutine get_object: called CC=1 SCAR=0.0
Pod documented
63 6 return shift;
64 }
65  
66 ## obj is shorthand for get_object. This is originally from the DBIx::Class store, but
67 ## as it has become common usage, this makes things more compatible. Plus, it's shorter.
68 1 ▶sub obj {
Subroutine obj: called CC=1 SCAR=0.0
Pod documented
69 1 my $self = shift;
70 1 return $self->get_object(@_);
71 }
72  
73 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
74 1 my $self = shift;
75 1 (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
76 1 ▶ return if $method eq "DESTROY";
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "DESTROY" 0 1 1
77  
78 1 my $obj = $self->obj;
79 # Don't bother unless we have a backing object
80 1 ▶ return if refaddr($obj) eq refaddr($self);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($obj) eq builtin::refaddr($self) 0 1 1
81  
82 1 $obj->$method(@_);
83 }
84  
85 7 __PACKAGE__;
86  
87 __END__
« Authentication/Credential/NoPassword.pm ↑ Summary Plugin/Authentication/User.pm »