--- trunk/lib/Frey/Server.pm 2008/11/29 22:02:08 627 +++ trunk/lib/Frey/Server.pm 2008/12/10 14:22:59 790 @@ -6,6 +6,7 @@ use Data::Dump qw/dump/; +use lib 'lib'; use Frey::Run; has 'port' => ( @@ -32,12 +33,14 @@ This is simple dispatcher for our server. Currently it's in flux and documented only in source code. + my $content_type = $self->request( $url, $params ); + =cut sub print { my $self = shift; - warn "# print ",dump( @_ ); - $self->{print}->( @_ ); + warn "# print ", join(' ', map { length $_ } @_ ); + $self->{_print}->( @_ ); } sub request { @@ -45,13 +48,15 @@ if ( my $ref = ref($url) ) { die "url not URI but ", dump( $url ) unless $ref =~ m{^URI}; + } else { $url = URI->new($url); } my $path = $url->path; + my $content_type = 'text/plain'; -# eval { - { + eval { +# { if ( $path =~ m{/reload(.*)} ) { @@ -61,9 +66,9 @@ if ( system($cmd) == 0 ) { my $server = Frey::Server->new; $self->load_config; - Module::Reload->check; +# Module::Reload->check; warn "# reload done"; - $self->print( refresh( $1, 1 ) ); + $self->print( refresh( $1, 0 ) ); return; } else { warn "ERROR: $?"; @@ -85,7 +90,6 @@ return $class; } - my $f; # shared run params @@ -113,18 +117,17 @@ my $class = rest2class $1; warn "# run $path -> $class $2"; $run->{format} = $3 if $3; - $params->{request_url} = $url, $run->{$_} = $params->{$_} foreach keys %$params; - $f = Frey::Run->new( class => $class, params => $run, run => $2, request_url => $url ); + $f = Frey::Run->new( class => $class, params => $run, run => $2 ); } elsif ( $path =~ m{/([^/]+)/?$} ) { my $class = rest2class $1; warn "# introspect $class"; $run->{class} ||= $class; - $f = Frey::Run->new( class => 'Frey::Introspect', params => $run, request_url => $url ); + $f = Frey::Run->new( class => 'Frey::Introspect', params => $run ); } else { - $f = Frey::Run->new( class => 'Frey::ClassBrowser', params => $run, request_url => $url ); + $f = Frey::Run->new( class => 'Frey::ClassBrowser', params => $run ); } if ( $f ) { @@ -141,6 +144,7 @@ confess "# can't call request on nothing!"; } + $content_type = $f->content_type; }; if ( $@ ) { @@ -150,12 +154,13 @@ # Carp::REPL::repl; } + return $content_type; } sub refresh { my ( $url, $time ) = @_; $url ||= '/'; - $time ||= 1; + $time ||= 0; warn "# refresh $url"; qq|