1 |
dpavlin |
627 |
package Frey::Server::Continuity; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use Continuity; |
7 |
|
|
#use Continuity::REPL; |
8 |
|
|
#use Carp::REPL; ## XXX it would be nice, but it breaks error reporting too much |
9 |
|
|
|
10 |
|
|
#use vars qw( $repl $server ); |
11 |
|
|
#$repl = Continuity::REPL->new; |
12 |
|
|
|
13 |
|
|
use Frey::Server; |
14 |
|
|
use Data::Dump qw/dump/; |
15 |
|
|
|
16 |
|
|
=head1 NAME |
17 |
|
|
|
18 |
|
|
Frey::Server - Continuity based server for Frey |
19 |
|
|
|
20 |
|
|
=head2 DESCRIPTION |
21 |
|
|
|
22 |
|
|
This is one of pissible server implementations for Frey. In it's current stage, it's also most complete one. |
23 |
|
|
|
24 |
|
|
=head2 run |
25 |
|
|
|
26 |
|
|
$o->run( $optional_port ); |
27 |
|
|
|
28 |
|
|
=cut |
29 |
|
|
|
30 |
|
|
our $server; |
31 |
|
|
our $continuity; |
32 |
|
|
|
33 |
|
|
sub run { |
34 |
|
|
my ( $self ) = @_; |
35 |
|
|
|
36 |
|
|
$server = new Frey::Server->new; |
37 |
|
|
|
38 |
|
|
$continuity = Continuity->new( |
39 |
|
|
port => $server->port, |
40 |
|
|
path_session => 1, |
41 |
|
|
cookie_session => 'sid', |
42 |
|
|
callback => \&callback, |
43 |
|
|
debug_level => 2, |
44 |
|
|
staticp => sub { |
45 |
|
|
$_[0]->url =~ m{^/+(static|var).*\.(jpg|jpeg|gif|png|css|ico|js|html?|xml|json|ya?ml)(\?.*)?$} |
46 |
|
|
}, |
47 |
|
|
); |
48 |
|
|
$Module::Reload::Debug = 1; # auto if debug_level > 1 |
49 |
|
|
Frey::ClassLoader->new->load_all_classes(); |
50 |
|
|
Frey::Editor->new->switch_screen if $ENV{FREY_SWITCH_SCREEN}; |
51 |
|
|
$continuity->loop; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
sub callback { |
55 |
|
|
my ($req) = @_; |
56 |
|
|
|
57 |
|
|
# $req->send_headers("X-Frey-VERSION: $Frey::VERSION"); |
58 |
|
|
|
59 |
|
|
$server->{print} = sub { |
60 |
|
|
$req->print( @_ ); |
61 |
|
|
}; |
62 |
|
|
|
63 |
|
|
warn dump( $req->params ); |
64 |
|
|
|
65 |
|
|
my %p = $req->params; |
66 |
|
|
warn "# params: ",dump( %p ); |
67 |
|
|
|
68 |
|
|
$server->request( $req->request->url, \%p ); |
69 |
|
|
|
70 |
|
|
if ( $req->conn ) { |
71 |
|
|
$req->print( "\r\n" ); # flush |
72 |
|
|
$req->conn->close; |
73 |
|
|
warn "## close connection: $@"; |
74 |
|
|
} |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
1; |