Auth0/Management/Base.pm

filter: Statementstmt 32.0% 17 / 53 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 22.2% 4 / 18 Podpod 72.7% 8 / 11 totaltotal 29.5% 29 / 98 CC 8 SCAR 31.9
CC
8
Cov
25%
uri_for
72.0
__ANON__
2.0
request
2.0
CRAP 24.2
« Auth0/UA/LWP.pm ↑ Summary Auth0.pm »
1 package WebService::Auth0::Management::Base;
2  
3 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use HTTP::Request::Common ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 has domain => (
9 is=>'ro',
10 required=>1 );
11  
12 3 has token => (
13 is=>'ro',
14 required=>1 );
15  
16 3 has ua => (
17 is=>'ro',
18 required=>1 );
19  
20 has mgmt_path_parts => (
21 is=>'ro',
22 required=>1,
23 0 ▶ isa=>sub { ref($_) eq 'ARRAY' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 ▶ default=>sub {['api', 'v2']} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
25  
26 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
27 0 my ($self, $request) = @_;
28 0 $request->push_header(Authorization => "Bearer ${\$self->token}");
29 0 return $self->ua->request($request);
30 }
31  
32 0 ▶sub GET { shift->request(HTTP::Request::Common::GET @_) }
Subroutine GET: not called CC=1 SCAR=6.9
Pod documented
33 0 ▶sub POST { shift->request(HTTP::Request::Common::POST @_) }
Subroutine POST: not called CC=1 SCAR=6.9
Pod documented
34 0 ▶sub PUT { shift->request(HTTP::Request::Common::PUT @_) }
Subroutine PUT: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ▶sub DELETE { shift->request(HTTP::Request::Common::DELETE @_) }
Subroutine DELETE: not called CC=1 SCAR=6.9
36 0 ▶sub PATCH { shift->request(HTTP::Request::Common::request_type_with_data('PATCH', @_)) }
Subroutine PATCH: not called CC=1 SCAR=6.9
Pod documented
37  
38 0 ▶sub encode_json { shift; JSON::MaybeXS::encode_json(shift) }
Subroutine encode_json: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 0 ▶sub POST_JSON {
Subroutine POST_JSON: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($self, $uri, $json) = @_;
42 0 return $self->POST( $uri,
43 'content-type' => 'application/json',
44 Content => $self->encode_json($json));
45 }
46  
47 0 ▶sub PUT_JSON {
Subroutine PUT_JSON: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my ($self, $uri, $json) = @_;
49 0 return $self->PUT( $uri,
50 'content-type' => 'application/json',
51 Content => $self->encode_json($json));
52 }
53  
54 0 ▶sub PATCH_JSON {
Subroutine PATCH_JSON: not called CC=1 SCAR=6.9
Pod documented
55 0 my ($self, $uri, $json) = @_;
56 0 return $self->PATCH( $uri,
57 'content-type' => 'application/json',
58 Content => $self->encode_json($json));
59 }
60  
61 0 ▶sub uri_for {
Subroutine uri_for: not called CC=8 SCAR=42.8
Pod documented
62 0 my $self = shift;
63 0 my @query = ();
64 0 ▶ if(my $type = ref($_[-1]||'')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = ref($_[-1] || "")) 0 0 0
Condition0%0/2
$_[-1] || ''
l!l
00
MC/DC0%0/1
$_[-1] || ''
$_[-1]
Truth table0%0/2
A
A= $_[-1]
Aresult
11
00
65 0 ▶ if($type eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 0 0 0
elsif ($type eq 'HASH') { } 0 0 0
66 0 @query = @{pop(@_)};
67 } elsif($type eq 'HASH') {
68 0 @query = %{pop(@_)};
69 }
70 }
71 0 ▶ @query = map { ref($_)||'' eq 'ARRAY' ? join(',', @$_): $_ } @query;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ || !1 ? : 0 0 0
Condition0%0/2
ref $_ or
l!l
00
MC/DC0%0/1
ref $_ or
ref $_
Truth table0%0/2
A
A= ref $_
Aresult
11
00
72 0 my $uri = URI->new("https://${\$self->domain}/");
73 0 $uri->path_segments(@{$self->mgmt_path_parts}, $self->path_suffix, @_);
74 0 ▶ $uri->query_form(@query) if @query;
Branch: 1 branch
BranchTrueFalseTotal
if @query 0 0 0
75 0 return $uri;
76 }
77  
78 0 ▶sub path_suffix { die "Extending class must override" }
Subroutine path_suffix: not called CC=1 SCAR=6.9
Pod documented
79  
80 =head1 NAME
81  
82 WebService::Auth0::Management::Base - Base class for the Management API
83  
84 =head1 SYNOPSIS
85  
86 package WebService::Auth0::Management::Users;
87  
88 use Moo;
89 extends 'WebService::Auth0::Management::Base';
90 with 'WebService::Auth0::Management::Role::All',
91 'WebService::Auth0::Management::Role::Search',
92 'WebService::Auth0::Management::Role::Create',
93 'WebService::Auth0::Management::Role::Get',
94 'WebService::Auth0::Management::Role::Update',
95 'WebService::Auth0::Management::Role::Delete'; # Optional helpers
96  
97 sub path_suffix { 'users' } # You need to override this
98  
99 # Other custom methods for the endpoint.
100  
101 1;
102  
103 =head1 DESCRIPTION
104  
105 A Base class for managment API endpoints
106  
107 =head1 METHODS
108  
109 This class defines the following methods:
110  
111 =head2 request
112  
113 =head2 GET
114  
115 =head2 POST
116  
117 =head2 POST_JSON
118  
119 =head2 DELETE
120  
121 =head2 PATCH
122  
123 =head2 PATCH_JSON
124  
125 =head2 uri_for
126  
127 =head2 path_suffix
128  
129 =head1 ATTRIBUTES
130  
131 This class defines the following attributes:
132  
133 =head2 domain
134  
135 =head2 token
136  
137 =head2 ua
138  
139 =head2 mgmt_path_parts
140  
141 =head1 SEE ALSO
142
143 L<WebService::Auth0>, L<https://auth0.com>.
144  
145 =head1 AUTHOR
146
147 See L<WebService::Auth0>
148
149 =head1 COPYRIGHT & LICENSE
150
151 See L<WebService::Auth0>
152  
153 =cut
154  
155 3 1;
« Auth0/UA/LWP.pm ↑ Summary Auth0.pm »