5 |
|
|
6 |
use Continuity; |
use Continuity; |
7 |
#use Continuity::REPL; |
#use Continuity::REPL; |
8 |
|
use Continuity::Widget::DomNode; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
|
|
11 |
use base 'Frey'; |
use base 'Frey'; |
12 |
use Frey::HTML; |
use Frey::HTML; |
13 |
|
use Frey::ObjectBrowser; |
14 |
|
|
15 |
my @messages; # Global (shared) list of messages |
my @messages; # Global (shared) list of messages |
16 |
my $got_message; # Flag to indicate that there is a new message to display |
my $got_message; # Flag to indicate that there is a new message to display |
23 |
path_session => 1, |
path_session => 1, |
24 |
cookie_session => 'sid', |
cookie_session => 'sid', |
25 |
callback => \&main, |
callback => \&main, |
26 |
|
debug_level => 1, |
27 |
|
staticp => sub { $_[0]->url =~ m/\.(jpg|jpeg|gif|png|css|ico|js|html?)$/ }, |
28 |
); |
); |
|
$server->debug_level( 2 ); |
|
29 |
|
|
30 |
sub run { |
sub run { |
31 |
$server->loop; |
$server->loop; |
32 |
} |
} |
33 |
|
|
|
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]; |
|
|
} |
|
|
} |
|
|
|
|
34 |
# 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 |
35 |
# 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 |
36 |
# of these cases, none of which will return (they all loop forever). |
# of these cases, none of which will return (they all loop forever). |
43 |
warn $req->request->header('User_Agent'); |
warn $req->request->header('User_Agent'); |
44 |
#warn dump( $req ); |
#warn dump( $req ); |
45 |
|
|
46 |
|
if ( $path =~ m!/~/([^/]+)(?:/([^/]*))?! ) { |
47 |
|
my $f = Frey::Introspect->new( package => $1 ); |
48 |
|
$f->html( $req ); |
49 |
|
} |
50 |
|
|
51 |
# If this is a request for the pushtream, then give them that |
# If this is a request for the pushtream, then give them that |
52 |
if($path =~ /pushstream/) { |
if($path =~ /pushstream/) { |
53 |
pushstream($req); |
pushstream($req); |
58 |
send_message($req); |
send_message($req); |
59 |
} |
} |
60 |
|
|
61 |
if ( $path =~ m/test/ ) { |
if($path =~ m!^/ob!) { |
62 |
use Data::Dumper; |
Frey::ObjectBrowser->new( req => $req )->html; |
|
$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); |
|
|
} |
|
63 |
} |
} |
64 |
|
|
65 |
# Otherwise, lets give them page |
# Otherwise, lets give them page |
121 |
$req->conn->send_status_line( 404, "$module" ); |
$req->conn->send_status_line( 404, "$module" ); |
122 |
$html = "Package $module not found"; |
$html = "Package $module not found"; |
123 |
} elsif ( ! $method ) { |
} elsif ( ! $method ) { |
124 |
$html = Frey::HTML->page( 'package-methods', $req, $module ); |
$html = Frey::HTML->page( 'package-templates', $req, $module ); |
125 |
} elsif ( grep(/^\Q$method\E$/, @{ $templates->{$module} }) ) { |
} elsif ( grep(/^\Q$method\E$/, @{ $templates->{$module} }) ) { |
126 |
$html = Frey::HTML->page( $method, $req ); |
$html = Frey::HTML->page( $method, $req ); |
127 |
} else { |
} else { |