--- trunk/lib/Frey/Server.pm 2008/11/05 08:20:50 277 +++ trunk/lib/Frey/Server.pm 2008/11/18 12:02:57 407 @@ -1,8 +1,9 @@ package Frey::Server; use Moose; - +extends 'Frey'; with 'Frey::Web'; +with 'Frey::Config'; use Continuity; #use Continuity::REPL; @@ -11,6 +12,7 @@ #use Carp::REPL; ## XXX it would be nice, but it breaks error reporting too much use Frey::ClassLoader; use Frey::Run; +use Frey::Editor; my @messages; # Global (shared) list of messages my $got_message; # Flag to indicate that there is a new message to display @@ -36,7 +38,7 @@ sub run { my ( $self, $port ) = @_; $server = Continuity->new( - port => $port || 16001, + port => $port || $self->config->{port} || 16001, path_session => 1, cookie_session => 'sid', callback => \&main, @@ -68,25 +70,46 @@ my %params = $req->params; my $html; + sub rest2class { + my $class = shift; + $class =~ s/-/::/; # sigh! + return $class; + } + + eval { my $f; - my $run_regexp = join('|', Frey::Run->execute ); + my $run_regexp = join('|', Frey::Run->runnable ); + my $editor = Frey::Editor->new; - if ( $path =~ m!/Frey[:-]+ObjectBrowser! ) { + if ( + $path =~ m{/Frey[:-]+ObjectBrowser} + ) { $f = Frey::ObjectBrowser->new( fey_class => $params{class} ); $f->request( $req ); - } elsif ( $path =~ m!/Frey[:-]+ObjectDesigner! ) { + } elsif ( + $path =~ m{/Frey[:-]+ObjectDesigner} + ) { $f = Frey::ObjectDesigner->new( fey_class => $params{class} ); $f->request( $req ); - } elsif ( $path =~ m!/Frey[:-]+Introspect! ) { - $f = Frey::Introspect->new( class => $params{class} ); - $req->print( $f->markup ); - undef $f; - } elsif ( $path =~ m!/([^/]+)/($run_regexp)! ) { - warn "# run $1 $2\n"; - $f = Frey::Run->new( class => $1, params => \%params ); + } elsif ( $path =~ $editor->url_regex ) { + $req->print( $editor->command( $path ) ); + system( $editor->command( $path ) ); + return; + } elsif ( + $path =~ m{/([^/]+)/($run_regexp)} + ) { + my $class = rest2class $1; + warn "# run $class $2\n"; + $f = Frey::Run->new( class => $class, params => \%params, 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 }, request_url => $req->request->url ); } else { $f = Frey::Run->new( class => 'Frey::ClassBrowser' ); } @@ -104,7 +127,7 @@ if ( $@ ) { warn $@; $req->conn->send_error( 404 ); # FIXME this should probably be 500, but we can't ship page with it - $req->print( qq{
$@
} );
+		$req->print( qq{
$@
} );
 #		Carp::REPL::repl;
 
 	}