| 1 | package Catalyst::Authentication::Store::FromSub; | ||||||||||||||
| 2 | 1 | our $VERSION = '0.01'; | |||||||||||||
| 3 | |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | # ABSTRACT: A storage class for Catalyst Authentication using one Catalyst Model class | ||||||||||||||
| 8 | |||||||||||||||
| 9 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 10 | 0 | my ( $class, $config, $app ) = @_; | |||||||||||||
| 11 | |||||||||||||||
| 12 | # load User or Object module | ||||||||||||||
| 13 | 0 | my $user_type = $config->{user_type}; | |||||||||||||
| 14 | 0 | ▶ | if ( $user_type eq 'Hash' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 15 | 0 | Catalyst::Utils::ensure_class_loaded( | |||||||||||||
| 16 | 'Catalyst::Authentication::User::Hash'); | ||||||||||||||
| 17 | 0 | $config->{user_type} = 'Catalyst::Authentication::User::Hash'; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | elsif ( $user_type eq 'Object' ) { | ||||||||||||||
| 20 | 0 | Catalyst::Utils::ensure_class_loaded( | |||||||||||||
| 21 | 'Catalyst::Authentication::FromSub::User::Object'); | ||||||||||||||
| 22 | $config->{user_type} = | ||||||||||||||
| 23 | 0 | 'Catalyst::Authentication::FromSub::User::Object'; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | else { | ||||||||||||||
| 26 | 0 | Catalyst::Utils::ensure_class_loaded($user_type); | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | bless { config => $config }, $class; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | ▶ | sub from_session { | ||||||||||||
|
Subroutine
from_session: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 33 | 0 | my ( $self, $c, $id ) = @_; | |||||||||||||
| 34 | |||||||||||||||
| 35 | # Don't use data in session because data maybe changed in model_class sub auth. | ||||||||||||||
| 36 | # return $id if ref $id; | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | my $id_field = $self->{config}->{id_field} || 'id'; | ||||||||||||
|
Condition0%0/2
$self->{'config'}{'id_field'} || 'id'
MC/DC0%0/1
$self->{'config'}{'id_field'} || 'id'
$self->{'config'}{'id_field'}
Truth table0%0/2
A
A= $self->{'config'}{'id_field'}
| |||||||||||||||
| 39 | 0 | ▶ | if ( ref $id ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | 0 | ▶ | if ( exists $id->{$id_field} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 0 | return $self->find_user( { $id_field => $id->{$id_field} }, $c ); | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | else { | ||||||||||||||
| 44 | 0 | return $id; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | $self->find_user( { $id_field => $id }, $c ); | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | ▶ | sub for_session { | ||||||||||||
|
Subroutine
for_session: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 52 | 0 | my ( $self, $c, $user ) = @_; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | return $user->for_session($c); | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | sub find_user { | ||||||||||||
|
Subroutine
find_user: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 58 | 0 | my ( $self, $userinfo, $c ) = @_; | |||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | my $config = $self->{config}; | |||||||||||||
| 61 | 0 | my $model_class = $config->{model_class}; | |||||||||||||
| 62 | 0 | my $model = $c->model($model_class); | |||||||||||||
| 63 | |||||||||||||||
| 64 | 0 | my $user = $model->auth( $c, $userinfo ); | |||||||||||||
| 65 | 0 | ▶ | return unless $user; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | ▶ | if ( $config->{user_type} eq 'Catalyst::Authentication::User::Hash' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 0 | return $config->{user_type}->new($user); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | else { | ||||||||||||||
| 71 | return $config->{user_type} | ||||||||||||||
| 72 | 0 | ->new( { user => $user, storage => $self }, $c ); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | ▶ | sub user_supports { | ||||||||||||
|
Subroutine
user_supports: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||
| 78 | |||||||||||||||
| 79 | # this can work as a class method on the user class | ||||||||||||||
| 80 | 0 | $self->{config}->{user_type}->supports(@_); | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 1 | 1; | |||||||||||||
| 84 | __END__ | ||||||||||||||