line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cake::URI;
|
2
|
8
|
|
|
8
|
|
42
|
use strict;
|
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
311
|
|
3
|
8
|
|
|
8
|
|
40
|
use warnings;
|
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
199
|
|
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
37
|
use base 'Exporter';
|
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
7282
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw(
|
7
|
|
|
|
|
|
|
uri_for
|
8
|
|
|
|
|
|
|
uri_with
|
9
|
|
|
|
|
|
|
subdomain
|
10
|
|
|
|
|
|
|
subdomains
|
11
|
|
|
|
|
|
|
);
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub uri_encode {
|
14
|
0
|
0
|
|
0
|
0
|
0
|
return '' if !$_[0];
|
15
|
0
|
|
|
|
|
0
|
$_[0] =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
|
|
0
|
|
|
|
|
0
|
|
16
|
0
|
|
|
|
|
0
|
return $_[0];
|
17
|
|
|
|
|
|
|
}
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub uri_decode {
|
20
|
2
|
|
|
2
|
0
|
6
|
$_[0] =~ tr/+/ /;
|
21
|
2
|
|
|
|
|
5
|
$_[0] =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
|
|
0
|
|
|
|
|
0
|
|
22
|
2
|
|
|
|
|
10
|
return $_[0];
|
23
|
|
|
|
|
|
|
}
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#============================================================================
|
26
|
|
|
|
|
|
|
# url functions
|
27
|
|
|
|
|
|
|
#============================================================================
|
28
|
|
|
|
|
|
|
sub uri_for {
|
29
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
30
|
0
|
|
|
|
|
|
return get_full_url($self,@_);
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
#=============================================================================
|
33
|
|
|
|
|
|
|
# return current url with path & parameters
|
34
|
|
|
|
|
|
|
# we can add new params to the requested URL $c->get_full_url({param=> value ...});
|
35
|
|
|
|
|
|
|
#=============================================================================
|
36
|
|
|
|
|
|
|
sub uri_with {
|
37
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
38
|
|
|
|
|
|
|
##localize params
|
39
|
0
|
|
|
|
|
|
local $self->{params};
|
40
|
0
|
|
|
|
|
|
for (@_){
|
41
|
0
|
0
|
|
|
|
|
if (ref $_ eq 'HASH'){
|
42
|
0
|
|
|
|
|
|
$_ = $self->param($_);
|
43
|
0
|
|
|
|
|
|
last;
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return get_full_url($self,@_);
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#=============================================================================
|
51
|
|
|
|
|
|
|
# get current full url
|
52
|
|
|
|
|
|
|
#=============================================================================
|
53
|
|
|
|
|
|
|
sub get_full_url {
|
54
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
55
|
0
|
|
|
|
|
|
my $path = '';
|
56
|
0
|
|
|
|
|
|
my $params = {};
|
57
|
0
|
|
|
|
|
|
my $url = $self->base;
|
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (!ref $_[0]){
|
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$path = shift;
|
62
|
|
|
|
|
|
|
##if request url has script name keep it
|
63
|
0
|
|
|
|
|
|
my $script = $self->env->{SCRIPT_NAME};
|
64
|
0
|
0
|
|
|
|
|
if ($self->env->{REQUEST_URI} =~ m/^$script/){
|
65
|
0
|
|
|
|
|
|
$url = $self->base.$script;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ($path =~ /^http/){
|
|
|
0
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$url = $path;
|
70
|
|
|
|
|
|
|
} elsif ($path =~ /^\//){
|
71
|
0
|
|
|
|
|
|
$url .= $path;
|
72
|
|
|
|
|
|
|
} else {
|
73
|
0
|
|
|
|
|
|
$url .= lc $self->action->{namespace}
|
74
|
|
|
|
|
|
|
.'/'.$path;
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} else {
|
78
|
0
|
|
|
|
|
|
$url = $self->env->{'REQUEST_URI'};
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if (ref $_[0] eq 'ARRAY') {
|
|
|
0
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $args = shift;
|
83
|
0
|
|
|
|
|
|
foreach my $arg (@{$args}){
|
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$url .= '/'.$arg;
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
} elsif (ref $_[0] eq 'HASH') {
|
87
|
0
|
|
|
|
|
|
$params = shift;
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if (keys %{$params}){
|
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my @params;
|
92
|
0
|
|
|
|
|
|
while (my ($key,$value) = each(%{$params})) {
|
|
0
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
push(@params,$key.'='.uri_encode($value));
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$params = join('&',@params);
|
97
|
0
|
|
|
|
|
|
$url .= '?'.$params;
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $url;
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub subdomain {
|
104
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
105
|
0
|
0
|
|
|
|
|
return $self->{'subdomain'} if $self->{'subdomain'};
|
106
|
|
|
|
|
|
|
###parse sub domains
|
107
|
0
|
|
|
|
|
|
my $host = $self->host;
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#remove port
|
110
|
0
|
|
|
|
|
|
$host =~ s/:\d+//;
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$host =~ s/^(([^\/]+?\.)*)([^\.]{2,})((\.[a-z]{1,4}))$/$1/;
|
113
|
0
|
|
|
|
|
|
$host =~ s/\.$//;
|
114
|
0
|
|
|
|
|
|
$self->{'subdomain'} = $host;
|
115
|
0
|
|
|
|
|
|
return $host;
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub subdomains {
|
119
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
120
|
0
|
0
|
|
|
|
|
return $self->{'subdomains'} if $self->{'subdomains'};
|
121
|
|
|
|
|
|
|
###parse sub domains
|
122
|
0
|
|
|
|
|
|
my $host = $self->subdomain;
|
123
|
0
|
|
|
|
|
|
my @subs = split(/\./,$host);
|
124
|
0
|
|
|
|
|
|
$self->{'subdomains'} = \@subs;
|
125
|
0
|
|
|
|
|
|
return \@subs;
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1;
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__
|