Skip to content

Commit

Permalink
removed schemes and data attributes from Mojo::URL
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 7, 2013
1 parent be51a3b commit d4436f3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 106 deletions.
5 changes: 3 additions & 2 deletions Changes
@@ -1,8 +1,9 @@

3.98 2013-05-07
- Added schemes attribute to Mojo::URL.
4.0 2013-05-07
- Added is_empty method to Mojo::Transaction::HTTP.
- Added close_gracefully method to Mojo::IOLoop::Stream.
- Removed data attribute from Mojo::URL.
- Removed deprecated end method from Mojo::IOLoop::Delay.
- Removed deprecated build_form_tx, build_json_tx, post_form and post_json
methods from Mojo::UserAgent.
- Removed deprecated form and json methods from Mojo::UserAgent::Transactor.
Expand Down
17 changes: 1 addition & 16 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -2,7 +2,6 @@ package Mojo::IOLoop::Delay;
use Mojo::Base 'Mojo::EventEmitter';

use Mojo::IOLoop;
use Mojo::Util 'deprecated';

has ioloop => sub { Mojo::IOLoop->singleton };

Expand All @@ -13,13 +12,6 @@ sub begin {
return sub { $ignore // 1 and shift; $self->_step($id, @_) };
}

# DEPRECATED in Rainbow!
sub end {
deprecated
'Mojo::IOLoop::Delay::end is DEPRECATED in favor of generated callbacks';
shift->_step(undef, @_);
}

sub steps {
my $self = shift;
$self->{steps} = [@_];
Expand All @@ -38,18 +30,11 @@ sub wait {
sub _step {
my ($self, $id) = (shift, shift);

if (defined $id) { $self->{args}[$id] = [@_] }

# DEPRECATED in Rainbow!
else { push @{$self->{unordered}}, @_ }

$self->{args}[$id] = [@_];
return $self->{pending} if --$self->{pending} || $self->{lock};
local $self->{lock} = 1;
my @args = (map {@$_} grep {defined} @{delete($self->{args}) || []});

# DEPRECATED in Rainbow!
push @args, @{delete($self->{unordered}) || []};

$self->{counter} = 0;
if (my $cb = shift @{$self->{steps} ||= []}) { $self->$cb(@args) }

Expand Down
52 changes: 9 additions & 43 deletions lib/Mojo/URL.pm
Expand Up @@ -10,8 +10,7 @@ use Mojo::Path;
use Mojo::Util qw(punycode_decode punycode_encode url_escape url_unescape);

has base => sub { Mojo::URL->new };
has [qw(data fragment host port scheme userinfo)];
has schemes => sub { [qw(http https ws wss)] };
has [qw(fragment host port scheme userinfo)];

sub new { shift->SUPER::new->parse(@_) }

Expand Down Expand Up @@ -46,8 +45,7 @@ sub clone {
my $self = shift;

my $clone = $self->new;
$clone->$_($self->$_)
for qw(schemes scheme data userinfo host port fragment);
$clone->$_($self->$_) for qw(scheme userinfo host port fragment);
$clone->path($self->path->clone);
$clone->query($self->query->clone);
$clone->base($self->base->clone) if $self->{base};
Expand Down Expand Up @@ -82,13 +80,7 @@ sub parse {
# Official regex
$url =~ m!(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?!;

# Preserve scheme data
my $proto = $self->scheme($1)->protocol;
return $self->data(substr($url, length($proto) + 1))
if $proto && !grep { $proto eq $_ } @{$self->schemes};

# Supported scheme or relative
$self->authority($2);
$self->scheme($1)->authority($2);
$self->path->parse($3);
return $self->query($4)->fragment($5);
}
Expand Down Expand Up @@ -201,29 +193,24 @@ sub to_rel {
sub to_string {
my $self = shift;

# Scheme data
my $data = $self->data;
return join ':', $self->scheme, $data if defined $data;

# Protocol
my $url = '';
if (my $proto = $self->protocol) { $url .= "$proto://" }
if (my $proto = $self->protocol) { $url .= "$proto:" }

# Authority
my $authority = $self->authority;
$url .= $url ? $authority : $authority ? "//$authority" : '';
$url .= "//$authority" if $authority;

# Relative path
my $path = $self->path;
if (!$url) { $url .= "$path" }
if (!$authority) { $url .= "$path" }

# Absolute path
elsif ($path->leading_slash) { $url .= "$path" }
else { $url .= @{$path->parts} ? "/$path" : '' }

# Query
my $query = join '', $self->query;
$url .= "?$query" if length $query;
if (length(my $query = $self->query)) { $url .= "?$query" }

# Fragment
my $fragment = $self->fragment;
Expand Down Expand Up @@ -284,16 +271,6 @@ L<Mojo::URL> implements the following attributes.
Base of this URL.
=head2 data
my $data = $url->data;
$url = $url->data('foo')
Data preserved for unknown schemes.
# "sri@example.com"
Mojo::URL->new('mailto:sri@example.com')->data;
=head2 fragment
my $fragment = $url->fragment;
Expand Down Expand Up @@ -322,13 +299,6 @@ Port part of this URL.
Scheme part of this URL.
=head2 schemes
my $schemes = $url->schemes;
$url = $url->schemes([qw(http https)]);
Schemes that can be parsed, defaults to C<http>, C<https>, C<ws> and C<wss>.
=head2 userinfo
my $userinfo = $url->userinfo;
Expand Down Expand Up @@ -381,8 +351,7 @@ Check if URL is absolute.
$url = $url->parse('http://127.0.0.1:3000/foo/bar?fo=o&baz=23#foo');
Parse relative or absolute URL for supported C<schemes> and preserve scheme
data for all unknown ones.
Parse relative or absolute URL.
# "/test/123"
$url->parse('/test/123?foo=bar')->path;
Expand All @@ -391,10 +360,7 @@ data for all unknown ones.
$url->parse('http://example.com/test/123?foo=bar')->host;
# "sri@example.com"
$url->parse('mailto:sri@example.com')->data;
# "/baz"
$url->schemes(['foo'])->parse('foo://bar/baz')->path;
$url->parse('mailto:sri@example.com')->path;
=head2 path
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -39,8 +39,8 @@ has sessions => sub { Mojolicious::Sessions->new };
has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.98';
our $CODENAME = 'Top Hat';
our $VERSION = '4.0';

sub AUTOLOAD {
my $self = shift;
Expand Down Expand Up @@ -635,6 +635,8 @@ L<http://www.apache.org/licenses/LICENSE-2.0>.
Every major release of L<Mojolicious> has a code name, these are the ones that
have been used in the past.
4.0, C<Top Hat> (u1F3A9)
3.0, C<Rainbow> (u1F308)
2.0, C<Leaf Fluttering In Wind> (u1F343)
Expand Down
72 changes: 33 additions & 39 deletions t/mojo/url.t
Expand Up @@ -96,51 +96,45 @@ is $url->fragment, '23', 'right fragment';
is "$url", 'wss://sri:foobar@example.com:8080?_monkeybiz%3B=&_monkey=&23=#23',
'right format';

# Unknown scheme
# No authority
$url = Mojo::URL->new('DATA:helloworld123');
is $url->scheme, 'DATA', 'right scheme';
is $url->protocol, 'data', 'right protocol';
is $url->userinfo, undef, 'no userinfo';
is $url->host, undef, 'no host';
is $url->port, undef, 'no port';
is $url->path, '', 'no path';
is $url->query, '', 'no query';
is $url->fragment, undef, 'no fragment';
is "$url", 'DATA:helloworld123', 'right format';
is $url->scheme, 'DATA', 'right scheme';
is $url->protocol, 'data', 'right protocol';
is $url->userinfo, undef, 'no userinfo';
is $url->host, undef, 'no host';
is $url->port, undef, 'no port';
is $url->path, 'helloworld123', 'right path';
is $url->query, '', 'no query';
is $url->fragment, undef, 'no fragment';
is "$url", 'data:helloworld123', 'right format';
$url = $url->clone;
is $url->scheme, 'DATA', 'right scheme';
is $url->protocol, 'data', 'right protocol';
is $url->userinfo, undef, 'no userinfo';
is $url->host, undef, 'no host';
is $url->port, undef, 'no port';
is $url->path, '', 'no path';
is $url->query, '', 'no query';
is $url->fragment, undef, 'no fragment';
is "$url", 'DATA:helloworld123', 'right format';
is $url->scheme, 'DATA', 'right scheme';
is $url->protocol, 'data', 'right protocol';
is $url->userinfo, undef, 'no userinfo';
is $url->host, undef, 'no host';
is $url->port, undef, 'no port';
is $url->path, 'helloworld123', 'right path';
is $url->query, '', 'no query';
is $url->fragment, undef, 'no fragment';
is "$url", 'data:helloworld123', 'right format';
$url = Mojo::URL->new->parse('mailto:sri@example.com');
is $url->scheme, 'mailto', 'right scheme';
is $url->protocol, 'mailto', 'right protocol';
is $url->data, 'sri@example.com', 'right data';
is $url->path, 'sri@example.com', 'right path';
is "$url", 'mailto:sri@example.com', 'right format';
$url = Mojo::URL->new->parse('foo://test/123');
is $url->scheme, 'foo', 'right scheme';
is $url->protocol, 'foo', 'right protocol';
is $url->data, '//test/123', 'right data';
is "$url", 'foo://test/123', 'right format';
is $url->scheme('Bar')->to_string, 'Bar://test/123', 'right format';
is $url->scheme, 'Bar', 'right scheme';
is $url->protocol, 'bar', 'right protocol';
is $url->host, undef, 'no host';
is $url->path, '', 'no path';
is $url->data, '//test/123', 'right data';
$url = Mojo::URL->new->schemes(['foo'])->parse('foo://test/123');
is $url->scheme, 'foo', 'right scheme';
is $url->protocol, 'foo', 'right protocol';
is $url->host, 'test', 'right host';
is $url->path, '/123', 'right path';
is $url->data, undef, 'no data';
is "$url", 'foo://test/123', 'right format';
is_deeply $url->clone->schemes, ['foo'], 'right schemes';
$url = Mojo::URL->new->parse('foo:/test/123?foo=bar');
is $url->scheme, 'foo', 'right scheme';
is $url->protocol, 'foo', 'right protocol';
is $url->path, '/test/123', 'right path';
is $url->query, 'foo=bar', 'right query';
is "$url", 'foo:/test/123?foo=bar', 'right format';
is $url->scheme('Bar')->to_string, 'bar:/test/123?foo=bar', 'right format';
is $url->scheme, 'Bar', 'right scheme';
is $url->protocol, 'bar', 'right protocol';
is $url->host, undef, 'no host';
is $url->path, '/test/123', 'right path';
is $url->query, 'foo=bar', 'right query';
is "$url", 'bar:/test/123?foo=bar', 'right format';

# Relative
$url = Mojo::URL->new('foo?foo=bar#23');
Expand Down
5 changes: 1 addition & 4 deletions t/pod_coverage.t
Expand Up @@ -7,8 +7,5 @@ plan skip_all => 'set TEST_POD to enable this test (developer only!)'
plan skip_all => 'Test::Pod::Coverage 1.04 required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

# DEPRECATED in Rainbow!
my @rainbow = ('end');

# False positive constants
all_pod_coverage_ok({also_private => [@rainbow, qw(IPV6 TLS)]});
all_pod_coverage_ok({also_private => [qw(IPV6 TLS)]});

0 comments on commit d4436f3

Please sign in to comment.