--- trunk/lib/Frey/Server.pm 2008/11/27 22:29:01 571 +++ trunk/lib/Frey/Server.pm 2008/11/28 13:16:47 581 @@ -68,33 +68,20 @@ eval { - sub refresh { - my ( $url, $time ) = @_; - $url ||= '/'; - $time ||= 1; - warn "# refresh $url"; - qq| - -
- - - - Refresh $url in $time sec - - - \n\r\n\r - |; # XXX newlines at end are important to flush content to browser - } - if ( $path =~ m{/reload(.*)} ) { $ENV{FREY_NO_LOG} = 1; my $cmd = "perl -c $0"; warn "# check config with $cmd"; if ( system($cmd) == 0 ) { - Frey::Server->new->load_config; + $req->print( "\r\n" ); + my $server = Frey::Server->new; + $server->load_config; + $req->print( "\r\n" ); Module::Reload->check; + $req->print( "\r\n" ); $req->print( refresh( $1, 1 ) ); + $req->print( "\r\n" ); warn "# reload done"; return; } else { @@ -106,6 +93,7 @@ # FIXME do we need some kind of check here for production? :-) # ./bin/dev.sh will restart us during development $req->print( refresh( $1, 2 ) ); + $req->print( "\r\n" ); exit; } @@ -146,7 +134,7 @@ system( $editor->command( $path ) ); return; } elsif ( - $path =~ m{/([^/]+)/(as_\w+)/?([^/]+)?} + $path =~ m{/([^/]+)/(\w*as_\w+)/?([^/]+)?} ) { my $class = rest2class $1; warn "# run $path -> $class $2"; @@ -167,14 +155,13 @@ if ( $f ) { $f->clean_status; $f->add_status( { request => $req } ); - warn "## status ", dump( map { keys %$_ } $f->status ); - my $html = $f->html; - die "no html output" unless $html; - warn "## html ",length($html)," bytes"; - eval { + $f->status_parts; + if ( my $html = $f->html ) { + warn "## html ",length($html)," bytes"; $req->print( $html ); - }; - die "can't send to wire: $@" if $@; + } else { + $req->print( qq|no output from $f\r\n\r\n| ); + } } else { warn "# can't call request on nothing!"; } @@ -182,9 +169,9 @@ }; if ( $@ ) { - warn $@; - $req->conn->send_error( 404 ); # FIXME this should probably be 500, but we can't ship page with it - $req->print( qq{
$@} ); + warn "SERVER ERROR: $@"; +# $req->conn->send_error( 404 ); # FIXME this should probably be 500, but we can't ship page with it + $req->print( qq{$@\r\n\r\n} ); # Carp::REPL::repl; } @@ -241,4 +228,22 @@ } } +sub refresh { + my ( $url, $time ) = @_; + $url ||= '/'; + $time ||= 1; + warn "# refresh $url"; + qq| + + + + + + Refresh $url in $time sec + + + \n\r\n\r + |; # XXX newlines at end are important to flush content to browser +} + 1;