[Bps-public-commit] r16804 - in Prophet/trunk/lib/Prophet: Server

jesse at bestpractical.com jesse at bestpractical.com
Mon Nov 10 08:42:00 EST 2008


Author: jesse
Date: Mon Nov 10 08:41:59 2008
New Revision: 16804

Modified:
   Prophet/trunk/lib/Prophet/DatabaseSetting.pm
   Prophet/trunk/lib/Prophet/Record.pm
   Prophet/trunk/lib/Prophet/Server.pm
   Prophet/trunk/lib/Prophet/Server/Dispatcher.pm

Log:
* Hacking on the prophet server on the Great Wall of China:


    r51805:  jesse | 2008-11-10 14:54:47 +0800
	* minor tweak to prophet::record to get a handle if you pass in an app::handle
	r51803:  jesse | 2008-11-10 13:48:42 +0800
	* Cleaning up dispatcher rules, prepping for app-specific view templates
	
    r51769:  jesse | 2008-11-10 13:39:19 +0800
	* Refactor the server to allow per-app dispatchers
	

Modified: Prophet/trunk/lib/Prophet/DatabaseSetting.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/DatabaseSetting.pm	(original)
+++ Prophet/trunk/lib/Prophet/DatabaseSetting.pm	Mon Nov 10 08:41:59 2008
@@ -81,7 +81,6 @@
 
     my $entry = from_json($content, { utf8 => 1 });
     return $entry;
-    # XXX TODO do we really want to just get the first one?
 }
 
 __PACKAGE__->meta->make_immutable;

Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm	(original)
+++ Prophet/trunk/lib/Prophet/Record.pm	Mon Nov 10 08:41:59 2008
@@ -25,6 +25,7 @@
 has handle => (
     is       => 'rw',
     required => 1,
+    default => sub { shift->app_handle->handle }
 );
 
 has type => (

Modified: Prophet/trunk/lib/Prophet/Server.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server.pm	(original)
+++ Prophet/trunk/lib/Prophet/Server.pm	Mon Nov 10 08:41:59 2008
@@ -40,7 +40,7 @@
     my $view_class = ref( $self->app_handle ) . "::Server::View";
 
     if ( Prophet::App->try_to_require($view_class) ) {
-        Template::Declare->init( roots => [$view_class] );
+        Template::Declare->init( roots => [$view_class, 'Prophet::Server::View'] );
 
     } else {
         Template::Declare->init( roots => ['Prophet::Server::View'] );
@@ -51,7 +51,15 @@
     my ( $self, $cgi ) = validate_pos( @_, { isa => 'Prophet::Server' }, { isa => 'CGI' } );
     $self->cgi($cgi);
 
-    my $d = Prophet::Server::Dispatcher->new( server => $self );
+     my $dispatcher_class = ref($self->app_handle) . "::Server::Dispatcher";
+     if (!$self->app_handle->try_to_require($dispatcher_class)) {
+         $dispatcher_class = "Prophet::Server::Dispatcher";
+     }
+ 
+ 
+     my $d =$dispatcher_class->new( server => $self );
+
+
     $d->run( $cgi->request_method . "/" . $cgi->path_info, $d )
         || $self->_send_404;
 
@@ -173,6 +181,7 @@
             content      => $content,
         );
     }
+    return undef;
 }
 
 sub load_record {

Modified: Prophet/trunk/lib/Prophet/Server/Dispatcher.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server/Dispatcher.pm	(original)
+++ Prophet/trunk/lib/Prophet/Server/Dispatcher.pm	Mon Nov 10 08:41:59 2008
@@ -28,11 +28,11 @@
         on qr|(.*)/(.*)/(.*)| => sub { shift->server->get_record_prop() };
         on qr|(.*)/(.*).json| => sub { shift->server->get_record() };
         on qr|(.*).json|      => sub { shift->server->get_record_list() };
-        on '^(.*)$'           => sub { shift->server->show_template() };
     };
+
+    on '^(.*)$' => sub { shift->server->show_template() || next_rule; };
 };
 
-on '*' => sub { return undef };
 
 no Moose;
 



More information about the Bps-public-commit mailing list