[Bps-public-commit] r15048 - in Prophet/trunk: . lib/Prophet/CLI/Command
jesse at bestpractical.com
jesse at bestpractical.com
Tue Aug 12 07:19:49 EDT 2008
Author: jesse
Date: Tue Aug 12 07:19:48 2008
New Revision: 15048
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/Makefile.PL
Prophet/trunk/lib/Prophet/CLI.pm
Prophet/trunk/lib/Prophet/CLI/Command/Server.pm
Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
Prophet/trunk/lib/Prophet/Server.pm
Log:
r43070 at PC0169 (orig r15040): jesse | 2008-08-12 12:09:39 +0100
- Create branch //local/Prophet/restyserver to //mirror/bps-public/Prophet/branches/restyserver
r43072 at PC0169 (orig r15042): jesse | 2008-08-12 12:10:28 +0100
r43041 at PC0169: jesse | 2008-08-12 01:35:08 +0100
* refactored the resty server to make it possible to deny remote update
* mooseified the resty server
* removed the dep on HTTP::Server::Simple::Bonjour
r43074 at PC0169 (orig r15044): jesse | 2008-08-12 12:11:03 +0100
r43066 at PC0169: jesse | 2008-08-12 12:00:05 +0100
* Term::ReadLine is core
Modified: Prophet/trunk/Makefile.PL
==============================================================================
--- Prophet/trunk/Makefile.PL (original)
+++ Prophet/trunk/Makefile.PL Tue Aug 12 07:19:48 2008
@@ -25,10 +25,6 @@
requires('XML::Atom::SimpleFeed');
features(
- 'Prophet shell' => [
- -default => 1,
- 'Term::ReadLine',
- ],
'Web server' => [
-default => 1,
'HTTP::Server::Simple', # HTTP::Server::Simple::CGI
@@ -58,7 +54,6 @@
'Bonjour support' => [
-default => 0,
'Net::Bonjour',
- 'HTTP::Server::Simple::Bonjour',
],
);
Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI.pm Tue Aug 12 07:19:48 2008
@@ -92,6 +92,14 @@
},
);
+has interactive_shell => (
+ is => 'rw',
+ isa => 'Bool',
+ default => sub { 0}
+);
+
+
+
=head2 _record_cmd
handles the subcommand for a particular type
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Server.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Server.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Server.pm Tue Aug 12 07:19:48 2008
@@ -5,14 +5,20 @@
use Prophet::Server;
sub run {
-
my $self = shift;
+ my $server = $self->_setup_server();
+ $server->run;
+}
+sub _setup_server {
+ my $self = shift;
my $server = Prophet::Server->new( $self->arg('port') || 8080 );
$server->app_handle( $self->app_handle );
- $server->run;
+ return $server;
}
+
+
__PACKAGE__->meta->make_immutable;
no Moose;
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm Tue Aug 12 07:19:48 2008
@@ -31,9 +31,9 @@
local $| = 1;
+ $self->cli->interactive_shell(1);
while (defined(local $_ = $self->readline($self->prompt))) {
next if /^\s*$/;
-
local @ARGV = split ' ', $_;
eval { $self->run_one_command };
warn $@ if $@;
Modified: Prophet/trunk/lib/Prophet/Server.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server.pm (original)
+++ Prophet/trunk/lib/Prophet/Server.pm Tue Aug 12 07:19:48 2008
@@ -1,47 +1,42 @@
package Prophet::Server;
-use warnings;
-use strict;
-use Prophet::App;
-
-BEGIN {
- if (Prophet::App->try_to_require('HTTP::Server::Simple::Bonjour')) {
- our @ISA = 'HTTP::Server::Simple::Bonjour';
- }
-}
-
-use base qw'HTTP::Server::Simple::CGI';
+use Moose;
+extends qw'HTTP::Server::Simple::CGI';
use Prophet::Server::View;
use Params::Validate qw/:all/;
use JSON;
-use Path::Class;
-
-# Support for the bonjour replica type
-our $DB_UUID;
-sub service_name { $DB_UUID }
-sub service_type { '_prophet._tcp' }
-sub app_handle {
- my $self = shift;
- if (@_) {
- $self->{'app_handle'} = shift;
- $DB_UUID = $self->{'app_handle'}->handle->db_uuid;
+has app_handle => ( isa => 'Prophet::App', is => 'rw',
+ handles => [ qw/handle/]
+);
+
+has read_only => ( is => 'rw', isa => 'Bool');
+
+before run => sub {
+ my $self = shift;
+ my $publisher = eval {
+ require Net::Rendezvous::Publish;
+ Net::Rendezvous::Publish->new;
+ };
+ if ($publisher) {
+ $publisher->publish(
+ name => $self->handle->db_uuid,
+ type => '_prophet._tcp',
+ port => $self->port,
+ domain => 'local',
+ );
+ } else {
+ warn
+ "Publisher backend is not available. Install one of the ".
+ "Net::Rendezvous::Publish::Backend modules from CPAN.";
}
- return $self->{'app_handle'};
-}
-
-sub handle { shift->app_handle->handle }
+};
-# we can't moose until we sort out HTTP::Server::Simple with bonjour
-#has app_handle => ( isa => 'Prophet::App', is => 'rw');
-
-sub new {
- my $class = shift;
+before new => sub {
Template::Declare->init(roots => ['Prophet::Server::View']);
- return $class->SUPER::new(@_);
-}
+};
-sub handle_request {
+override handle_request => sub {
my ($self, $cgi) = validate_pos( @_, { isa => 'Prophet::Server'} , { isa => 'CGI' } );
my $http_status;
if ( my $sub = $self->can( 'handle_request_' . lc( $cgi->request_method ) ) ) {
@@ -50,7 +45,7 @@
unless ($http_status) {
$self->_send_404;
}
-}
+};
sub handle_request_get {
my $self = shift;
@@ -60,7 +55,6 @@
if ($p =~ qr{^/+replica/+(.*)$}) {
my $repo_file = $1;
- my $file_obj = file($repo_file);
return undef unless $self->handle->can('read_file');
my $content = $self->handle->read_file($repo_file);
@@ -124,6 +118,9 @@
sub handle_request_post {
my $self = shift;
+
+ return $self->_send_401 if ($self->read_only);
+
my ($cgi) = validate_pos( @_, { isa => 'CGI' } );
my $p = $cgi->path_info;
if ( $p =~ m|^/records/(.*)/(.*)/(.*)| ) {
@@ -174,6 +171,12 @@
return '200';
}
+sub _send_401 {
+ my $self = shift;
+ print "HTTP/1.0 401 READONLY_SERVER\r\n";
+ return '401';
+}
+
sub _send_404 {
my $self = shift;
print "HTTP/1.0 404 ENOFILE\r\n";
More information about the Bps-public-commit
mailing list