CatalystX/OAuth2/ClientInjector.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 75.0% 3 / 4 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 2 totaltotal 78.7% 63 / 80 SCAR 18.1
CC
6
Cov
86%
_apply_client_role
3.0
restore_token
2.5
persist_token
2.5
CRAP 6.1
« CatalystX/OAuth2/Request/GrantAuth.pm ↑ Summary Catalyst/ActionRole/OAuth2/ProtectedResource.pm »
1 package CatalystX::OAuth2::ClientInjector;
2 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use MooseX::NonMoose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use CatalystX::OAuth2::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: A role for automatically providing an oauth2 client to authenticated user objects
8  
9 3 requires qw(find_user restore_user persist_user);
10  
11 around 'find_user' => sub {
12 2 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
13 2 my $self = shift;
14 2 my ( $authinfo, $c ) = @_;
15 2 my $user = $self->$orig(@_);
16 2 ▶ my $token = $authinfo->{token} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $token = $authinfo->{"token"} or return 0 2 2
17 2 $self->_apply_client_role( $user, $authinfo->{token} );
18 2 return $user;
19 3 };
20  
21 around 'restore_user' => sub {
22 1 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 my $self = shift;
24 1 my ($c) = @_;
25 1 my $user = $self->$orig(@_);
26 1 my $token = $self->restore_token($c);
27 1 $self->_apply_client_role( $user, $token );
28 1 return $user;
29 3 };
30  
31 before persist_user => sub {
32 1 ▶ my ( $self, $c, $user ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 $self->persist_token( $c, $user );
34 3 };
35  
36 sub restore_token {
37 1 ▶ my ( $self, $c ) = @_;
Subroutine restore_token: called CC=2 SCAR=9.2
Pod undocumented
38 1 ▶ return ( $c->can('session') || sub { {} } )->($c)->{__oauth2}{token};
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$c->can('session') || sub {
l!l&&r!l&&!r
100
MC/DC0%0/2
$c->can('session') || sub { {}; }
$c->can('session') sub { {}; }
Truth table33%1/3
A || B
A= $c->can('session')B= sub { {}; }
ABresult
1X1
011
000
39 }
40  
41 sub persist_token {
42 1 ▶ my ( $self, $c, $user ) = @_;
Subroutine persist_token: called CC=2 SCAR=9.2
Pod undocumented
43 0 ▶ ( $c->can('session') || sub { {} } )->($c)->{__oauth2}{token} =
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 1 ▶ $user->oauth2->token;
Condition33%1/3
$c->can('session') || sub {
l!l&&r!l&&!r
100
MC/DC0%0/2
$c->can('session') || sub { {}; }
$c->can('session') sub { {}; }
Truth table33%1/3
A || B
A= $c->can('session')B= sub { {}; }
ABresult
1X1
011
000
45 }
46  
47 sub _apply_client_role {
48 3 ▶ my ( $self, $user, $token ) = @_;
Subroutine _apply_client_role: called CC=3 SCAR=11.0
49 3 my $oauth2 = $self->_build_oauth2_client($token);
50 3 ▶ if ( UNIVERSAL::isa( 'Moose::Object', $user ) or !$user->can('oauth2') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa('Moose::Object', $user) or not $user->can('oauth2')) { } 1 2 3
Condition66%2/3
UNIVERSAL::isa("Moose::Object", $user) or not $user->can("oauth2")
l!l&&r!l&&!r
012
MC/DC50%1/2
UNIVERSAL::isa("Moose::Object", $user) or not $user->can("oauth2")
UNIVERSAL::isa("Moose::Object", $user) not $user->can("oauth2")
Truth table66%2/3
A or not(B)
A= UNIVERSAL::isa("Moose::Object", $user)B= not $user->can("oauth2")
ABresult
1X1
011
000
51 1 Moose::Util::ensure_all_roles(
52 $user,
53 'CatalystX::OAuth2::ClientContainer',
54 { rebless_params => { oauth2 => $oauth2 } }
55 );
56 } else {
57 2 $user->oauth2($oauth2);
58 }
59 }
60  
61 sub _build_oauth2_client {
62 3 ▶ my ( $self, $token ) = @_;
Subroutine _build_oauth2_client: called CC=1 SCAR=0.0
63 3 return CatalystX::OAuth2::Client->new( token => $token );
64 }
65  
66 3 1;
67  
68 __END__
69  
70 =pod
71  
72 =head1 NAME
73  
74 CatalystX::OAuth2::ClientInjector - A role for automatically providing an oauth2 client to authenticated user objects
75  
76 =head1 VERSION
77  
78 version 0.001006
79  
80 =head1 AUTHOR
81  
82 Eden Cardim <edencardim@gmail.com>
83  
84 =head1 COPYRIGHT AND LICENSE
85  
86 This software is copyright (c) 2017 by Suretec Systems Ltd.
87  
88 This is free software; you can redistribute it and/or modify it under
89 the same terms as the Perl 5 programming language system itself.
90  
91 =cut
« CatalystX/OAuth2/Request/GrantAuth.pm ↑ Summary Catalyst/ActionRole/OAuth2/ProtectedResource.pm »