Skip to content

Commit

Permalink
more Mojo::URL examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 22, 2013
1 parent ca2aa4c commit cb24ea6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/Mojo/URL.pm
Expand Up @@ -416,8 +416,17 @@ appended, defaults to a L<Mojo::Parameters> object.
Clone relative URL and turn it into an absolute one using C<base> or provided
base URL.
# "http://example.com/foo?bar=baz"
Mojo::URL->new('foo?bar=baz')->to_rel(Mojo::URL->new('http://example.com'));
# "http://example.com/foo/baz.xml?test=123"
Mojo::URL->new('baz.xml?test=123')
->to_abs(Mojo::URL->new('http://example.com/foo/bar.html'));
# "http://example.com/baz.xml?test=123"
Mojo::URL->new('/baz.xml?test=123')
->to_abs(Mojo::URL->new('http://example.com/foo/bar.html'));
# "http://example.com/foo/baz.xml?test=123"
Mojo::URL->new('//example.com/foo/baz.xml?test=123')
->to_abs(Mojo::URL->new('http://example.com/foo/bar.html'));
=head2 to_rel
Expand All @@ -427,10 +436,18 @@ base URL.
Clone absolute URL and turn it into a relative one using C<base> or provided
base URL.
# "foo?bar=baz"
Mojo::URL->new('http://example.com/foo?bar=baz')
# "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

0 comments on commit cb24ea6

Please sign in to comment.