File Coverage

blib/lib/URI/URL.pm
Criterion Covered Total %
statement 89 93 95.7
branch 21 28 75.0
condition 11 18 61.1
subroutine 32 34 94.1
pod 3 27 11.1
total 156 200 78.0


line stmt bran cond sub pod time code
1             package URI::URL;
2              
3 6     6   275993 use strict;
  6         41  
  6         212  
4 6     6   50 use warnings;
  6         18  
  6         191  
5              
6 6     6   2740 use parent 'URI::WithBase';
  6         1946  
  6         37  
7              
8             our $VERSION = '5.20';
9              
10             # Provide as much as possible of the old URI::URL interface for backwards
11             # compatibility...
12              
13 6     6   382 use Exporter 5.57 'import';
  6         94  
  6         394  
14             our @EXPORT = qw(url);
15              
16             # Easy to use constructor
17 7     7 0 265 sub url ($;$) { URI::URL->new(@_); }
18              
19 6     6   46 use URI::Escape qw(uri_unescape);
  6         11  
  6         7830  
20              
21             sub new
22             {
23 255     255 1 57163 my $class = shift;
24 255         726 my $self = $class->SUPER::new(@_);
25 255         1046 $self->[0] = $self->[0]->canonical;
26 255         829 $self;
27             }
28              
29             sub newlocal
30             {
31 6     6 0 143 my $class = shift;
32 6         78 require URI::file;
33 6         88 bless [URI::file->new_abs(shift)], $class;
34             }
35              
36             {package URI::_foreign;
37             sub _init # hope it is not defined
38             {
39 8     8   16 my $class = shift;
40 8 50       20 die "Unknown URI::URL scheme $_[1]:" if $URI::URL::STRICT;
41 8         39 $class->SUPER::_init(@_);
42             }
43             }
44              
45             sub strict
46             {
47 2     2 0 1422 my $old = $URI::URL::STRICT;
48 2 50       10 $URI::URL::STRICT = shift if @_;
49 2         5 $old;
50             }
51              
52             sub print_on
53             {
54 0     0 0 0 my $self = shift;
55 0         0 require Data::Dumper;
56 0         0 print STDERR Data::Dumper::Dumper($self);
57             }
58              
59             sub _try
60             {
61 42     42   92 my $self = shift;
62 42         60 my $method = shift;
63 42         52 scalar(eval { $self->$method(@_) });
  42         119  
64             }
65              
66             sub crack
67             {
68             # should be overridden by subclasses
69 6     6 0 10 my $self = shift;
70 6         32 (scalar($self->scheme),
71             $self->_try("user"),
72             $self->_try("password"),
73             $self->_try("host"),
74             $self->_try("port"),
75             $self->_try("path"),
76             $self->_try("params"),
77             $self->_try("query"),
78             scalar($self->fragment),
79             )
80             }
81              
82             sub full_path
83             {
84 8     8 0 3515 my $self = shift;
85 8         43 my $path = $self->path_query;
86 8 50       28 $path = "/" unless length $path;
87 8         55 $path;
88             }
89              
90             sub netloc
91             {
92 16     16 0 1465 shift->authority(@_);
93             }
94              
95             sub epath
96             {
97 33     33 0 663 my $path = shift->SUPER::path(@_);
98 33         79 $path =~ s/;.*//;
99 33         64 $path;
100             }
101              
102             sub eparams
103             {
104 12     12 0 777 my $self = shift;
105 12         56 my @p = $self->path_segments;
106 11 100       59 return undef unless ref($p[-1]);
107 3         43 @p = @{$p[-1]};
  3         41  
108 3         10 shift @p;
109 3         19 join(";", @p);
110             }
111              
112 10     10 0 2686 sub params { shift->eparams(@_); }
113              
114             sub path {
115 28     28 0 6349 my $self = shift;
116 28         78 my $old = $self->epath(@_);
117 28 100       83 return unless defined wantarray;
118 23 50 33     99 return '/' if !defined($old) || !length($old);
119 23 100 66     326 Carp::croak("Path components contain '/' (you must call epath)")
120             if $old =~ /%2[fF]/ and !@_;
121 22 100 100     81 $old = "/$old" if $old !~ m|^/| && defined $self->netloc;
122 22         58 return uri_unescape($old);
123             }
124              
125             sub path_components {
126 4     4 0 37 shift->path_segments(@_);
127             }
128              
129             sub query {
130 18     18 0 4732 my $self = shift;
131 18         85 my $old = $self->equery(@_);
132 18 100 100     80 if (defined(wantarray) && defined($old)) {
133 7 100       30 if ($old =~ /%(?:26|2[bB]|3[dD])/) { # contains escaped '=' '&' or '+'
134 1         4 my $mess;
135 1         4 for ($old) {
136 1 50 33     5 $mess = "Query contains both '+' and '%2B'"
137             if /\+/ && /%2[bB]/;
138 1 50 33     11 $mess = "Form query contains escaped '=' or '&'"
139             if /=/ && /%(?:3[dD]|26)/;
140             }
141 1 50       6 if ($mess) {
142 1         116 Carp::croak("$mess (you must call equery)");
143             }
144             }
145             # Now it should be safe to unescape the string without losing
146             # information
147 6         16 return uri_unescape($old);
148             }
149 11         44 undef;
150              
151             }
152              
153             sub abs
154             {
155 80     80 1 243 my $self = shift;
156 80         113 my $base = shift;
157 80         99 my $allow_scheme = shift;
158 80 100       172 $allow_scheme = $URI::URL::ABS_ALLOW_RELATIVE_SCHEME
159             unless defined $allow_scheme;
160 80         117 local $URI::ABS_ALLOW_RELATIVE_SCHEME = $allow_scheme;
161 80         107 local $URI::ABS_REMOTE_LEADING_DOTS = $URI::URL::ABS_REMOTE_LEADING_DOTS;
162 80         255 $self->SUPER::abs($base);
163             }
164              
165 7     7 0 2788 sub frag { shift->fragment(@_); }
166 5     5 0 36 sub keywords { shift->query_keywords(@_); }
167              
168             # file:
169 1     1 0 43 sub local_path { shift->file; }
170 9     9 0 66 sub unix_path { shift->file("unix"); }
171 2     2 0 43 sub dos_path { shift->file("dos"); }
172 3     3 0 23 sub mac_path { shift->file("mac"); }
173 0     0 0 0 sub vms_path { shift->file("vms"); }
174              
175             # mailto:
176 1     1 0 757 sub address { shift->to(@_); }
177 1     1 0 721 sub encoded822addr { shift->to(@_); }
178 1     1 1 6 sub URI::mailto::authority { shift->to(@_); } # make 'netloc' method work
179              
180             # news:
181 1     1 0 21 sub groupart { shift->_group(@_); }
182 3     3 0 29 sub article { shift->message(@_); }
183              
184             1;
185              
186             __END__