line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::URL; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
219871
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
44
|
|
5
|
2
|
|
|
2
|
|
35
|
use 5.008001; |
|
2
|
|
|
|
|
6
|
|
6
|
2
|
|
|
2
|
|
11
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
27
|
|
7
|
2
|
|
|
2
|
|
9
|
use Test2::Compare (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
8
|
2
|
|
|
2
|
|
13
|
use Test2::Compare::Hash (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
26
|
|
9
|
2
|
|
|
2
|
|
10
|
use Test2::Compare::String (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
52
|
|
10
|
2
|
|
|
2
|
|
11
|
use base qw( Exporter ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
739
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( url url_base url_component ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# ABSTRACT: Compare a URL in your Test2 test |
15
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub url (&) |
19
|
|
|
|
|
|
|
{ |
20
|
27
|
|
|
27
|
1
|
168576
|
Test2::Compare::build('Test2::Tools::URL::Check', @_); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub url_base ($) |
25
|
|
|
|
|
|
|
{ |
26
|
3
|
|
|
3
|
1
|
2016
|
my($base) = @_; |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
10
|
my $build = Test2::Compare::get_build(); |
29
|
3
|
100
|
|
|
|
16
|
if($build) |
30
|
1
|
|
|
|
|
5
|
{ $build->set_base($base) } |
31
|
|
|
|
|
|
|
else |
32
|
2
|
|
|
|
|
6
|
{ Test2::Tools::URL::Check->set_global_base($base) } |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub url_component ($$) |
37
|
|
|
|
|
|
|
{ |
38
|
29
|
|
|
29
|
1
|
877
|
my($name, $expect) = @_; |
39
|
|
|
|
|
|
|
|
40
|
29
|
50
|
|
|
|
144
|
Carp::croak("$name is not a valid URL component") |
41
|
|
|
|
|
|
|
unless $name =~ /^(?:scheme|authority|userinfo|hostport|host|port|path|query|fragment)$/; |
42
|
|
|
|
|
|
|
|
43
|
29
|
50
|
|
|
|
67
|
my $build = Test2::Compare::get_build()or Carp::croak("No current build!"); |
44
|
29
|
|
|
|
|
161
|
$build->add_component($name, $expect); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
package Test2::Tools::URL::Check; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
2
|
|
16
|
use overload (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
80
|
|
50
|
2
|
|
|
2
|
|
1034
|
use URI 1.61; |
|
2
|
|
|
|
|
8931
|
|
|
2
|
|
|
|
|
58
|
|
51
|
2
|
|
|
2
|
|
853
|
use URI::QueryParam; |
|
2
|
|
|
|
|
1540
|
|
|
2
|
|
|
|
|
66
|
|
52
|
2
|
|
|
2
|
|
15
|
use Scalar::Util qw( blessed ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
123
|
|
53
|
2
|
|
|
2
|
|
11
|
use base qw( Test2::Compare::Base ); |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1293
|
|
54
|
|
|
|
|
|
|
|
55
|
18
|
|
|
18
|
|
7064
|
sub name { '' } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $global_base; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _uri |
60
|
|
|
|
|
|
|
{ |
61
|
40
|
|
|
40
|
|
89
|
my($self, $url) = @_; |
62
|
|
|
|
|
|
|
$self->{base} |
63
|
|
|
|
|
|
|
? URI->new_abs("$url", $self->{base}) |
64
|
40
|
100
|
|
|
|
249
|
: $global_base |
|
|
100
|
|
|
|
|
|
65
|
|
|
|
|
|
|
? URI->new_abs("$url", $global_base) |
66
|
|
|
|
|
|
|
: URI->new("$url"); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub verify |
70
|
|
|
|
|
|
|
{ |
71
|
27
|
|
|
27
|
|
5391
|
my($self, %params) = @_; |
72
|
27
|
|
|
|
|
81
|
my($got, $exists) = @params{qw/ got exists /}; |
73
|
|
|
|
|
|
|
|
74
|
27
|
50
|
|
|
|
77
|
return 0 unless $exists; |
75
|
27
|
100
|
|
|
|
136
|
return 0 unless $got; |
76
|
26
|
100
|
100
|
|
|
107
|
return 0 if ref($got) && !blessed($got); |
77
|
22
|
100
|
100
|
|
|
67
|
return 0 if ref($got) && !overload::Method($got, '""'); |
78
|
|
|
|
|
|
|
|
79
|
21
|
|
|
|
|
113
|
my $url = eval { $self->_uri($got) }; |
|
21
|
|
|
|
|
85
|
|
80
|
21
|
50
|
|
|
|
11265
|
return 0 if $@; |
81
|
21
|
100
|
|
|
|
73
|
return 0 if ! $url->has_recognized_scheme; |
82
|
|
|
|
|
|
|
|
83
|
19
|
|
|
|
|
164
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub set_base |
87
|
|
|
|
|
|
|
{ |
88
|
1
|
|
|
1
|
|
3
|
my($self, $base) = @_; |
89
|
1
|
|
|
|
|
5
|
$self->{base} = $base; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub set_global_base |
93
|
|
|
|
|
|
|
{ |
94
|
2
|
|
|
2
|
|
5
|
my($self, $base) = @_; |
95
|
2
|
|
|
|
|
6
|
$global_base = $base; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub add_component |
99
|
|
|
|
|
|
|
{ |
100
|
29
|
|
|
29
|
|
65
|
my($self, $name, $expect) = @_; |
101
|
29
|
|
|
|
|
43
|
push @{ $self->{component} }, [ $name, $expect ]; |
|
29
|
|
|
|
|
110
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub deltas |
105
|
|
|
|
|
|
|
{ |
106
|
19
|
|
|
19
|
|
142
|
my($self, %args) = @_; |
107
|
19
|
|
|
|
|
53
|
my($got, $convert, $seen) = @args{'got', 'convert', 'seen'}; |
108
|
|
|
|
|
|
|
|
109
|
19
|
|
|
|
|
40
|
my $uri = $self->_uri($got); |
110
|
|
|
|
|
|
|
|
111
|
19
|
|
|
|
|
1688
|
my @deltas; |
112
|
|
|
|
|
|
|
|
113
|
19
|
|
|
|
|
37
|
foreach my $comp (@{ $self->{component} }) |
|
19
|
|
|
|
|
113
|
|
114
|
|
|
|
|
|
|
{ |
115
|
29
|
|
|
|
|
928
|
my($name, $expect) = @$comp; |
116
|
|
|
|
|
|
|
|
117
|
29
|
|
|
|
|
59
|
my $method = $name; |
118
|
29
|
100
|
|
|
|
73
|
$method = 'host_port' if $method eq 'hostport'; |
119
|
29
|
|
|
|
|
139
|
my $value = $uri->$method; |
120
|
29
|
|
|
|
|
720
|
my $check = $convert->($expect); |
121
|
|
|
|
|
|
|
|
122
|
29
|
50
|
33
|
|
|
2584
|
if($^O eq 'MSWin32' && $method eq 'path') |
123
|
|
|
|
|
|
|
{ |
124
|
0
|
|
|
|
|
0
|
$value =~ s{/([A-Z]:)}{$1}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
29
|
100
|
100
|
|
|
120
|
if($method eq 'query' && !$check->isa('Test2::Compare::String')) |
128
|
|
|
|
|
|
|
{ |
129
|
6
|
100
|
|
|
|
32
|
if($check->isa('Test2::Compare::Hash')) |
|
|
50
|
|
|
|
|
|
130
|
|
|
|
|
|
|
{ |
131
|
4
|
|
|
|
|
23
|
$value = $uri->query_form_hash; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
elsif($check->isa('Test2::Compare::Array')) |
134
|
|
|
|
|
|
|
{ |
135
|
2
|
|
|
|
|
7
|
$value = [ $uri->query_form ]; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
29
|
|
|
|
|
568
|
push @deltas => $check->run( |
141
|
|
|
|
|
|
|
id => [ HASH => $name ], |
142
|
|
|
|
|
|
|
convert => $convert, |
143
|
|
|
|
|
|
|
seen => $seen, |
144
|
|
|
|
|
|
|
exists => defined $value, |
145
|
|
|
|
|
|
|
got => $value, |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
19
|
|
|
|
|
3131
|
@deltas; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__END__ |