Created
January 12, 2012 16:32
-
-
Save diegok/1601462 to your computer and use it in GitHub Desktop.
Example code for url_with proposal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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