| 1 | # vim: set ts=2 sts=2 sw=2 expandtab smarttab: | ||||||||||||
| 2 | # | ||||||||||||
| 3 | # This file is part of AnyEvent-HTTP-Message | ||||||||||||
| 4 | # | ||||||||||||
| 5 | # This software is copyright (c) 2012 by Randy Stauner. | ||||||||||||
| 6 | # | ||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 9 | # | ||||||||||||
| 10 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | package AnyEvent::HTTP::Response; | ||||||||||||
| 14 | { | ||||||||||||
| 15 | 3 | $AnyEvent::HTTP::Response::VERSION = '0.302'; | |||||||||||
| 16 | } | ||||||||||||
| 17 | 3 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 3 | $AnyEvent::HTTP::Response::AUTHORITY = 'cpan:RWSTAUNER'; | |||||||||||
| 19 | } | ||||||||||||
| 20 | # ABSTRACT: HTTP Response object for AnyEvent::HTTP | ||||||||||||
| 21 | |||||||||||||
| 22 | 3 | ▶ | use parent 'AnyEvent::HTTP::Message'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | 5 | ▶ | sub args { | ||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 26 | 5 | my ($self) = @_; | |||||||||||
| 27 | return ( | ||||||||||||
| 28 | $self->body, | ||||||||||||
| 29 | { | ||||||||||||
| 30 | 5 | %{ $self->headers }, | |||||||||||
| 31 | 5 | %{ $self->pseudo_headers }, | |||||||||||
| 32 | }, | ||||||||||||
| 33 | ); | ||||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | 5 | ▶ | sub parse_args { | ||||||||||
|
Subroutine
parse_args: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 38 | 5 | my $self = shift; | |||||||||||
| 39 | 5 | ▶ | $self->_error( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | q[expects two arguments: ($content_body, \%headers)] | ||||||||||||
| 41 | ) | ||||||||||||
| 42 | unless @_ == 2; | ||||||||||||
| 43 | |||||||||||||
| 44 | 2 | my $args = { | |||||||||||
| 45 | body => $_[0], | ||||||||||||
| 46 | }; | ||||||||||||
| 47 | |||||||||||||
| 48 | 2 | my %headers = %{ $_[1] }; | |||||||||||
| 49 | 2 | my %pseudo; | |||||||||||
| 50 | { | ||||||||||||
| 51 | 2 | my @pseudo = grep { /^[A-Z]/ } keys %headers; | |||||||||||
| 52 | # remove the ae-http pseudo-headers (init-capped) | ||||||||||||
| 53 | 2 | @pseudo{ @pseudo } = delete @headers{ @pseudo }; | |||||||||||
| 54 | } | ||||||||||||
| 55 | 2 | @$args{qw(headers pseudo_headers)} = (\%headers, \%pseudo); | |||||||||||
| 56 | |||||||||||||
| 57 | 2 | return $args; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 3 | ▶ | sub from_http_message { | ||||||||||
|
Subroutine
from_http_message: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 62 | 3 | my ($self, $res) = @_; | |||||||||||
| 63 | my $args = { | ||||||||||||
| 64 | 3 | ▶ | body => $res->${\ ($res->can('decoded_content') || 'content') }, | ||||||||||
|
Condition50%1/2
$res->can('decoded_content') || 'content'
MC/DC0%0/1
$res->can('decoded_content') || 'content'
$res->can('decoded_content')
Truth table50%1/2
A
A= $res->can('decoded_content')
| |||||||||||||
| 65 | pseudo_headers => { | ||||||||||||
| 66 | Status => $res->code, | ||||||||||||
| 67 | Reason => $res->message, | ||||||||||||
| 68 | }, | ||||||||||||
| 69 | headers => $self->_hash_http_headers($res->headers), | ||||||||||||
| 70 | }; | ||||||||||||
| 71 | 3 | ▶ | if( my $proto = $res->protocol ){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | # regexp taken straight from AnyEvent::HTTP 2.13 | ||||||||||||
| 73 | 1 | $args->{pseudo_headers}{HTTPVersion} = ($proto =~ /^HTTP\/0*([0-9\.]+)/)[0]; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 3 | return $args; | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | |||||||||||||
| 80 | 13 | ▶ | sub pseudo_headers { $_[0]->{pseudo_headers} ||= {} } | ||||||||||
|
Subroutine
pseudo_headers: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[0]{"pseudo_headers"} ||= {}
MC/DC100%1/1
$_[0]{"pseudo_headers"} ||= {}
$_[0]{"pseudo_headers"}
Truth table100%2/2
A
A= $_[0]{"pseudo_headers"}
| |||||||||||||
| 81 | |||||||||||||
| 82 | |||||||||||||
| 83 | 2 | ▶ | sub to_http_message { | ||||||||||
|
Subroutine
to_http_message: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 84 | 2 | my ($self) = @_; | |||||||||||
| 85 | 2 | require HTTP::Response; | |||||||||||
| 86 | |||||||||||||
| 87 | my $res = HTTP::Response->new( | ||||||||||||
| 88 | 2 | @{ $self->pseudo_headers }{qw(Status Reason)}, | |||||||||||
| 89 | 2 | [ %{ $self->headers } ], | |||||||||||
| 90 | $self->body | ||||||||||||
| 91 | ); | ||||||||||||
| 92 | 2 | ▶ | if( my $v = $self->pseudo_headers->{HTTPVersion} ){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 93 | 2 | $res->protocol("HTTP/$v") | |||||||||||
| 94 | } | ||||||||||||
| 95 | 2 | return $res; | |||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 3 | 1; | |||||||||||
| 99 | |||||||||||||
| 100 | __END__ | ||||||||||||