Skip to content

Instantly share code, notes, and snippets.

@marcusramberg
Created January 12, 2012 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusramberg/1600581 to your computer and use it in GitHub Desktop.
Save marcusramberg/1600581 to your computer and use it in GitHub Desktop.
$self->helper(
url_with => sub {
my $this = shift;
my $args = ref $_[-1] eq 'HASH' ? pop : {};
my $url = @_ ? $this->url_for(@_) : $this->req->url->clone;
my $query = $this->req->url->query->clone;
$url->query($query);
for my $key (keys %$args) {
my $value = $args->{$key};
if (defined($value) and $value ne '') {
$query->param($key => $args->{$key});
}
else {
$query->remove($key);
}
}
return $url;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment