line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Deep::URI; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
205632
|
use strict; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
89
|
|
4
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
73
|
|
5
|
4
|
|
|
4
|
|
96
|
use 5.008_005; |
|
4
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Easier testing of URIs for Test::Deep |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
17
|
use base qw(Exporter::Tiny); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1576
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(uri uri_qf); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
12459
|
use URI; |
|
4
|
|
|
|
|
14718
|
|
|
4
|
|
|
|
|
104
|
|
14
|
4
|
|
|
4
|
|
549
|
use Test::Deep (); |
|
4
|
|
|
|
|
6766
|
|
|
4
|
|
|
|
|
68
|
|
15
|
4
|
|
|
4
|
|
1427
|
use Test::Deep::Cmp; # exports "new", other stuff. |
|
4
|
|
|
|
|
2108
|
|
|
4
|
|
|
|
|
12
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################################################ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub uri { |
21
|
35
|
|
|
35
|
1
|
142329
|
my ($expected_uri) = @_; |
22
|
35
|
|
|
|
|
130
|
return __PACKAGE__->new($expected_uri); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub uri_qf { |
26
|
4
|
|
|
4
|
1
|
14974
|
my ($expected_uri, $expected_query_form) = @_; |
27
|
4
|
|
|
|
|
18
|
my $self = __PACKAGE__->new($expected_uri, $expected_query_form); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub init |
31
|
|
|
|
|
|
|
{ |
32
|
39
|
|
|
39
|
0
|
229
|
my ($self, $expected_uri, $expected_query_form) = @_; |
33
|
|
|
|
|
|
|
|
34
|
39
|
|
|
|
|
85
|
my $is_deep_qf = scalar(@_) == 3; |
35
|
|
|
|
|
|
|
|
36
|
39
|
100
|
100
|
|
|
183
|
if (! $is_deep_qf && ! defined $expected_uri) { |
|
|
100
|
|
|
|
|
|
37
|
1
|
|
|
|
|
12
|
warn "Missing argument to uri()!"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($is_deep_qf) { |
40
|
4
|
50
|
|
|
|
6
|
warn "Missing uri for uri_qf()!" |
41
|
|
|
|
|
|
|
unless defined $expected_uri; |
42
|
4
|
50
|
|
|
|
8
|
warn "Missing query form for uri_qf()!" |
43
|
|
|
|
|
|
|
unless defined $expected_query_form; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# URI objects act a little weird on URIs like "//host/path". |
47
|
|
|
|
|
|
|
# "/path" can be pulled via path(), but host() dies. Thus I'm |
48
|
|
|
|
|
|
|
# copying the host string if necessary. |
49
|
39
|
100
|
100
|
|
|
198
|
if (($expected_uri || '') =~ m{//([^/]+)/}) { |
50
|
24
|
|
|
|
|
175
|
$self->{host} = $1; |
51
|
|
|
|
|
|
|
} |
52
|
39
|
|
|
|
|
118
|
$self->{uri} = URI->new($expected_uri); |
53
|
39
|
100
|
|
|
|
22440
|
if ($is_deep_qf) { |
54
|
4
|
|
|
|
|
7
|
$self->{is_deep_qf} = $is_deep_qf; |
55
|
4
|
|
|
|
|
8
|
$self->{expected_qf} = $expected_query_form; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub descend |
60
|
|
|
|
|
|
|
{ |
61
|
39
|
|
|
39
|
0
|
27530
|
my ($self, $got) = @_; |
62
|
|
|
|
|
|
|
|
63
|
39
|
|
|
|
|
77
|
my $uri = $self->{uri}; |
64
|
39
|
|
|
|
|
84
|
$got = URI->new($got); |
65
|
|
|
|
|
|
|
|
66
|
39
|
|
|
|
|
2801
|
my @methods; |
67
|
39
|
100
|
|
|
|
123
|
push @methods, scheme => $uri->scheme if $uri->scheme(); |
68
|
39
|
|
|
|
|
958
|
local $@; |
69
|
39
|
|
|
|
|
55
|
eval { |
70
|
|
|
|
|
|
|
# Dies on partial URIs |
71
|
39
|
|
|
|
|
270
|
push @methods, host => $uri->host; |
72
|
|
|
|
|
|
|
# Don't need kludge |
73
|
12
|
|
|
|
|
401
|
delete $self->{host}; |
74
|
|
|
|
|
|
|
}; |
75
|
39
|
|
|
|
|
130
|
push @methods, path => $uri->path; |
76
|
39
|
|
|
|
|
474
|
push @methods, fragment => $uri->fragment; |
77
|
|
|
|
|
|
|
|
78
|
39
|
|
|
|
|
307
|
my @expected = ( |
79
|
|
|
|
|
|
|
$self->_get_expected_qf(), |
80
|
|
|
|
|
|
|
Test::Deep::methods(@methods) |
81
|
|
|
|
|
|
|
); |
82
|
39
|
|
|
|
|
3546
|
my @received = ( |
83
|
|
|
|
|
|
|
_to_hashref([ $got->query_form ]), |
84
|
|
|
|
|
|
|
$got, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Kludge to test host! |
88
|
39
|
100
|
|
|
|
107
|
if ($self->{host}) { |
89
|
12
|
|
|
|
|
23
|
push @expected, $self->{host}; |
90
|
12
|
100
|
|
|
|
77
|
push @received, |
91
|
|
|
|
|
|
|
($got->can('host')) |
92
|
|
|
|
|
|
|
? $got->host |
93
|
|
|
|
|
|
|
: $got =~ m{//([^/]+)/}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
39
|
|
|
|
|
349
|
$self->data->{got} = $got; |
97
|
39
|
|
|
|
|
376
|
return Test::Deep::wrap(\@expected)->descend(\@received); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _get_expected_qf { |
101
|
39
|
|
|
39
|
|
68
|
my ($self) = @_; |
102
|
|
|
|
|
|
|
return $self->{expected_qf} |
103
|
39
|
100
|
|
|
|
87
|
if exists $self->{expected_qf}; |
104
|
35
|
|
|
|
|
111
|
return _to_hashref([ $self->{uri}->query_form ]); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _to_hashref |
108
|
|
|
|
|
|
|
{ |
109
|
74
|
|
|
74
|
|
4154
|
my ($list) = @_; |
110
|
74
|
|
|
|
|
96
|
my %hash; |
111
|
74
|
|
|
|
|
259
|
while (my ($key, $val) = splice(@$list, 0, 2)) |
112
|
|
|
|
|
|
|
{ |
113
|
192
|
100
|
|
|
|
335
|
if (exists $hash{$key}) { |
114
|
|
|
|
|
|
|
$hash{$key} = [ $hash{$key} ] |
115
|
72
|
100
|
|
|
|
179
|
unless ref $hash{$key}; |
116
|
72
|
|
|
|
|
93
|
push @{$hash{$key}}, $val; |
|
72
|
|
|
|
|
131
|
|
117
|
72
|
|
|
|
|
187
|
next; |
118
|
|
|
|
|
|
|
} |
119
|
120
|
|
|
|
|
317
|
$hash{$key} = $val; |
120
|
|
|
|
|
|
|
} |
121
|
74
|
|
|
|
|
224
|
return \%hash; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
__END__ |