File Coverage

blib/lib/Test2/Tools/HTTP/Tx.pm
Criterion Covered Total %
statement 50 54 92.5
branch 4 6 66.6
condition 2 6 33.3
subroutine 16 17 94.1
pod 8 8 100.0
total 80 91 87.9


line stmt bran cond sub pod time code
1             package Test2::Tools::HTTP::Tx;
2              
3 6     6   262320 use strict;
  6         14  
  6         271  
4 6     6   36 use warnings;
  6         13  
  6         334  
5 6     6   117 use 5.014;
  6         24  
6 6     6   55 use Test2::API ();
  6         42  
  6         207  
7 6     6   51 use Carp ();
  6         17  
  6         4494  
8              
9             # ABSTRACT: Object representing the last transaction for Test2::Tools::HTTP
10             our $VERSION = '0.12'; # VERSION
11              
12              
13 25     25 1 882 sub req { shift->{req} }
14 31     31 1 265 sub res { shift->{res} }
15 8     8 1 55 sub ok { shift->{ok} }
16 2     2 1 14 sub connection_error { shift->{connection_error} }
17 3     3 1 14 sub location { shift->{location} }
18              
19             sub _note_or_diag
20             {
21 4     4   12 my($self, $method) = @_;
22 4         14 my $ctx = Test2::API::context();
23              
24 4         321 $ctx->$method($self->req->method . ' ' . $self->req->uri);
25 4         1261 $ctx->$method($self->req->headers->as_string);
26 4   33     1315 $ctx->$method($self->req->decoded_content || $self->req->content);
27 4 50       1075 if($self->res)
28             {
29 4         15 $ctx->$method($self->res->code . ' ' . $self->res->message);
30 4         1132 $ctx->$method($self->res->headers->as_string);
31 4   33     1414 $ctx->$method($self->res->decoded_content || $self->res->content);
32             }
33 4         2794 $ctx->$method("ok = " . $self->ok);
34              
35 4         1067 $ctx->release;
36             }
37              
38              
39             sub note
40             {
41 4     4 1 13 my($self) = shift;
42 4         18 my $ctx = Test2::API::context();
43 4         532 $self->_note_or_diag('note');
44 4         87 $ctx->release;
45             }
46              
47              
48             sub diag
49             {
50 0     0 1 0 my($self) = shift;
51 0         0 my $ctx = Test2::API::context();
52 0         0 $self->_note_or_diag('diag');
53 0         0 $ctx->release;
54             }
55              
56              
57             sub add_helper
58             {
59 6     6 1 2749 my(undef, $sig, $code) = @_;
60              
61 6         24 my($class, $name) = split /\./, $sig;
62              
63 6         29 my %class = (
64             tx => 'Test2::Tools::HTTP::Tx',
65             req => 'Test2::Tools::HTTP::Tx::Request',
66             res => 'Test2::Tools::HTTP::Tx::Response',
67             );
68              
69 6 50       26 $class = $class{lc $class} if $class{lc $class};
70              
71 6 100       230 Carp::croak("$class already can $name") if $class->can($name);
72              
73 6     6   54 no strict 'refs';
  6         19  
  6         818  
74 3         53 *{"${class}::${name}"} = $code;
  3         24  
75             }
76              
77             package Test2::Tools::HTTP::Tx::Request;
78              
79 6     6   631 use parent 'HTTP::Request';
  6         394  
  6         41  
80              
81             package Test2::Tools::HTTP::Tx::Response;
82              
83 6     6   35832 use parent 'HTTP::Response';
  6         13  
  6         36  
84              
85             1;
86              
87             __END__