| 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
Condition66%2/3
exists $args{"uri_base"} and defined $args{"uri_base"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->does("PONAPI::Client::Request::Role::HasFilter") and $self->has_filter
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
| |||||||||||||||||||||||||||||
| 64 | if $self->does('PONAPI::Client::Request::Role::HasFilter') and $self->has_filter; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 9 | ▶ | $u{fields} = $self->fields | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->does("PONAPI::Client::Request::Role::HasFields") and $self->has_fields
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
| |||||||||||||||||||||||||||||
| 67 | if $self->does('PONAPI::Client::Request::Role::HasFields') and $self->has_fields; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 9 | ▶ | $u{page} = $self->page | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->does("PONAPI::Client::Request::Role::HasPage") and $self->has_page
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
| |||||||||||||||||||||||||||||
| 70 | if $self->does('PONAPI::Client::Request::Role::HasPage') and $self->has_page; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 9 | ▶ | $u{include} = $self->include | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->does("PONAPI::Client::Request::Role::HasInclude") and $self->has_include
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
| |||||||||||||||||||||||||||||
| 73 | if $self->does('PONAPI::Client::Request::Role::HasInclude') and $self->has_include; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 9 | ▶ | $u{sort} = $self->sort | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->does("PONAPI::Client::Request::Role::HasSort") and $self->has_sort
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
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||