Skip to content

Instantly share code, notes, and snippets.

@diegok
Created January 12, 2012 16:32
Show Gist options
  • Save diegok/1601462 to your computer and use it in GitHub Desktop.
Save diegok/1601462 to your computer and use it in GitHub Desktop.
Example code for url_with proposal
$self->helper(
url_with => sub {
my $this = shift;
my $url = $this->req->url->clone;
return $url unless @_;
my $query = ref $_[-1] eq 'HASH'
|| ( ref $_[-1] eq 'ARRAY' and not @{$_[-1]} % 2 )
? pop : [];
if ( @_ && ref $_[0] eq 'ARRAY' ) {
my $current_query = $url->query->clone;
$url = $this->url_for(@{ shift() });
$url->query($current_query);
}
elsif ( my $path = shift ) {
$url->path($path);
}
$url->query($query);
return $url;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment