| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Deep::URI; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
275243
|
use strict; |
|
|
4
|
|
|
|
|
22
|
|
|
|
4
|
|
|
|
|
85
|
|
|
4
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
89
|
|
|
5
|
4
|
|
|
4
|
|
65
|
use 5.008_005; |
|
|
4
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Easier testing of URIs for Test::Deep |
|
9
|
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
18
|
use base qw(Exporter::Tiny); |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
1415
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(uri uri_qf); |
|
12
|
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
11684
|
use URI; |
|
|
4
|
|
|
|
|
23600
|
|
|
|
4
|
|
|
|
|
126
|
|
|
14
|
4
|
|
|
4
|
|
449
|
use Test::Deep (); |
|
|
4
|
|
|
|
|
6306
|
|
|
|
4
|
|
|
|
|
60
|
|
|
15
|
4
|
|
|
4
|
|
1413
|
use Test::Deep::Cmp; # exports "new", other stuff. |
|
|
4
|
|
|
|
|
2144
|
|
|
|
4
|
|
|
|
|
13
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################################################ |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub uri { |
|
21
|
35
|
|
|
35
|
1
|
126889
|
my ($expected_uri) = @_; |
|
22
|
35
|
|
|
|
|
115
|
return __PACKAGE__->new($expected_uri); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub uri_qf { |
|
26
|
5
|
|
|
5
|
1
|
21670
|
my ($expected_uri, $expected_query_form) = @_; |
|
27
|
5
|
|
|
|
|
26
|
my $self = __PACKAGE__->new($expected_uri, $expected_query_form); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub init |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
40
|
|
|
40
|
0
|
208
|
my ($self, $expected_uri, $expected_query_form) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
40
|
|
|
|
|
63
|
my $is_deep_qf = scalar(@_) == 3; |
|
35
|
|
|
|
|
|
|
|
|
36
|
40
|
100
|
100
|
|
|
163
|
if (! $is_deep_qf && ! defined $expected_uri) { |
|
|
|
100
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
11
|
warn "Missing argument to uri()!"; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
elsif ($is_deep_qf) { |
|
40
|
5
|
100
|
|
|
|
19
|
warn "Missing uri for uri_qf()!" |
|
41
|
|
|
|
|
|
|
unless defined $expected_uri; |
|
42
|
5
|
100
|
|
|
|
14
|
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
|
40
|
100
|
100
|
|
|
194
|
if (($expected_uri || '') =~ m{//([^/]+)/}) { |
|
50
|
24
|
|
|
|
|
164
|
$self->{host} = $1; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
40
|
|
|
|
|
110
|
$self->{uri} = URI->new($expected_uri); |
|
53
|
40
|
100
|
|
|
|
28360
|
if ($is_deep_qf) { |
|
54
|
5
|
|
|
|
|
8
|
$self->{is_deep_qf} = $is_deep_qf; |
|
55
|
5
|
|
|
|
|
12
|
$self->{expected_qf} = $expected_query_form; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub descend |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
40
|
|
|
40
|
0
|
31421
|
my ($self, $got) = @_; |
|
62
|
|
|
|
|
|
|
|
|
63
|
40
|
|
|
|
|
53
|
my $uri = $self->{uri}; |
|
64
|
40
|
|
|
|
|
82
|
$got = URI->new($got); |
|
65
|
|
|
|
|
|
|
|
|
66
|
40
|
|
|
|
|
2626
|
my @methods; |
|
67
|
40
|
100
|
|
|
|
116
|
push @methods, scheme => $uri->scheme if $uri->scheme(); |
|
68
|
40
|
|
|
|
|
878
|
local $@; |
|
69
|
40
|
|
|
|
|
56
|
eval { |
|
70
|
|
|
|
|
|
|
# Dies on partial URIs |
|
71
|
40
|
|
|
|
|
229
|
push @methods, host => $uri->host; |
|
72
|
|
|
|
|
|
|
# Don't need kludge |
|
73
|
12
|
|
|
|
|
341
|
delete $self->{host}; |
|
74
|
|
|
|
|
|
|
}; |
|
75
|
40
|
|
|
|
|
104
|
push @methods, path => $uri->path; |
|
76
|
40
|
|
|
|
|
414
|
push @methods, fragment => $uri->fragment; |
|
77
|
|
|
|
|
|
|
|
|
78
|
40
|
|
|
|
|
284
|
my @expected = ( |
|
79
|
|
|
|
|
|
|
$self->_get_expected_qf(), |
|
80
|
|
|
|
|
|
|
Test::Deep::methods(@methods) |
|
81
|
|
|
|
|
|
|
); |
|
82
|
40
|
|
|
|
|
3657
|
my @received = ( |
|
83
|
|
|
|
|
|
|
_to_hashref([ $got->query_form ]), |
|
84
|
|
|
|
|
|
|
$got, |
|
85
|
|
|
|
|
|
|
); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Kludge to test host! |
|
88
|
40
|
100
|
|
|
|
101
|
if ($self->{host}) { |
|
89
|
12
|
|
|
|
|
24
|
push @expected, $self->{host}; |
|
90
|
12
|
100
|
|
|
|
84
|
push @received, |
|
91
|
|
|
|
|
|
|
($got->can('host')) |
|
92
|
|
|
|
|
|
|
? $got->host |
|
93
|
|
|
|
|
|
|
: $got =~ m{//([^/]+)/}; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
40
|
|
|
|
|
302
|
$self->data->{got} = $got; |
|
97
|
40
|
|
|
|
|
334
|
return Test::Deep::wrap(\@expected)->descend(\@received); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _get_expected_qf { |
|
101
|
40
|
|
|
40
|
|
61
|
my ($self) = @_; |
|
102
|
|
|
|
|
|
|
return $self->{expected_qf} |
|
103
|
40
|
100
|
|
|
|
88
|
if exists $self->{expected_qf}; |
|
104
|
35
|
|
|
|
|
81
|
return _to_hashref([ $self->{uri}->query_form ]); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _to_hashref |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
75
|
|
|
75
|
|
5195
|
my ($list) = @_; |
|
110
|
75
|
|
|
|
|
88
|
my %hash; |
|
111
|
75
|
|
|
|
|
189
|
while (my ($key, $val) = splice(@$list, 0, 2)) |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
195
|
100
|
|
|
|
275
|
if (exists $hash{$key}) { |
|
114
|
|
|
|
|
|
|
$hash{$key} = [ $hash{$key} ] |
|
115
|
73
|
100
|
|
|
|
154
|
unless ref $hash{$key}; |
|
116
|
73
|
|
|
|
|
78
|
push @{$hash{$key}}, $val; |
|
|
73
|
|
|
|
|
130
|
|
|
117
|
73
|
|
|
|
|
154
|
next; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
122
|
|
|
|
|
1389
|
$hash{$key} = $val; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
75
|
|
|
|
|
200
|
return \%hash; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
__END__ |