Client/Request.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 94.4% 17 / 18 Conditioncond 77.7% 14 / 18 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 87.5% 84 / 96 SCAR 27.8
CC
16
Cov
92%
_build_query_string
11.1
request_params
4.0
BUILDARGS
3.0
CRAP 16.1
« Client.pm ↑ Summary Client/UA/Hijk.pm »
1 # ABSTRACT: request class
2 package PONAPI::Client::Request;
3  
4 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use JSON::MaybeXS qw< encode_json >;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use PONAPI::Utils::URI qw< to_uri >;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 requires 'method';
11 7 requires 'path';
12  
13 has 'uri_base' => (
14 is => 'ro',
15 isa => 'Maybe[Str]',
16 18 ▶ default => sub { '' },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 7 );
18  
19 sub BUILDARGS {
20 19 ▶ my ( $class, %args ) = @_;
Subroutine BUILDARGS: called CC=3 SCAR=11.0
Pod undocumented
21 $args{uri_base} =~ s|/$||
22 19 ▶ if exists $args{uri_base} and defined $args{uri_base};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"uri_base"} and defined $args{"uri_base"} 1 18 19
Condition66%2/3
exists $args{"uri_base"} and defined $args{"uri_base"}
!ll&&!rl&&r
1801
MC/DC50%1/2
exists $args{"uri_base"} and defined $args{"uri_base"}
exists $args{"uri_base"} defined $args{"uri_base"}
Truth table66%2/3
A and B
A= exists $args{"uri_base"}B= defined $args{"uri_base"}
ABresult
0X0
100
111
23 19 return \%args;
24 }
25  
26 sub request_params {
27 12 ▶ my $self = shift;
Subroutine request_params: called CC=4 SCAR=13.9
Pod undocumented
28  
29 12 my $method = $self->method;
30  
31 12 my $template = $self->uri_template;
32 12 my $path_args = $self->path;
33 12 (my $path = $template) =~ s/
34 \{
35 ( [^}]+ )
36 \}
37 /
38 24 my $placeholder = $1;
39 24 ▶ if ( !exists $path_args->{$placeholder} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $path_args->{$placeholder}) 0 24 24
40 0 die "uri_template($template) has placeholder $placeholder, but that is not one of the request params for this class";
41 }
42 24 $path_args->{$placeholder}
43 /xeg;
44  
45 return (
46 12 ▶ method => $method,
Branch: 2 branches
BranchTrueFalseTotal
$method eq 'GET' ? : 9 3 12
$self->can('data') ? : 2 1 3
47 path => $self->uri_base . $path,
48 ( $method eq 'GET'
49 ? ( query_string => $self->_build_query_string )
50 : ( $self->can('data')
51 ? ( body => encode_json( { data => $self->data } ) )
52 : ()
53 )
54 )
55 );
56 }
57  
58 sub _build_query_string {
59 9 ▶ my $self = shift;
Subroutine _build_query_string: called CC=11 SCAR=24.1
60  
61 9 my %u;
62  
63 9 ▶ $u{filter} = $self->filter
Branch: 1 branch
BranchTrueFalseTotal
if $self->does("PONAPI::Client::Request::Role::HasFilter") and $self->has_filter 3 6 9
Condition66%2/3
$self->does("PONAPI::Client::Request::Role::HasFilter") and $self->has_filter
!ll&&!rl&&r
063
MC/DC50%1/2
$self->does("PONAPI::Client::Request::Role::HasFilter") and $self->has_filter
$self->does("PONAPI::Client::Request::Role::HasFilter") $self->has_filter
Truth table66%2/3
A and B
A= $self->does("PONAPI::Client::Request::Role::HasFilter")B= $self->has_filter
ABresult
0X0
100
111
64 if $self->does('PONAPI::Client::Request::Role::HasFilter') and $self->has_filter;
65  
66 9 ▶ $u{fields} = $self->fields
Branch: 1 branch
BranchTrueFalseTotal
if $self->does("PONAPI::Client::Request::Role::HasFields") and $self->has_fields 7 2 9
Condition100%3/3
$self->does("PONAPI::Client::Request::Role::HasFields") and $self->has_fields
!ll&&!rl&&r
117
MC/DC100%2/2
$self->does("PONAPI::Client::Request::Role::HasFields") and $self->has_fields
$self->does("PONAPI::Client::Request::Role::HasFields") $self->has_fields
Truth table100%3/3
A and B
A= $self->does("PONAPI::Client::Request::Role::HasFields")B= $self->has_fields
ABresult
0X0
100
111
67 if $self->does('PONAPI::Client::Request::Role::HasFields') and $self->has_fields;
68  
69 9 ▶ $u{page} = $self->page
Branch: 1 branch
BranchTrueFalseTotal
if $self->does("PONAPI::Client::Request::Role::HasPage") and $self->has_page 2 7 9
Condition66%2/3
$self->does("PONAPI::Client::Request::Role::HasPage") and $self->has_page
!ll&&!rl&&r
072
MC/DC50%1/2
$self->does("PONAPI::Client::Request::Role::HasPage") and $self->has_page
$self->does("PONAPI::Client::Request::Role::HasPage") $self->has_page
Truth table66%2/3
A and B
A= $self->does("PONAPI::Client::Request::Role::HasPage")B= $self->has_page
ABresult
0X0
100
111
70 if $self->does('PONAPI::Client::Request::Role::HasPage') and $self->has_page;
71  
72 9 ▶ $u{include} = $self->include
Branch: 1 branch
BranchTrueFalseTotal
if $self->does("PONAPI::Client::Request::Role::HasInclude") and $self->has_include 7 2 9
Condition100%3/3
$self->does("PONAPI::Client::Request::Role::HasInclude") and $self->has_include
!ll&&!rl&&r
117
MC/DC100%2/2
$self->does("PONAPI::Client::Request::Role::HasInclude") and $self->has_include
$self->does("PONAPI::Client::Request::Role::HasInclude") $self->has_include
Truth table100%3/3
A and B
A= $self->does("PONAPI::Client::Request::Role::HasInclude")B= $self->has_include
ABresult
0X0
100
111
73 if $self->does('PONAPI::Client::Request::Role::HasInclude') and $self->has_include;
74  
75 9 ▶ $u{sort} = $self->sort
Branch: 1 branch
BranchTrueFalseTotal
if $self->does("PONAPI::Client::Request::Role::HasSort") and $self->has_sort 1 8 9
Condition66%2/3
$self->does("PONAPI::Client::Request::Role::HasSort") and $self->has_sort
!ll&&!rl&&r
801
MC/DC50%1/2
$self->does("PONAPI::Client::Request::Role::HasSort") and $self->has_sort
$self->does("PONAPI::Client::Request::Role::HasSort") $self->has_sort
Truth table66%2/3
A and B
A= $self->does("PONAPI::Client::Request::Role::HasSort")B= $self->has_sort
ABresult
0X0
100
111
76 if $self->does('PONAPI::Client::Request::Role::HasSort') and $self->has_sort;
77  
78 9 return to_uri( \%u );
79 }
80  
81 7 ▶no Moose::Role; 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 __END__
84  
85 =pod
86  
87 =encoding UTF-8
88  
89 =head1 NAME
90  
91 PONAPI::Client::Request - request class
92  
93 =head1 VERSION
94  
95 version 0.002011
96  
97 =head1 AUTHORS
98  
99 =over 4
100  
101 =item *
102  
103 Mickey Nasriachi <mickey@cpan.org>
104  
105 =item *
106  
107 Stevan Little <stevan@cpan.org>
108  
109 =item *
110  
111 Brian Fraser <hugmeir@cpan.org>
112  
113 =back
114  
115 =head1 COPYRIGHT AND LICENSE
116  
117 This software is copyright (c) 2019 by Mickey Nasriachi, Stevan Little, Brian Fraser.
118  
119 This is free software; you can redistribute it and/or modify it under
120 the same terms as the Perl 5 programming language system itself.
121  
122 =cut
« Client.pm ↑ Summary Client/UA/Hijk.pm »