Created
March 10, 2012 05:49
-
-
Save rsimoes/2010440 to your computer and use it in GitHub Desktop.
Proof of concept: Lazy IO variable with AnyEvent, Variable::Magic, Data::Alias, and PadWalker
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
#!/usr/bin/env perl | |
use v5.14; | |
use warnings; | |
use AnyEvent::HTTP "http_get"; | |
use Variable::Magic qw(wizard cast dispell); | |
use Data::Alias "alias"; | |
use PadWalker "peek_my"; | |
sub get_page { | |
my ($uri) = @_; | |
alias my $var = ${ peek_my(1)->{q"$page"} }; | |
my $wiz; | |
my $result = AE::cv; | |
$wiz = wizard get => sub { | |
dispell $var, $wiz; | |
$var = $result->recv; }; | |
cast $var, $wiz; | |
http_get $uri, sub { | |
my ($body) = @_; | |
$result->send($body); }; } | |
my $page; | |
$page = get_page("http://perl.org"); | |
say "Before page load..."; | |
say $page; | |
say "... After page load"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment