Skip to content

Commit

Permalink
removed url_with method and upgraded url_with helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 13, 2012
1 parent ea0d9c9 commit f65e2d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Changes
@@ -1,8 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.44 2012-01-13 00:00:00
- Added EXPERIMENTAL url_with method to Mojolicious::Controller.
(diegok, marcus, judofyr, sri)
- Added EXPERIMENTAL url_with helper to
Mojolicious::Plugin::DefaultHelpers. (diegok, marcus, judofyr, sri)
- Added EXPERIMENTAL support for removing query parmaters while
merging to query method of Mojo::URL. (marcus, judofyr, sri)
- Removed experimental status from Mojo::IOLoop::Delay.
Expand Down
20 changes: 0 additions & 20 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -590,11 +590,6 @@ sub url_for {
return $url;
}

sub url_with {
my $self = shift;
return $self->url_for(@_)->query($self->req->url->query->clone);
}

sub write {
my ($self, $chunk, $cb) = @_;

Expand Down Expand Up @@ -1026,21 +1021,6 @@ Generate a portable L<Mojo::URL> object with base for a route, path or URL.
# "/myapp/perldoc?foo=bar" if application is deployed under "/myapp"
say $c->url_for('/perldoc')->query(foo => 'bar');
=head2 C<url_with>
my $url = $c->url_with;
my $url = $c->url_with(name => 'sebastian');
my $url = $c->url_with('test', name => 'sebastian');
my $url = $c->url_with('/perldoc');
my $url = $c->url_with('http://mojolicio.us/perldoc');
Does the same as C<url_for>, but inherits query parameters from the current
request. Note that this method is EXPERIMENTAL and might change without
warning!
# Replace one query parameter
say $c->url_with->query([page => 2]);
=head2 C<write>
$c->write;
Expand Down
17 changes: 14 additions & 3 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -9,7 +9,7 @@ sub register {
my ($self, $app) = @_;

# Controller alias helpers
for my $name (qw/app flash param stash session url_for url_with/) {
for my $name (qw/app flash param stash session url_for/) {
$app->helper($name => sub { shift->$name(@_) });
}

Expand Down Expand Up @@ -98,6 +98,14 @@ sub register {
$memorize->{$name}->{content} = $cb->();
}
);

# Add "url_with" helper
$app->helper(
url_with => sub {
my $self = shift;
return $self->url_for(@_)->query($self->req->url->query->clone);
}
);
}

1;
Expand Down Expand Up @@ -239,8 +247,11 @@ Alias for L<Mojolicious::Controller/"url_for">.
%= url_with 'named', controller => 'bar', action => 'baz'
Alias for L<Mojolicious::Controller/"url_with">. Note that this helper is
EXPERIMENTAL and might change without warning!
Does the same as C<url_for>, but inherits query parameters from the current
request. Note that this helper is EXPERIMENTAL and might change without
warning!
%= url_with->query([page => 2])
=head1 METHODS
Expand Down

0 comments on commit f65e2d3

Please sign in to comment.