4 |
use warnings; |
use warnings; |
5 |
|
|
6 |
use Continuity; |
use Continuity; |
7 |
use Continuity::REPL; |
#use Continuity::REPL; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
10 |
use base 'Frey'; |
use base 'Frey'; |
15 |
|
|
16 |
use vars qw( $repl $server ); |
use vars qw( $repl $server ); |
17 |
|
|
18 |
sub run { |
#$repl = Continuity::REPL->new; |
19 |
$repl = Continuity::REPL->new; |
$server = Continuity->new( |
20 |
$server = Continuity->new( |
port => 16001, |
21 |
port => 16001, |
path_session => 1, |
22 |
path_session => 1, |
cookie_session => 'sid', |
23 |
cookie_session => 'sid', |
callback => \&main, |
24 |
callback => \&main, |
debug_level => 1, |
25 |
); |
); |
|
$server->debug_level( 2 ); |
|
26 |
|
|
27 |
|
sub run { |
28 |
$server->loop; |
$server->loop; |
29 |
} |
} |
30 |
|
|
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). |
34 |
sub main { |
sub main { |
35 |
my ($req) = @_; |
my ($req) = @_; |
36 |
|
|
37 |
my $path = $req->request->url->path; |
my $path = $req->request->url->path; |
38 |
warn "REQUEST: $path\n"; |
warn "REQUEST: $path\n"; |
39 |
|
|
40 |
warn $req->request->header('User_Agent'); |
warn $req->request->header('User_Agent'); |
41 |
#warn dump( $req ); |
#warn dump( $req ); |
42 |
|
|
43 |
# If this is a request for the pushtream, then give them that |
# If this is a request for the pushtream, then give them that |
44 |
if($path =~ /pushstream/) { |
if($path =~ /pushstream/) { |
45 |
pushstream($req); |
pushstream($req); |
46 |
} |
} |
47 |
|
|
48 |
# If they are sending us a message, we give them a thread for that too |
# If they are sending us a message, we give them a thread for that too |
49 |
if($path =~ /sendmessage/) { |
if($path =~ /sendmessage/) { |
50 |
send_message($req); |
send_message($req); |
51 |
} |
} |
52 |
|
|
53 |
# Otherwise, lets give them page |
# Otherwise, lets give them page |
54 |
send_page($req); |
send_page($req); |
55 |
} |
} |
56 |
|
|
57 |
# Here we accept a connection to the browser, and keep it open. Meanwhile we |
# Here we accept a connection to the browser, and keep it open. Meanwhile we |
100 |
warn "param = ",dump($req->param); |
warn "param = ",dump($req->param); |
101 |
my $path = $req->request->url->path; |
my $path = $req->request->url->path; |
102 |
|
|
103 |
|
my $html; |
104 |
|
|
105 |
if ( $path =~ m/::/ ) { |
if ( $path =~ m/::/ ) { |
106 |
my ( undef, $module, $method ) = split(m!/!, $path, 3); |
my ( undef, $module, $method ) = split(m!/!, $path, 3); |
107 |
|
|
108 |
if ( ! defined( $templates->{$module} ) ) { |
if ( ! defined( $templates->{$module} ) ) { |
109 |
$req->conn->send_status_line( 404, "$module" ); |
$req->conn->send_status_line( 404, "$module" ); |
110 |
$req->print("Package $module not found"); |
$html = "Package $module not found"; |
111 |
|
} elsif ( ! $method ) { |
112 |
|
$html = Frey::HTML->page( 'package-methods', $req, $module ); |
113 |
} elsif ( grep(/^\Q$method\E$/, @{ $templates->{$module} }) ) { |
} elsif ( grep(/^\Q$method\E$/, @{ $templates->{$module} }) ) { |
114 |
$req->print( Frey::HTML->page( $method, $req ) ); |
$html = Frey::HTML->page( $method, $req ); |
115 |
} else { |
} else { |
116 |
$req->conn->send_status_line( 404, "$module $method" ); |
$req->conn->send_status_line( 404, "$module $method" ); |
117 |
$req->print("Package $module doesn't have $method"); |
$html = "Package $module doesn't have $method"; |
118 |
} |
} |
119 |
} else { |
} else { |
120 |
my $html = Frey::HTML->page( 'status' ); |
warn "fallback to status page\n"; |
121 |
$req->print( $html ); |
$html = Frey::HTML->page( 'status' ); |
|
warn ">> ",length( $html ), " bytes\n"; |
|
122 |
} |
} |
123 |
|
|
124 |
|
$req->print( $html ); |
125 |
|
warn ">> ",length( $html ), " bytes\n"; |
126 |
$req->next; |
$req->next; |
|
Module::Refresh->refresh; |
|
127 |
} |
} |
128 |
} |
} |
129 |
|
|