4 @ISA=qw(URI::WithBase);
7 use vars qw(@EXPORT $VERSION);
11 # Provide as much as possible of the old URI::URL interface for backwards
15 *import = \&Exporter::import;
18 # Easy to use constructor
19 sub url ($;$) { URI::URL->new(@_); }
21 use URI::Escape qw(uri_unescape);
26 my $self = $class->SUPER::new(@_);
27 $self->[0] = $self->[0]->canonical;
35 bless [URI::file->new_abs(shift)], $class;
38 {package URI::_foreign;
39 sub _init # hope it is not defined
42 die "Unknown URI::URL scheme $_[1]:" if $URI::URL::STRICT;
43 $class->SUPER::_init(@_);
49 my $old = $URI::URL::STRICT;
50 $URI::URL::STRICT = shift if @_;
58 print STDERR Data::Dumper::Dumper($self);
65 scalar(eval { $self->$method(@_) });
70 # should be overridden by subclasses
72 (scalar($self->scheme),
74 $self->_try("password"),
78 $self->_try("params"),
80 scalar($self->fragment),
87 my $path = $self->path_query;
88 $path = "/" unless length $path;
99 my $path = shift->SUPER::path(@_);
107 my @p = $self->path_segments;
108 return unless ref($p[-1]);
114 sub params { shift->eparams(@_); }
118 my $old = $self->epath(@_);
119 return unless defined wantarray;
120 return '/' if !defined($old) || !length($old);
121 Carp::croak("Path components contain '/' (you must call epath)")
122 if $old =~ /%2[fF]/ and !@_;
123 $old = "/$old" if $old !~ m|^/| && defined $self->netloc;
124 return uri_unescape($old);
127 sub path_components {
128 shift->path_segments(@_);
133 my $old = $self->equery(@_);
134 if (defined(wantarray) && defined($old)) {
135 if ($old =~ /%(?:26|2[bB]|3[dD])/) { # contains escaped '=' '&' or '+'
138 $mess = "Query contains both '+' and '%2B'"
140 $mess = "Form query contains escaped '=' or '&'"
141 if /=/ && /%(?:3[dD]|26)/;
144 Carp::croak("$mess (you must call equery)");
147 # Now it should be safe to unescape the string without loosing
149 return uri_unescape($old);
159 my $allow_scheme = shift;
160 $allow_scheme = $URI::URL::ABS_ALLOW_RELATIVE_SCHEME
161 unless defined $allow_scheme;
162 local $URI::ABS_ALLOW_RELATIVE_SCHEME = $allow_scheme;
163 local $URI::ABS_REMOTE_LEADING_DOTS = $URI::URL::ABS_REMOTE_LEADING_DOTS;
164 $self->SUPER::abs($base);
167 sub frag { shift->fragment(@_); }
168 sub keywords { shift->query_keywords(@_); }
171 sub local_path { shift->file; }
172 sub unix_path { shift->file("unix"); }
173 sub dos_path { shift->file("dos"); }
174 sub mac_path { shift->file("mac"); }
175 sub vms_path { shift->file("vms"); }
178 sub address { shift->to(@_); }
179 sub encoded822addr { shift->to(@_); }
180 sub URI::mailto::authority { shift->to(@_); } # make 'netloc' method work
183 sub groupart { shift->_group(@_); }
184 sub article { shift->message(@_); }
192 URI::URL - Uniform Resource Locators
196 $u1 = URI::URL->new($str, $base);
201 This module is provided for backwards compatibility with modules that
202 depend on the interface provided by the C<URI::URL> class that used to
203 be distributed with the libwww-perl library.
205 The following differences exist compared to the C<URI> class interface:
211 The URI::URL module exports the url() function as an alternate
212 constructor interface.
216 The constructor takes an optional $base argument. The C<URI::URL>
217 class is a subclass of C<URI::WithBase>.
221 The URI::URL->newlocal class method is the same as URI::file->new_abs.
229 $url->print_on method
237 $url->full_path: same as ($uri->abs_path || "/")
241 $url->netloc: same as $uri->authority
245 $url->epath, $url->equery: same as $uri->path, $uri->query
249 $url->path and $url->query pass unescaped strings.
253 $url->path_components: same as $uri->path_segments (if you don't
254 consider path segment parameters)
258 $url->params and $url->eparams methods
262 $url->base method. See L<URI::WithBase>.
266 $url->abs and $url->rel have an optional $base argument. See
271 $url->frag: same as $uri->fragment
275 $url->keywords: same as $uri->query_keywords
279 $url->localpath and friends map to $uri->file.
283 $url->address and $url->encoded822addr: same as $uri->to for mailto URI
287 $url->groupart method for news URI
291 $url->article: same as $uri->message
299 L<URI>, L<URI::WithBase>
303 Copyright 1998-2000 Gisle Aas.