line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package URI::FromHash; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24206
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
880
|
use Params::Validate qw( validate SCALAR ARRAYREF HASHREF ); |
|
1
|
|
|
|
|
7580
|
|
|
1
|
|
|
|
|
82
|
|
9
|
1
|
|
|
1
|
|
827
|
use URI 1.68; |
|
1
|
|
|
|
|
8436
|
|
|
1
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
7
|
use Exporter qw( import ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
711
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( uri uri_object ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %BaseParams = ( |
16
|
|
|
|
|
|
|
scheme => { type => SCALAR, optional => 1 }, |
17
|
|
|
|
|
|
|
username => { type => SCALAR, optional => 1 }, |
18
|
|
|
|
|
|
|
password => { type => SCALAR, default => q{} }, |
19
|
|
|
|
|
|
|
host => { type => SCALAR, optional => 1 }, |
20
|
|
|
|
|
|
|
port => { type => SCALAR, optional => 1 }, |
21
|
|
|
|
|
|
|
path => { type => SCALAR | ARRAYREF, optional => 1 }, |
22
|
|
|
|
|
|
|
query => { type => HASHREF, default => {} }, |
23
|
|
|
|
|
|
|
fragment => { type => SCALAR, optional => 1 }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub uri_object { |
27
|
17
|
|
|
17
|
1
|
528
|
my %p = validate( @_, \%BaseParams ); |
28
|
17
|
|
|
|
|
107
|
_check_required( \%p ); |
29
|
|
|
|
|
|
|
|
30
|
17
|
|
|
|
|
68
|
my $uri = URI->new(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$uri->scheme( $p{scheme} ) |
33
|
17
|
100
|
|
|
|
6742
|
if grep { defined && length } $p{scheme}; |
|
17
|
100
|
|
|
|
118
|
|
34
|
|
|
|
|
|
|
|
35
|
17
|
100
|
|
|
|
4358
|
if ( grep { defined && length } $p{username}, $p{password} ) { |
|
34
|
100
|
|
|
|
144
|
|
36
|
3
|
|
50
|
|
|
9
|
$p{username} ||= q{}; |
37
|
3
|
|
100
|
|
|
11
|
$p{password} ||= q{}; |
38
|
3
|
50
|
33
|
|
|
25
|
if ( $uri->can('user') && $uri->can('password') ) { |
39
|
0
|
|
|
|
|
0
|
$uri->user( $p{username} ); |
40
|
0
|
|
|
|
|
0
|
$uri->password( $p{password} ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
3
|
|
|
|
|
15
|
$uri->userinfo("$p{username}:$p{password}"); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
17
|
|
|
|
|
150
|
for my $k (qw( host port )) { |
48
|
|
|
|
|
|
|
$uri->$k( $p{$k} ) |
49
|
34
|
100
|
|
|
|
840
|
if grep { defined && length } $p{$k}; |
|
34
|
100
|
|
|
|
188
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
17
|
100
|
|
|
|
87
|
if ( $p{path} ) { |
53
|
7
|
100
|
|
|
|
19
|
if ( ref $p{path} ) { |
54
|
5
|
|
|
|
|
7
|
$uri->path( join '/', grep {defined} @{ $p{path} } ); |
|
22
|
|
|
|
|
50
|
|
|
5
|
|
|
|
|
10
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
2
|
|
|
|
|
6
|
$uri->path( $p{path} ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
17
|
|
|
|
|
241
|
$uri->query_form( $p{query} ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$uri->fragment( $p{fragment} ) |
64
|
17
|
100
|
|
|
|
748
|
if grep { defined && length } $p{fragment}; |
|
17
|
100
|
|
|
|
85
|
|
65
|
|
|
|
|
|
|
|
66
|
17
|
|
|
|
|
105
|
return $uri; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
my $spec = { |
71
|
|
|
|
|
|
|
%BaseParams, |
72
|
|
|
|
|
|
|
query_separator => { type => SCALAR, default => ';' }, |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub uri { |
76
|
18
|
|
|
18
|
1
|
10319
|
my %p = validate( |
77
|
|
|
|
|
|
|
@_, |
78
|
|
|
|
|
|
|
$spec, |
79
|
|
|
|
|
|
|
); |
80
|
18
|
|
|
|
|
116
|
_check_required( \%p ); |
81
|
|
|
|
|
|
|
|
82
|
16
|
|
|
|
|
36
|
my $sep = delete $p{query_separator}; |
83
|
16
|
|
|
|
|
48
|
my $uri = uri_object(%p); |
84
|
|
|
|
|
|
|
|
85
|
16
|
100
|
66
|
|
|
75
|
if ( $sep ne '&' && $uri->query() ) { |
86
|
4
|
|
|
|
|
52
|
my $query = $uri->query(); |
87
|
4
|
|
|
|
|
37
|
$query =~ s/&/$sep/g; |
88
|
4
|
|
|
|
|
11
|
$uri->query($query); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# force stringification |
92
|
16
|
|
|
|
|
260
|
return $uri->canonical() . q{}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _check_required { |
97
|
35
|
|
|
35
|
|
49
|
my $p = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return |
100
|
|
|
|
|
|
|
if ( |
101
|
70
|
100
|
|
|
|
334
|
grep { defined and length } |
102
|
35
|
100
|
|
|
|
57
|
map { $p->{$_} } qw( host fragment ) |
|
70
|
|
|
|
|
174
|
|
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return |
106
|
|
|
|
|
|
|
if ref $p->{path} |
107
|
7
|
|
|
|
|
22
|
? @{ $p->{path} } |
108
|
10
|
100
|
66
|
|
|
37
|
: defined $p->{path} && length $p->{path}; |
|
|
100
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
2
|
50
|
|
|
|
3
|
return if keys %{ $p->{query} }; |
|
2
|
|
|
|
|
11
|
|
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
28
|
require Carp; |
113
|
2
|
|
|
|
|
5
|
local $Carp::CarpLevel = 1; |
114
|
2
|
|
|
|
|
281
|
Carp::croak( 'None of the required parameters ' |
115
|
|
|
|
|
|
|
. '(host, path, fragment, or query) were given' ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# ABSTRACT: Build a URI from a set of named parameters |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |