blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Test.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 95 CC 3 SCAR 13.0
CC
3
Cov
0%
is_success
12.0
GET
2.0
POST
2.0
CRAP 3.7
1 package Dwarf::Test;
2 use Dwarf::Pragma;
3 use parent 'Exporter';
4 use HTTP::Request::Common ();
5 use Plack::Test;
6 use Test::More;
7 use UNIVERSAL::require;
8  
9 our @EXPORT = qw/GET POST is_success get_ok post_ok post_redirect get_not_ok post_not_ok/;
10  
11 sub GET { HTTP::Request::Common::GET(@_) }
12 sub POST { HTTP::Request::Common::POST(@_) }
13  
14 sub is_success {
15 my ($res, $path) = @_;
16 my $desc = $res->status_line;
17 $desc .= ', redirected to ' . ($res->header("Location") || "") if ($res->is_redirect);
18 if (!$res->is_redirect) {
19 ok $res->is_success, "$path: $desc";
20 } else {
21 ok $res->is_redirect, "$path: $desc";
22 }
23 }
24  
25 sub is_failure {
26 my ($res, $path) = @_;
27 my $desc = $res->status_line;
28 ok !$res->is_success, "$path: $desc";
29 }
30  
31 sub get_ok {
32 my ($cb, $path) = @_;
33 my $res = $cb->(GET $path);
34 is_success($res, $path);
35 $res;
36 }
37  
38 sub post_ok {
39 my ($cb, $path, @args) = @_;
40 my $res = $cb->(POST $path, @args);
41 is_success($res, $path);
42 $res;
43 }
44  
45 sub get_redirect {
46 my ($cb, $path) = @_;
47 my $res = $cb->(GET $path);
48 ok !$res->is_success, "$path: " . $res->status_line;
49 ok $res->is_redirect, "$path: redirected to " . ($res->header("Location") || '');
50 $res;
51 }
52  
53 sub post_redirect {
54 my ($cb, $path, $param) = @_;
55 my $res = $cb->(POST $path, $param);
56 ok !$res->is_success, "$path: " . $res->status_line;
57 ok $res->is_redirect, "$path: redirected to " . ($res->header("Location") || '');
58 $res;
59 }
60  
61 sub get_not_ok {
62 my ($cb, $path) = @_;
63 my $res = $cb->(GET $path);
64 is_failure($res, $path);
65 $res;
66 }
67  
68 sub post_not_ok {
69 my ($cb, $path, @args) = @_;
70 my $res = $cb->(POST $path, @args);
71 is_failure($res, $path);
72 $res;
73 }
74  
75  
76 1;