21 |
path_session => 1, |
path_session => 1, |
22 |
cookie_session => 'sid', |
cookie_session => 'sid', |
23 |
callback => \&main, |
callback => \&main, |
24 |
|
debug_level => 1, |
25 |
); |
); |
|
$server->debug_level( 2 ); |
|
26 |
|
|
27 |
sub run { |
sub run { |
28 |
$server->loop; |
$server->loop; |
29 |
} |
} |
30 |
|
|
|
my @callbacks; |
|
|
my $callback_count; |
|
|
|
|
|
sub gen_link { |
|
|
my ($text, $code) = @_; |
|
|
$callbacks[$callback_count] = $code; |
|
|
my $out = qq{<a href="?cb=$callback_count">$text</a>}; |
|
|
$callback_count++; |
|
|
return $out; |
|
|
} |
|
|
|
|
|
sub process_links { |
|
|
my $request = shift; |
|
|
my $cb = $request->param('cb'); |
|
|
if (exists $callbacks[$cb]) { |
|
|
$callbacks[$cb]->($request); |
|
|
# delete $callbacks[$cb]; |
|
|
} |
|
|
} |
|
|
|
|
31 |
# This is the main entrypoint. We are looking for one of three things -- a |
# This is the main entrypoint. We are looking for one of three things -- a |
32 |
# pushstream, a sent message, or a request for the main HTML. We delegate each |
# pushstream, a sent message, or a request for the main HTML. We delegate each |
33 |
# of these cases, none of which will return (they all loop forever). |
# of these cases, none of which will return (they all loop forever). |
50 |
send_message($req); |
send_message($req); |
51 |
} |
} |
52 |
|
|
|
if ( $path =~ m/test/ ) { |
|
|
use Data::Dumper; |
|
|
$Data::Dumper::Deparse = 1; |
|
|
|
|
|
my $x = 0; |
|
|
my $continue = 1; |
|
|
my $link1 = gen_link('+' => sub { $x++ }); |
|
|
my $link2 = gen_link('-' => sub { $x-- }); |
|
|
my $out = gen_link('X' => sub { $continue = 0 }); |
|
|
while ( $continue ) { |
|
|
warn "## x = $x ",dump( $req->params ); |
|
|
$req->print("\$x is now: $x"); |
|
|
$req->print($link1, ' ', $link2, ' ', $out); |
|
|
$req->print('<pre>'.Dumper( @callbacks ).'</pre>'); |
|
|
$req->next; |
|
|
process_links($req); |
|
|
} |
|
|
} |
|
|
|
|
53 |
# Otherwise, lets give them page |
# Otherwise, lets give them page |
54 |
send_page($req); |
send_page($req); |
55 |
} |
} |