Navigation Menu

Skip to content

Commit

Permalink
deprecated Mojo::URL::to_rel (closes #573)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 17, 2013
1 parent 99fa13b commit 6a2672b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 145 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

4.62 2013-12-17
- Deprecated Mojo::URL::to_rel.

4.61 2013-12-16
- Added select_one method to Mojo::DOM::CSS.
- Improved performance of Mojo::DOM::at significantly.
Expand Down
25 changes: 4 additions & 21 deletions lib/Mojo/URL.pm
Expand Up @@ -4,7 +4,8 @@ use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;

use Mojo::Parameters;
use Mojo::Path;
use Mojo::Util qw(punycode_decode punycode_encode url_escape url_unescape);
use Mojo::Util
qw(deprecated punycode_decode punycode_encode url_escape url_unescape);

has base => sub { Mojo::URL->new };
has [qw(fragment host port scheme userinfo)];
Expand Down Expand Up @@ -159,7 +160,9 @@ sub to_abs {
return $abs;
}

# DEPRECATED in Top Hat!
sub to_rel {
deprecated 'Mojo::URL::to_rel is DEPRECATED';
my $self = shift;

my $rel = $self->clone;
Expand Down Expand Up @@ -427,26 +430,6 @@ provided base URL.
Mojo::URL->new('//example.com/foo/baz.xml?test=123')
->to_abs(Mojo::URL->new('http://example.com/foo/bar.html'));
=head2 to_rel
my $rel = $url->to_rel;
my $rel = $url->to_rel(Mojo::URL->new('http://example.com/foo'));
Clone absolute URL and turn it into a relative one using L</"base"> or
provided base URL.
# "foo/bar.html?test=123"
Mojo::URL->new('http://example.com/foo/bar.html?test=123')
->to_rel(Mojo::URL->new('http://example.com'));
# "bar.html?test=123"
Mojo::URL->new('http://example.com/foo/bar.html?test=123')
->to_rel(Mojo::URL->new('http://example.com/foo/'));
# "//example.com/foo/bar.html?test=123"
Mojo::URL->new('http://example.com/foo/bar.html?test=123')
->to_rel(Mojo::URL->new('http://'));
=head2 to_string
my $str = $url->to_string;
Expand Down
32 changes: 16 additions & 16 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -50,15 +50,15 @@ sub new {

# DEPRECATED in Top Hat!
sub app {
deprecated "Mojo::UserAgent::app is DEPRECATED in favor of"
. " Mojo::UserAgent::Server::app";
deprecated 'Mojo::UserAgent::app is DEPRECATED in favor of'
. ' Mojo::UserAgent::Server::app';
shift->_delegate('server', 'app', @_);
}

# DEPRECATED in Top Hat!
sub app_url {
deprecated "Mojo::UserAgent::app_url is DEPRECATED in favor of"
. " Mojo::UserAgent::Server::url";
deprecated 'Mojo::UserAgent::app_url is DEPRECATED in favor of'
. ' Mojo::UserAgent::Server::url';
shift->_delegate('server', 'url', @_);
}

Expand All @@ -67,43 +67,43 @@ sub build_websocket_tx { shift->transactor->websocket(@_) }

# DEPRECATED in Top Hat!
sub detect_proxy {
deprecated "Mojo::UserAgent::detect_proxy is DEPRECATED in favor of"
. " Mojo::UserAgent::Proxy::detect";
deprecated 'Mojo::UserAgent::detect_proxy is DEPRECATED in favor of'
. ' Mojo::UserAgent::Proxy::detect';
shift->tap(sub { $_->proxy->detect });
}

# DEPRECATED in Top Hat!
sub http_proxy {
deprecated "Mojo::UserAgent::http_proxy is DEPRECATED in favor of"
. " Mojo::UserAgent::Proxy::http";
deprecated 'Mojo::UserAgent::http_proxy is DEPRECATED in favor of'
. ' Mojo::UserAgent::Proxy::http';
shift->_delegate('proxy', 'http', @_);
}

# DEPRECATED in Top Hat!
sub https_proxy {
deprecated "Mojo::UserAgent::https_proxy is DEPRECATED in favor of"
. " Mojo::UserAgent::Proxy::https";
deprecated 'Mojo::UserAgent::https_proxy is DEPRECATED in favor of'
. ' Mojo::UserAgent::Proxy::https';
shift->_delegate('proxy', 'https', @_);
}

# DEPRECATED in Top Hat!
sub name {
deprecated "Mojo::UserAgent::name is DEPRECATED in favor of"
. " Mojo::UserAgent::Transactor::name";
deprecated 'Mojo::UserAgent::name is DEPRECATED in favor of'
. ' Mojo::UserAgent::Transactor::name';
shift->_delegate('transactor', 'name', @_);
}

# DEPRECATED in Top Hat!
sub no_proxy {
deprecated "Mojo::UserAgent::no_proxy is DEPRECATED in favor of"
. " Mojo::UserAgent::Proxy::not";
deprecated 'Mojo::UserAgent::no_proxy is DEPRECATED in favor of'
. ' Mojo::UserAgent::Proxy::not';
shift->_delegate('proxy', 'not', @_);
}

# DEPRECATED in Top Hat!
sub need_proxy {
deprecated "Mojo::UserAgent::need_proxy is DEPRECATED in favor of"
. " Mojo::UserAgent::Proxy::is_needed";
deprecated 'Mojo::UserAgent::need_proxy is DEPRECATED in favor of'
. ' Mojo::UserAgent::Proxy::is_needed';
shift->proxy->is_needed(@_);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -43,7 +43,7 @@ has types => sub { Mojolicious::Types->new };
has validator => sub { Mojolicious::Validator->new };

our $CODENAME = 'Top Hat';
our $VERSION = '4.61';
our $VERSION = '4.62';

sub AUTOLOAD {
my $self = shift;
Expand Down
112 changes: 6 additions & 106 deletions t/mojo/url.t
Expand Up @@ -175,10 +175,6 @@ is "$url", 'foo?foo=bar#23', 'right relative version';
$url = Mojo::URL->new('/foo?foo=bar#23');
ok !$url->is_abs, 'is not absolute';
is "$url", '/foo?foo=bar#23', 'right relative version';
$url = Mojo::URL->new('http://sri:foobar@example.com:8080/foo?foo=bar#23');
$url->base->parse('http://sri:foobar@example.com:8080/');
ok $url->is_abs, 'is absolute';
is $url->to_rel, 'foo?foo=bar#23', 'right relative version';

# Relative without scheme
$url = Mojo::URL->new('//localhost/23/');
Expand Down Expand Up @@ -207,88 +203,6 @@ is $url->host, '', 'no host';
is $url->path, '//bar//23/', 'right path';
is "$url", '////bar//23/', 'right relative version';

# Relative (base without trailing slash)
$url = Mojo::URL->new('http://sri:foobar@example.com:8080/baz/foo?foo=bar#23');
$url->base->parse('http://sri:foobar@example.com:8080');
is $url->to_rel, 'baz/foo?foo=bar#23', 'right relative version';
is $url->to_rel->to_abs,
'http://sri:foobar@example.com:8080/baz/foo?foo=bar#23',
'right absolute version';
$url = Mojo::URL->new('http://sri:foobar@example.com:8080/baz/foo?foo=bar#23');
$url->base->parse('http://sri:foobar@example.com:8080/baz');
is $url->to_rel, 'baz/foo?foo=bar#23', 'right relative version';
is $url->to_rel->to_abs,
'http://sri:foobar@example.com:8080/baz/foo?foo=bar#23',
'right absolute version';

# Relative (base without authority)
$url = Mojo::URL->new('http://sri:foobar@example.com:8080/baz/foo?foo=bar#23');
$url->base->parse('http://');
is $url->to_rel, '//sri:foobar@example.com:8080/baz/foo?foo=bar#23',
'right relative version';
is $url->to_rel->to_abs,
'http://sri:foobar@example.com:8080/baz/foo?foo=bar#23',
'right absolute version';

# Relative with path
$url = Mojo::URL->new('http://example.com/foo/index.html?foo=bar#23');
$url->base->parse('http://example.com/foo/');
my $rel = $url->to_rel;
is $rel, 'index.html?foo=bar#23', 'right format';
ok !$rel->is_abs, 'not absolute';
is $rel->to_abs, 'http://example.com/foo/index.html?foo=bar#23',
'right absolute version';

# Relative (base argument)
$url = Mojo::URL->new('http://example.com/');
$rel = $url->to_rel($url->clone);
is $rel, '', 'right relative version';
is $rel->to_abs, 'http://example.com/', 'right absolute version';
is $rel->to_abs->to_rel, '', 'right relative version';
$rel = $url->to_rel(Mojo::URL->new('http://example.com/a/'));
is $rel, '..', 'right relative version';
is $rel->to_abs, 'http://example.com/', 'right absolute version';
is $rel->to_abs->to_rel, '..', 'right relative version';
$rel = $url->to_rel(Mojo::URL->new('http://example.com/a/b/'));
is $rel, '../..', 'right relative version';
is $rel->to_abs, 'http://example.com/', 'right absolute version';
is $rel->to_abs->to_rel, '../..', 'right relative version';
$url = Mojo::URL->new('http://example.com/index.html');
$rel = $url->to_rel(Mojo::URL->new('http://example.com/'));
is $rel, 'index.html', 'right relative version';
is $rel->to_abs, 'http://example.com/index.html', 'right absolute version';
is $rel->to_abs->to_rel, 'index.html', 'right relative version';
$url = Mojo::URL->new('http://example.com/index.html');
$rel = $url->to_rel(Mojo::URL->new('http://example.com/a/'));
is $rel, '../index.html', 'right relative version';
is $rel->to_abs, 'http://example.com/index.html', 'right absolute version';
is $rel->to_abs->to_rel, '../index.html', 'right relative version';
$url = Mojo::URL->new('http://example.com/index.html');
$rel = $url->to_rel(Mojo::URL->new('http://example.com/a/b/'));
is $rel, '../../index.html', 'right relative version';
is $rel->to_abs, 'http://example.com/index.html', 'right absolute version';
is $rel->to_abs->to_rel, '../../index.html', 'right relative version';
$url = Mojo::URL->new('http://example.com/a/b/c/index.html');
$rel = $url->to_rel(Mojo::URL->new('http://example.com/a/b/'));
is $rel, 'c/index.html', 'right relative version';
is $rel->to_abs, 'http://example.com/a/b/c/index.html',
'right absolute version';
is $rel->to_abs->to_rel, 'c/index.html', 'right relative version';
$url = Mojo::URL->new('http://example.com/a/b/c/d/index.html');
$rel = $url->to_rel(Mojo::URL->new('http://example.com/a/b/'));
is $rel, 'c/d/index.html', 'right relative version';
is $rel->to_abs, 'http://example.com/a/b/c/d/index.html',
'right absolute version';
is $rel->to_abs->to_rel, 'c/d/index.html', 'right relative version';
$url = Mojo::URL->new('/foo');
is $url->base, '', 'no base';
is $url->to_abs(Mojo::URL->new('http://example.com'))->base,
'http://example.com', 'right base';
$url = Mojo::URL->new('http://example.com/foo');
is $url->base, '', 'no base';
is $url->to_rel(Mojo::URL->new('http://example.com'))->base,
'http://example.com', 'right base';

# Relative path
$url = Mojo::URL->new('http://example.com/foo/?foo=bar#23');
$url->path('bar');
Expand Down Expand Up @@ -328,11 +242,6 @@ is $url->to_abs, 'http://www.aviary.com/cages/birds.gif',
$url = Mojo::URL->new('../foo?foo=bar#23');
$url->base->parse('http://example.com/bar/baz/');
ok !$url->is_abs, 'not absolute';
is $url->to_abs, 'http://example.com/bar/foo?foo=bar#23',
'right absolute version';
is $url->to_abs->to_rel, '../foo?foo=bar#23', 'right relative version';
is $url->to_abs->to_rel->to_abs, 'http://example.com/bar/foo?foo=bar#23',
'right absolute version';
is $url->to_abs, 'http://example.com/bar/foo?foo=bar#23',
'right absolute version';
is $url->to_abs->base, 'http://example.com/bar/baz/', 'right base';
Expand Down Expand Up @@ -472,28 +381,19 @@ is "$url", 'http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83',
$url = Mojo::URL->new('http://foo.com/');
is $url->to_abs, 'http://foo.com/', 'right absolute version';

# Already relative
$url = Mojo::URL->new('http://sri:foobar@example.com:8080/foo?foo=bar#23');
$url->base->parse('http://sri:foobar@example.com:8080/');
my $url2 = $url->to_rel;
is $url->to_rel, 'foo?foo=bar#23', 'right relative version';

# Empty path elements
$url = Mojo::URL->new('http://example.com/foo//bar/23/');
$url->base->parse('http://example.com/');
ok $url->is_abs, 'is absolute';
is $url->to_rel, 'foo//bar/23/', 'right relative version';
is $url->path, '/foo//bar/23/', 'right path';
is "$url", 'http://example.com/foo//bar/23/', 'right format';
$url = Mojo::URL->new('http://example.com//foo//bar/23/');
$url->base->parse('http://example.com/');
ok $url->is_abs, 'is absolute';
is $url->to_rel, '/foo//bar/23/', 'right relative version';
is $url->path, '//foo//bar/23/', 'right path';
is "$url", 'http://example.com//foo//bar/23/', 'right format';
$url = Mojo::URL->new('http://example.com/foo///bar/23/');
$url->base->parse('http://example.com/');
ok $url->is_abs, 'is absolute';
is $url->to_rel, 'foo///bar/23/', 'right relative version';
is $url->to_abs, 'http://example.com/foo///bar/23/', 'right absolute version';
ok $url->is_abs, 'is absolute';
is $url->to_rel, 'foo///bar/23/', 'right relative version';
is $url->path, '/foo///bar/23/', 'right path';
is "$url", 'http://example.com/foo///bar/23/', 'right format';

# Merge relative path
$url = Mojo::URL->new('http://foo.bar/baz?yada');
Expand Down
2 changes: 1 addition & 1 deletion t/pod_coverage.t
Expand Up @@ -10,7 +10,7 @@ plan skip_all => 'Test::Pod::Coverage 1.04 required for this test!'
# DEPRECATED in Top Hat!
my @tophat = (
qw(app app_url detect_proxy http_proxy https_proxy name need_proxy new),
qw(no_proxy)
qw(no_proxy to_rel)
);

# False positive constants
Expand Down

0 comments on commit 6a2672b

Please sign in to comment.