| 1 | # | ||||||||||
| 2 | # This file is part of DNS-NIOS | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is Copyright (c) 2021 by Christian Segundo. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software, licensed under: | ||||||||||
| 7 | # | ||||||||||
| 8 | # The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 9 | # | ||||||||||
| 10 | ## no critic | ||||||||||
| 11 | package DNS::NIOS::Response; | ||||||||||
| 12 | 6 | $DNS::NIOS::Response::VERSION = '0.004'; | |||||||||
| 13 | |||||||||||
| 14 | # ABSTRACT: WAPI Response object | ||||||||||
| 15 | # VERSION | ||||||||||
| 16 | # AUTHORITY | ||||||||||
| 17 | |||||||||||
| 18 | ## use critic | ||||||||||
| 19 | 6 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 6 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 6 | ▶ | use JSON qw(from_json to_json); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 6 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 6 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 6 | ▶ | use Class::Tiny qw( _http_response ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | sub BUILD { | ||||||||||
| 27 | 1211 | ▶ | my $self = shift; | ||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||
| 28 | 1211 | ▶ | croak "Missing required attribute" unless defined $self->_http_response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1211 | ▶ | croak "Bad attribute" unless ref $self->_http_response eq "HTTP::Response"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | sub code { | ||||||||||
| 33 | 7 | ▶ | return shift->_http_response->{_rc}; | ||||||||
|
Subroutine
code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub is_success { | ||||||||||
| 37 | 5 | ▶ | return shift->_http_response->is_success; | ||||||||
|
Subroutine
is_success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub content { | ||||||||||
| 41 | 2407 | ▶ | my $self = shift; | ||||||||
|
Subroutine
content: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||
| 42 | 2407 | my $h; | |||||||||
| 43 | try { | ||||||||||
| 44 | 2407 | ▶ | $h = from_json( $self->_http_response->decoded_content ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 45 | |||||||||||
| 46 | } | ||||||||||
| 47 | catch { | ||||||||||
| 48 | 0 | ▶ | $h = $self->_http_response->decoded_content; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | |||||||||||
| 50 | # For some reason <5.28 returns a quoted string during test | ||||||||||
| 51 | 0 | $h =~ s/^"|"$//g; | |||||||||
| 52 | 2407 | }; | |||||||||
| 53 | 2407 | return $h; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub json { | ||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 58 | try { | ||||||||||
| 59 | 0 | ▶ | my $h = to_json( $self->content, @_ ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 60 | 0 | return $h; | |||||||||
| 61 | 0 | }; | |||||||||
| 62 | 0 | return to_json( { content => $self->content }, @_ ); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub pretty { | ||||||||||
| 66 | 0 | ▶ | return shift->json( { utf8 => 1, pretty => 1 } ); | ||||||||
|
Subroutine
pretty: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 6 | 1; | |||||||||
| 70 | |||||||||||
| 71 | __END__ | ||||||||||