Created
November 17, 2010 17:02
-
-
Save draegtun/703651 to your computer and use it in GitHub Desktop.
Expose any Perl object over the web. An interesting little snippet (using Continuity)
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
#!/usr/bin/env perl | |
use 5.012; | |
use warnings; | |
use autobox::Core; | |
use Continuity; | |
Continuity->new( port => 9292 )->loop; | |
sub main { | |
my $request = shift; | |
my $expose = []; # exposed Array object, per user! | |
while (1) { | |
my ($func, @attrs) = $request->uri->as_string->split('/')->tail; | |
$request->print( $expose->$func(@attrs) )->next; | |
} | |
} | |
# to run: perl webapp_continuity.pl | |
# http://localhost:9292/push/1 -> 1 | |
# http://localhost:9292/push/2 -> 12 | |
# http://localhost:9292/push/3 -> 123 | |
# http://localhost:9292/flatten -> 123 | |
# http://localhost:9292/pop -> 3 | |
# http://localhost:9292/shift -> 1 | |
## | |
# see: "Expose any Ruby object over the web. An interesting little snippet" | |
# http://news.ycombinator.com/item?id=1910120 | |
# https://gist.github.com/675667 | |
# also: | |
# https://gist.github.com/703620 (Plack version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment