Skip to content

Instantly share code, notes, and snippets.

@rsimoes
Created March 10, 2012 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsimoes/2010440 to your computer and use it in GitHub Desktop.
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
#!/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