Last active
August 29, 2015 14:23
-
-
Save jberger/b62332a506b364117e37 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# note run notebook server with IO_ASYNC_LOOP=Mojo\n", | |
"# use Mojo::Reactor::IOAsync cannot report the correct running state\n", | |
"use Mojo::Base -strict;\n", | |
"use experimental 'signatures';" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"sub print_async {\n", | |
" my $kernel = $IPerl::current_kernel;\n", | |
" my $msg = $IPerl::current_msg;\n", | |
" my $count = $IPerl::REPL->execution_count;\n", | |
" return sub ($value) {\n", | |
" my $output = $msg->new_reply_to(\n", | |
" msg_type => 'execute_result',\n", | |
" content => {\n", | |
" execution_count => $count,\n", | |
" data => {\n", | |
" 'text/plain' => $value,\n", | |
" },\n", | |
" metadata => {},\n", | |
" }\n", | |
" );\n", | |
" $kernel->send_message( $kernel->iopub, $output );\n", | |
" };\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"0da5a3afd626628dfb8a0eff31c79f85\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"Google" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"use Mojo::UserAgent;\n", | |
"my $ua = Mojo::UserAgent->new->max_redirects(10);\n", | |
"my $print = print_async;\n", | |
"$ua->get('google.com' => sub ($ua, $tx) { my $title = $tx->res->dom->at('title')->text; $print->($title) })" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "IPerl 0.005", | |
"language": "perl", | |
"name": "iperl" | |
}, | |
"language_info": { | |
"file_extension": ".pl", | |
"mimetype": "text/x-perl", | |
"name": "perl", | |
"version": "5.22.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment