@@ -5,33 +5,34 @@ use strict;
55use warnings;
66
77use Test::More;
8- use Test::Fatal qw( dies_ok lives_ok ) ;
98plan tests => 15;
109
1110use HTTP::Request;
11+ use Try::Tiny qw( catch try ) ;
1212
13- my $req = HTTP::Request-> new(GET => " http://www.example.com" );
13+ my $req = HTTP::Request-> new( GET => " http://www.example.com" );
1414$req -> accept_decodable;
1515
16- is($req -> method, " GET" );
17- is($req -> uri, " http://www.example.com" );
18- like($req -> header(" Accept-Encoding" ), qr /\b gzip\b / ); # assuming IO::Uncompress::Gunzip is there
16+ is( $req -> method, " GET" );
17+ is( $req -> uri, " http://www.example.com" );
18+ like( $req -> header(" Accept-Encoding" ), qr /\b gzip\b / )
19+ ; # assuming IO::Uncompress::Gunzip is there
1920
20- $req -> dump (prefix => " # " );
21+ $req -> dump ( prefix => " # " );
2122
22- is($req -> method(" DELETE" ), " GET" );
23- is($req -> method, " DELETE" );
23+ is( $req -> method(" DELETE" ), " GET" );
24+ is( $req -> method, " DELETE" );
2425
25- is($req -> uri(" http:" ), " http://www.example.com" );
26- is($req -> uri, " http:" );
26+ is( $req -> uri(" http:" ), " http://www.example.com" );
27+ is( $req -> uri, " http:" );
2728
2829$req -> protocol(" HTTP/1.1" );
2930
30- my $r2 = HTTP::Request-> parse($req -> as_string);
31- is($r2 -> method, " DELETE" );
32- is($r2 -> uri, " http:" );
33- is($r2 -> protocol, " HTTP/1.1" );
34- is($r2 -> header(" Accept-Encoding" ), $req -> header(" Accept-Encoding" ));
31+ my $r2 = HTTP::Request-> parse( $req -> as_string );
32+ is( $r2 -> method, " DELETE" );
33+ is( $r2 -> uri, " http:" );
34+ is( $r2 -> protocol, " HTTP/1.1" );
35+ is( $r2 -> header(" Accept-Encoding" ), $req -> header(" Accept-Encoding" ) );
3536
3637# Test objects which are accepted as URI-like
3738{
@@ -57,16 +58,31 @@ is($r2->header("Accept-Encoding"), $req->header("Accept-Encoding"));
5758
5859 package main ;
5960
60- ok( Foo::URI-> new-> can( ' scheme' ), ' Object can scheme()' );
61- dies_ok(
62- sub { HTTP::Request-> new( GET => Foo::URI-> new ) },
61+ ok( Foo::URI-> new-> can(' scheme' ), ' Object can scheme()' );
62+ ok(
63+ !do {
64+ try {
65+ HTTP::Request-> new( GET => Foo::URI-> new );
66+ return 1;
67+ }
68+ catch { return 0 };
69+ },
6370 ' Object without canonical method triggers an exception'
6471 );
6572
66- ok( Foo::URI::WithCanonical-> new-> can( ' canonical' ),
67- ' Object can canonical()' );
68- lives_ok(
69- sub { HTTP::Request-> new( GET => Foo::URI::WithCanonical-> new ) },
73+ ok(
74+ Foo::URI::WithCanonical-> new-> can(' canonical' ),
75+ ' Object can canonical()'
76+ );
77+
78+ ok(
79+ do {
80+ try {
81+ HTTP::Request-> new( GET => Foo::URI::WithCanonical-> new );
82+ return 1;
83+ }
84+ catch { return 0 };
85+ },
7086 ' Object with canonical method does not trigger an exception'
7187 );
7288}
0 commit comments