CatalystX/OAuth2/Schema/Result/RefreshToken.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 5 totaltotal 84.7% 39 / 46 SCAR 0.0
CC
1
Cov
97%
from_access_token
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« CatalystX/OAuth2/Request/ProtectedResource.pm ↑ Summary CatalystX/OAuth2/Schema/ResultSet/Client.pm »
1 package CatalystX::OAuth2::Schema::Result::RefreshToken;
2 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use parent 'DBIx::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: A table for registering refresh tokens
7  
8 10 __PACKAGE__->load_components(qw(Core));
9 10 __PACKAGE__->table('refresh_token');
10 10 __PACKAGE__->add_columns(
11 id => { data_type => 'int', is_auto_increment => 1 },
12 code_id => { data_type => 'int', is_nullable => 0 },
13 );
14 10 __PACKAGE__->set_primary_key(qw(id));
15  
16 10 __PACKAGE__->add_unique_constraint( [qw(id code_id)] );
17  
18 10 __PACKAGE__->belongs_to( code => 'CatalystX::OAuth2::Schema::Result::Code' =>
19 { 'foreign.id' => 'self.code_id' } );
20  
21 # this is a has many but will only ever return a single record
22 # because of the constraint on the relationship table
23 10 __PACKAGE__->has_many(
24 from_access_token_map =>
25 'CatalystX::OAuth2::Schema::Result::AccessTokenToRefreshToken' => {
26 'foreign.refresh_token_id' => 'self.id',
27 'foreign.code_id' => 'self.code_id'
28 }
29 );
30 10 __PACKAGE__->many_to_many(
31 from_access_token_map_m2m => from_access_token_map => 'access_token' );
32  
33 # this is a has many but will only ever return a single record
34 # because of the constraint on the relationship table
35 10 __PACKAGE__->has_many(
36 to_access_token_map =>
37 'CatalystX::OAuth2::Schema::Result::RefreshTokenToAccessToken' => {
38 'foreign.refresh_token_id' => 'self.id',
39 'foreign.code_id' => 'self.code_id'
40 }
41 );
42 10 __PACKAGE__->many_to_many(
43 to_access_token_map_m2m => to_access_token_map => 'access_token' );
44  
45 0 ▶sub from_access_token { shift->from_access_token_map_m2m->first }
Subroutine from_access_token: not called CC=1 SCAR=6.9
Pod undocumented
46 2 ▶sub to_access_token { shift->to_access_token_map_m2m->first }
Subroutine to_access_token: called CC=1 SCAR=0.0
Pod undocumented
47  
48 sub create_access_token {
49 2 ▶ my ($self) = @_;
Subroutine create_access_token: called CC=1 SCAR=0.0
Pod undocumented
50 2 my $code = $self->code;
51 2 my $token;
52 $self->result_source->storage->txn_do(
53 sub {
54 # create a new token from this refresh token
55 2 ▶ $token = $code->tokens->create(
Subroutine __ANON__: called CC=1 SCAR=0.0
56 { from_refresh_token_map => [ { refresh_token => $self } ] } );
57  
58 # create a new refresh token and add it to the new token
59 2 my $refresh = $code->refresh_tokens->create( {} );
60 2 $token->to_refresh_token_map->create(
61 { code => $code, refresh_token => $refresh } );
62 }
63 2 );
64 2 return $token;
65 }
66  
67 # if we have already created a token from this refresh, de-activate it
68 1 ▶sub is_active { !shift->to_access_token_map->count }
Subroutine is_active: called CC=1 SCAR=0.0
Pod undocumented
69  
70 2 ▶sub as_string { shift->id }
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
71  
72 10 1;
73  
74 __END__
75  
76 =pod
77  
78 =head1 NAME
79  
80 CatalystX::OAuth2::Schema::Result::RefreshToken - A table for registering refresh tokens
81  
82 =head1 VERSION
83  
84 version 0.001006
85  
86 =head1 AUTHOR
87  
88 Eden Cardim <edencardim@gmail.com>
89  
90 =head1 COPYRIGHT AND LICENSE
91  
92 This software is copyright (c) 2017 by Suretec Systems Ltd.
93  
94 This is free software; you can redistribute it and/or modify it under
95 the same terms as the Perl 5 programming language system itself.
96  
97 =cut
« CatalystX/OAuth2/Request/ProtectedResource.pm ↑ Summary CatalystX/OAuth2/Schema/ResultSet/Client.pm »