--- trunk/lib/Frey/Server.pm 2008/11/28 13:16:47 581 +++ trunk/lib/Frey/Server.pm 2008/11/29 17:48:54 625 @@ -2,7 +2,6 @@ use Moose; extends 'Frey'; -with 'Frey::Web'; with 'Frey::Config'; use Continuity; @@ -35,10 +34,16 @@ =cut +our $editor = Frey::Editor->new; +our $port; + sub run { - my ( $self, $port ) = @_; + my ( $self ) = @_; + + $port = $ENV{FREY_PORT} || $self->config->{port} || 16001; + $server = Continuity->new( - port => $port || $self->config->{port} || 16001, + port => $port, path_session => 1, cookie_session => 'sid', callback => \&main, @@ -49,6 +54,7 @@ ); $Module::Reload::Debug = 1; # auto if debug_level > 1 Frey::ClassLoader->new->load_all_classes(); + $editor->switch_screen if $ENV{FREY_SWITCH_SCREEN}; $server->loop; } @@ -66,7 +72,8 @@ my $path = $req->request->url->path; - eval { +# eval { + { if ( $path =~ m{/reload(.*)} ) { @@ -111,12 +118,10 @@ my $f; - my $editor = Frey::Editor->new; - # shared run params my $run = { request_url => $req->request->url, - debug => 1, +# debug => 1, }; if ( @@ -131,7 +136,6 @@ $f->request( $req ); } elsif ( $path =~ $editor->url_regex ) { $req->print( $editor->command( $path ) ); - system( $editor->command( $path ) ); return; } elsif ( $path =~ m{/([^/]+)/(\w*as_\w+)/?([^/]+)?} @@ -141,15 +145,17 @@ $run->{format} = $3 if $3; $params{request_url} = $req->request->url; $req->print( "\r\n\r\n" ); # send something to browser so we don't time-out - $f = Frey::Run->new( class => $class, params => \%params, run => $2, %$run ); + $run->{$_} = $params{$_} foreach keys %params; + $f = Frey::Run->new( class => $class, params => $run, run => $2, request_url => $req->request->url ); } elsif ( $path =~ m{/([^/]+)/?$} ) { my $class = rest2class $1; warn "# introspect $class"; - $f = Frey::Run->new( class => 'Frey::Introspect', params => { class => $class }, %$run ); + $run->{class} ||= $class; + $f = Frey::Run->new( class => 'Frey::Introspect', params => $run, request_url => $req->request->url ); } else { - $f = Frey::Run->new( class => 'Frey::ClassBrowser', %$run ); + $f = Frey::Run->new( class => 'Frey::ClassBrowser', params => $run, request_url => $req->request->url ); } if ( $f ) { @@ -160,10 +166,10 @@ warn "## html ",length($html)," bytes"; $req->print( $html ); } else { - $req->print( qq|
no output from $f
\r\n\r\n| ); + confess "no output from $f"; } } else { - warn "# can't call request on nothing!"; + confess "# can't call request on nothing!"; } }; @@ -186,6 +192,7 @@ } if ( $req->conn ) { + $req->print( "\r\n" ); # flush $req->conn->close; warn "## close connection: $@"; }