| 1 | package Cake::URI; | ||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 8 | ▶ | use base 'Exporter'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 8 | our @EXPORT = qw( | |||||||||||||
| 7 | uri_for | ||||||||||||||
| 8 | uri_with | ||||||||||||||
| 9 | subdomain | ||||||||||||||
| 10 | subdomains | ||||||||||||||
| 11 | ); | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 0 | ▶ | sub uri_encode { | ||||||||||||
|
Subroutine
uri_encode: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 14 | 0 | ▶ | return '' if !$_[0]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 0 | $_[0] =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; | |||||||||||||
| 16 | 0 | return $_[0]; | |||||||||||||
| 17 | } | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 2 | ▶ | sub uri_decode { | ||||||||||||
|
Subroutine
uri_decode: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||
| 20 | 2 | $_[0] =~ tr/+/ /; | |||||||||||||
| 21 | 0 | $_[0] =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg; | |||||||||||||
| 22 | 2 | return $_[0]; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | |||||||||||||||
| 25 | #============================================================================ | ||||||||||||||
| 26 | # url functions | ||||||||||||||
| 27 | #============================================================================ | ||||||||||||||
| 28 | 0 | ▶ | sub uri_for { | ||||||||||||
|
Subroutine
uri_for: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 29 | 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 | 0 | ▶ | sub uri_with { | ||||||||||||
|
Subroutine
uri_with: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||
| 38 | ##localize params | ||||||||||||||
| 39 | 0 | local $self->{params}; | |||||||||||||
| 40 | 0 | for (@_){ | |||||||||||||
| 41 | 0 | ▶ | if (ref $_ eq 'HASH'){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 0 | ▶ | sub get_full_url { | ||||||||||||
|
Subroutine
get_full_url: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||
| 55 | 0 | my $path = ''; | |||||||||||||
| 56 | 0 | my $params = {}; | |||||||||||||
| 57 | 0 | my $url = $self->base; | |||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | ▶ | if (!ref $_[0]){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | $path = shift; | |||||||||||||
| 62 | ##if request url has script name keep it | ||||||||||||||
| 63 | 0 | my $script = $self->env->{SCRIPT_NAME}; | |||||||||||||
| 64 | 0 | ▶ | if ($self->env->{REQUEST_URI} =~ m/^$script/){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 0 | $url = $self->base.$script; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | ▶ | if ($path =~ /^http/){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 69 | 0 | $url = $path; | |||||||||||||
| 70 | } elsif ($path =~ /^\//){ | ||||||||||||||
| 71 | 0 | $url .= $path; | |||||||||||||
| 72 | } else { | ||||||||||||||
| 73 | $url .= lc $self->action->{namespace} | ||||||||||||||
| 74 | 0 | .'/'.$path; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | } else { | ||||||||||||||
| 78 | 0 | $url = $self->env->{'REQUEST_URI'}; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | ▶ | if (ref $_[0] eq 'ARRAY') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 82 | 0 | my $args = shift; | |||||||||||||
| 83 | 0 | foreach my $arg (@{$args}){ | |||||||||||||
| 84 | 0 | $url .= '/'.$arg; | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | } elsif (ref $_[0] eq 'HASH') { | ||||||||||||||
| 87 | 0 | $params = shift; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 0 | ▶ | if (keys %{$params}){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 0 | my @params; | |||||||||||||
| 92 | 0 | ▶ | while (my ($key,$value) = each(%{$params})) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 0 | ▶ | sub subdomain { | ||||||||||||
|
Subroutine
subdomain: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||
| 105 | 0 | ▶ | return $self->{'subdomain'} if $self->{'subdomain'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 0 | ▶ | sub subdomains { | ||||||||||||
|
Subroutine
subdomains: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||
| 120 | 0 | ▶ | return $self->{'subdomains'} if $self->{'subdomains'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 8 | 1; | |||||||||||||
| 129 | |||||||||||||||
| 130 | __END__ | ||||||||||||||