line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Deep::URI; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
210196
|
use strict; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
100
|
|
4
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
79
|
|
5
|
4
|
|
|
4
|
|
96
|
use 5.008_005; |
|
4
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Easier testing of URIs for Test::Deep |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
18
|
use base qw(Exporter::Tiny); |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
1624
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(uri uri_qf); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
13315
|
use URI; |
|
4
|
|
|
|
|
16097
|
|
|
4
|
|
|
|
|
116
|
|
14
|
4
|
|
|
4
|
|
614
|
use Test::Deep (); |
|
4
|
|
|
|
|
7424
|
|
|
4
|
|
|
|
|
65
|
|
15
|
4
|
|
|
4
|
|
1489
|
use Test::Deep::Cmp; # exports "new", other stuff. |
|
4
|
|
|
|
|
2300
|
|
|
4
|
|
|
|
|
16
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################################################ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub uri { |
21
|
35
|
|
|
35
|
1
|
145745
|
my ($expected_uri) = @_; |
22
|
35
|
|
|
|
|
129
|
return __PACKAGE__->new($expected_uri); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub uri_qf { |
26
|
5
|
|
|
5
|
1
|
21506
|
my ($expected_uri, $expected_query_form) = @_; |
27
|
5
|
|
|
|
|
24
|
my $self = __PACKAGE__->new($expected_uri, $expected_query_form); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub init |
31
|
|
|
|
|
|
|
{ |
32
|
40
|
|
|
40
|
0
|
238
|
my ($self, $expected_uri, $expected_query_form) = @_; |
33
|
|
|
|
|
|
|
|
34
|
40
|
|
|
|
|
58
|
my $is_deep_qf = scalar(@_) == 3; |
35
|
|
|
|
|
|
|
|
36
|
40
|
100
|
100
|
|
|
172
|
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
|
|
|
|
23
|
warn "Missing uri for uri_qf()!" |
41
|
|
|
|
|
|
|
unless defined $expected_uri; |
42
|
5
|
100
|
|
|
|
20
|
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
|
|
|
215
|
if (($expected_uri || '') =~ m{//([^/]+)/}) { |
50
|
24
|
|
|
|
|
178
|
$self->{host} = $1; |
51
|
|
|
|
|
|
|
} |
52
|
40
|
|
|
|
|
145
|
$self->{uri} = URI->new($expected_uri); |
53
|
40
|
100
|
|
|
|
23566
|
if ($is_deep_qf) { |
54
|
5
|
|
|
|
|
10
|
$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
|
28273
|
my ($self, $got) = @_; |
62
|
|
|
|
|
|
|
|
63
|
40
|
|
|
|
|
56
|
my $uri = $self->{uri}; |
64
|
40
|
|
|
|
|
86
|
$got = URI->new($got); |
65
|
|
|
|
|
|
|
|
66
|
40
|
|
|
|
|
2925
|
my @methods; |
67
|
40
|
100
|
|
|
|
123
|
push @methods, scheme => $uri->scheme if $uri->scheme(); |
68
|
40
|
|
|
|
|
961
|
local $@; |
69
|
40
|
|
|
|
|
67
|
eval { |
70
|
|
|
|
|
|
|
# Dies on partial URIs |
71
|
40
|
|
|
|
|
268
|
push @methods, host => $uri->host; |
72
|
|
|
|
|
|
|
# Don't need kludge |
73
|
12
|
|
|
|
|
400
|
delete $self->{host}; |
74
|
|
|
|
|
|
|
}; |
75
|
40
|
|
|
|
|
109
|
push @methods, path => $uri->path; |
76
|
40
|
|
|
|
|
473
|
push @methods, fragment => $uri->fragment; |
77
|
|
|
|
|
|
|
|
78
|
40
|
|
|
|
|
345
|
my @expected = ( |
79
|
|
|
|
|
|
|
$self->_get_expected_qf(), |
80
|
|
|
|
|
|
|
Test::Deep::methods(@methods) |
81
|
|
|
|
|
|
|
); |
82
|
40
|
|
|
|
|
3714
|
my @received = ( |
83
|
|
|
|
|
|
|
_to_hashref([ $got->query_form ]), |
84
|
|
|
|
|
|
|
$got, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Kludge to test host! |
88
|
40
|
100
|
|
|
|
118
|
if ($self->{host}) { |
89
|
12
|
|
|
|
|
22
|
push @expected, $self->{host}; |
90
|
12
|
100
|
|
|
|
81
|
push @received, |
91
|
|
|
|
|
|
|
($got->can('host')) |
92
|
|
|
|
|
|
|
? $got->host |
93
|
|
|
|
|
|
|
: $got =~ m{//([^/]+)/}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
40
|
|
|
|
|
330
|
$self->data->{got} = $got; |
97
|
40
|
|
|
|
|
373
|
return Test::Deep::wrap(\@expected)->descend(\@received); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _get_expected_qf { |
101
|
40
|
|
|
40
|
|
66
|
my ($self) = @_; |
102
|
|
|
|
|
|
|
return $self->{expected_qf} |
103
|
40
|
100
|
|
|
|
88
|
if exists $self->{expected_qf}; |
104
|
35
|
|
|
|
|
97
|
return _to_hashref([ $self->{uri}->query_form ]); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _to_hashref |
108
|
|
|
|
|
|
|
{ |
109
|
75
|
|
|
75
|
|
4258
|
my ($list) = @_; |
110
|
75
|
|
|
|
|
85
|
my %hash; |
111
|
75
|
|
|
|
|
206
|
while (my ($key, $val) = splice(@$list, 0, 2)) |
112
|
|
|
|
|
|
|
{ |
113
|
195
|
100
|
|
|
|
312
|
if (exists $hash{$key}) { |
114
|
|
|
|
|
|
|
$hash{$key} = [ $hash{$key} ] |
115
|
73
|
100
|
|
|
|
175
|
unless ref $hash{$key}; |
116
|
73
|
|
|
|
|
83
|
push @{$hash{$key}}, $val; |
|
73
|
|
|
|
|
141
|
|
117
|
73
|
|
|
|
|
174
|
next; |
118
|
|
|
|
|
|
|
} |
119
|
122
|
|
|
|
|
321
|
$hash{$key} = $val; |
120
|
|
|
|
|
|
|
} |
121
|
75
|
|
|
|
|
240
|
return \%hash; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
__END__ |