Created
September 9, 2013 14:57
-
-
Save gideondsouza/6496750 to your computer and use it in GitHub Desktop.
using LWP::Protocol::PSGI with dancer2
This file contains hidden or 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
use LWP::UserAgent; | |
use LWP::Protocol::PSGI; | |
# can be Mojolicious, Catalyst ... any PSGI application | |
my $psgi_app = do { | |
use Dancer;#ATTENTION: changing this to Dancer2 makes this sample NOT WORK. | |
setting apphandler => 'PSGI'; | |
get '/search' => sub { | |
return 'googling ' . params->{q}; | |
}; | |
dance; | |
}; | |
# Register the $psgi_app to handle all LWP requests | |
LWP::Protocol::PSGI->register($psgi_app); | |
# can hijack any code or module that uses LWP::UserAgent underneath, with no changes | |
my $ua = LWP::UserAgent->new; | |
my $res = $ua->get("http://www.google.com/search?q=bar"); | |
print $res->content; # "googling bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment