[Bps-public-commit] r11704 - in Prophet/trunk: . bin lib/Prophet/Test t
jesse at bestpractical.com
jesse at bestpractical.com
Fri Apr 11 22:45:20 EDT 2008
Author: jesse
Date: Fri Apr 11 22:45:17 2008
New Revision: 11704
Added:
Prophet/trunk/lib/Prophet/App.pm
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/bin/generalized_sync_n_merge.t
Prophet/trunk/lib/Prophet/CLI.pm
Prophet/trunk/lib/Prophet/Test.pm
Prophet/trunk/lib/Prophet/Test/Participant.pm
Prophet/trunk/t/export.t
Prophet/trunk/t/resty-server.t
Prophet/trunk/t/validation.t
Log:
r29604 at 31b: jesse | 2008-04-11 17:43:45 -0400
* Factored out an 'App' class
Modified: Prophet/trunk/bin/generalized_sync_n_merge.t
==============================================================================
--- Prophet/trunk/bin/generalized_sync_n_merge.t (original)
+++ Prophet/trunk/bin/generalized_sync_n_merge.t Fri Apr 11 22:45:17 2008
@@ -54,7 +54,7 @@
sub {
warn "==> hi";
my $cli = Prophet::CLI->new();
- my $handle = $cli->handle;
+ my $handle = $cli->app_handle->handle;
my $records = Prophet::Collection->new(
handle => $handle,
type => 'Scratch'
Added: Prophet/trunk/lib/Prophet/App.pm
==============================================================================
--- (empty file)
+++ Prophet/trunk/lib/Prophet/App.pm Fri Apr 11 22:45:17 2008
@@ -0,0 +1,60 @@
+use warnings;
+use strict;
+
+
+package Prophet::App;
+use base qw/Class::Accessor/;
+
+__PACKAGE__->mk_accessors(qw/_handle _resdb_handle/);
+
+sub new {
+ my $self = shift->SUPER::new(@_);
+
+ # Initialize our handle and resolution db handle
+
+ $self->handle;
+ $self->resdb_handle;
+
+ return $self;
+}
+
+=head2 handle
+
+
+=cut
+
+sub handle {
+ my $self = shift;
+ unless ( $self->_handle ) {
+ my $root = $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' );
+ $self->_handle( Prophet::Handle->new( repository => $root ) );
+ }
+ return $self->_handle();
+}
+
+=head2 resdb_handle
+
+=cut
+
+sub resdb_handle {
+ my $self = shift;
+ unless ( $self->_resdb_handle ) {
+ my $root = ( $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' ) ) . "_res";
+ $self->_resdb_handle( Prophet::Handle->new( repository => $root ) );
+ }
+ return $self->_resdb_handle();
+}
+
+=head2 get_handle_for_replica($replica, $db_root)
+
+for a foreign $replica, this returns a Prophet::Handle for local storage that are based in db_root
+
+=cut
+
+sub get_handle_for_replica {
+ my ( $self, $replica, $db_uuid ) = @_;
+ my $root = $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' ) . '/_prophet_replica/' . $replica->uuid;
+ return Prophet::Handle->new( repository => $root, db_uuid => $db_uuid );
+}
+
+1;
Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI.pm Fri Apr 11 22:45:17 2008
@@ -3,11 +3,10 @@
package Prophet::CLI;
use base qw/Class::Accessor/;
-__PACKAGE__->mk_accessors(qw/app_class record_class type uuid _handle _resdb_handle/);
+__PACKAGE__->mk_accessors(qw/app_class record_class type uuid app_handle/);
use Path::Class;
use Prophet;
-use Prophet::Handle;
use Prophet::Record;
use Prophet::Collection;
use Prophet::Replica;
@@ -25,52 +24,13 @@
}
- # Initialize our handle and resolution db handle
-
- $self->handle;
- $self->resdb_handle;
-
+ my $app_class = $self->app_class || 'Prophet::App';
+ $app_class->require();# unless exists $INC{$app_class_path};
+ $self->app_handle($app_class->new);
return $self;
}
-=head2 handle
-
-=cut
-
-sub handle {
- my $self = shift;
- unless ( $self->_handle ) {
- my $root = $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' );
- $self->_handle( Prophet::Handle->new( repository => $root ) );
- }
- return $self->_handle();
-}
-
-=head2 resdb_handle
-
-=cut
-
-sub resdb_handle {
- my $self = shift;
- unless ( $self->_resdb_handle ) {
- my $root = ( $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' ) ) . "_res";
- $self->_resdb_handle( Prophet::Handle->new( repository => $root ) );
- }
- return $self->_resdb_handle();
-}
-
-=head2 get_handle_for_replica($replica, $db_root)
-
-for a foreign $replica, this returns a Prophet::Handle for local storage that are based in db_root
-
-=cut
-
-sub get_handle_for_replica {
- my ( $self, $replica, $db_uuid ) = @_;
- my $root = $ENV{'PROPHET_REPO'} || dir( $ENV{'HOME'}, '.prophet' ) . '/_prophet_replica/' . $replica->uuid;
- return Prophet::Handle->new( repository => $root, db_uuid => $db_uuid );
-}
=head2 _record_cmd
@@ -195,7 +155,7 @@
sub _get_record {
my $self = shift;
return $self->record_class->new(
- { handle => $self->handle,
+ { handle => $self->app_handle->handle,
type => $self->type,
}
);
@@ -220,7 +180,7 @@
}
my $record = $self->_get_record;
$record->collection_class->require;
- my $records = $record->collection_class->new( handle => $self->handle, type => $self->type );
+ my $records = $record->collection_class->new( handle => $self->app_handle->handle, type => $self->type );
$records->matching(
sub {
my $item = shift;
@@ -277,7 +237,7 @@
sub do_push {
my $self = shift;
- my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->handle->repo_path } );
+ my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->app_handle->handle->repo_path } );
my $other = shift @ARGV;
my $source_other = Prophet::Replica->new( { url => $other } );
my $resdb = $source_me->import_resolutions_from_remote_replica( from => $source_other );
@@ -287,14 +247,14 @@
sub do_export {
my $self = shift;
- my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->handle->repo_path } );
+ my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->app_handle->handle->repo_path } );
my $path = $self->args->{'path'};
$source_me->export_to( path => $path );
}
sub do_pull {
my $self = shift;
- my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->handle->repo_path } );
+ my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->app_handle->handle->repo_path } );
my $other = shift @ARGV;
my $source_other = Prophet::Replica->new( { url => $other } );
my $resdb = $source_me->import_resolutions_from_remote_replica( from => $source_other );
@@ -309,7 +269,7 @@
my $opts = $self->args();
require Prophet::Server::REST;
my $server = Prophet::Server::REST->new( $opts->{'port'} || 8080 );
- $server->prophet_handle( $self->handle );
+ $server->prophet_handle( $self->app_handle->handle );
$server->run;
}
@@ -344,7 +304,7 @@
$target->import_changesets(
from => $source,
- resdb => $self->resdb_handle,
+ resdb => $self->app_handle->resdb_handle,
$ENV{'PROPHET_RESOLVER'}
? ( resolver_class => 'Prophet::Resolver::' . $ENV{'PROPHET_RESOLVER'} )
: ( ( $opts->{'prefer'} eq 'to' ? ( resolver_class => 'Prophet::Resolver::AlwaysTarget' ) : () ),
Modified: Prophet/trunk/lib/Prophet/Test.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test.pm (original)
+++ Prophet/trunk/lib/Prophet/Test.pm Fri Apr 11 22:45:17 2008
@@ -211,7 +211,7 @@
sub replica_uuid {
my $self = shift;
my $cli = Prophet::CLI->new();
- return $cli->handle->uuid;
+ return $cli->app_handle->handle->uuid;
}
=head2 replica_merge_tickets
@@ -227,7 +227,7 @@
sub replica_merge_tickets {
my $self = shift;
my $cli = Prophet::CLI->new();
- my $tickets = Prophet::Collection->new( handle => $cli->handle, type => $Prophet::Handle::MERGETICKET_METATYPE );
+ my $tickets = Prophet::Collection->new( handle => $cli->app_handle->handle, type => $Prophet::Handle::MERGETICKET_METATYPE );
$tickets->matching( sub {1} );
return { map { $_->uuid => $_->prop('last-changeset') } @{ $tickets->as_array_ref } };
@@ -235,7 +235,7 @@
sub replica_last_rev {
my $cli = Prophet::CLI->new();
- return $cli->handle->repo_handle->fs->youngest_rev;
+ return $cli->app_handle->handle->repo_handle->fs->youngest_rev;
}
=head2 as_user USERNAME CODEREF
Modified: Prophet/trunk/lib/Prophet/Test/Participant.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test/Participant.pm (original)
+++ Prophet/trunk/lib/Prophet/Test/Participant.pm Fri Apr 11 22:45:17 2008
@@ -140,8 +140,8 @@
my $state;
- my $nodes = Prophet::Collection->new( handle => $cli->handle, type => 'Scratch' );
- my $merges = Prophet::Collection->new( handle => $cli->handle, type => $Prophet::Handle::MERGETICKET_METATYPE );
+ my $nodes = Prophet::Collection->new( handle => $cli->app_handle->handle, type => 'Scratch' );
+ my $merges = Prophet::Collection->new( handle => $cli->app_handle->handle, type => $Prophet::Handle::MERGETICKET_METATYPE );
my $resolutions = Prophet::Collection->new( handle => $cli->resdb_handle, type => '_prophet_resolution' );
$nodes->matching( sub {1} );
Modified: Prophet/trunk/t/export.t
==============================================================================
--- Prophet/trunk/t/export.t (original)
+++ Prophet/trunk/t/export.t Fri Apr 11 22:45:17 2008
@@ -44,7 +44,7 @@
run_ok( 'prophet', [ 'export', '--path', $path ] );
my $cli = Prophet::CLI->new;
- $path = $path->subdir( $cli->handle->db_uuid );
+ $path = $path->subdir( $cli->app_handle->handle->db_uuid );
ok( -d $path, 'found db-uuid root ' . $path );
ok( -e $path->file('replica-uuid'), 'found replica uuid file' );
lives_and {
Modified: Prophet/trunk/t/resty-server.t
==============================================================================
--- Prophet/trunk/t/resty-server.t (original)
+++ Prophet/trunk/t/resty-server.t Fri Apr 11 22:45:17 2008
@@ -14,7 +14,7 @@
my $ua = Test::WWW::Mechanize->new();
my $cli = Prophet::CLI->new();
my $s = Prophet::TestServer->new();
-$s->prophet_handle( $cli->handle );
+$s->prophet_handle( $cli->app_handle->handle );
my $url_root = $s->started_ok("start up my web server");
@@ -25,7 +25,7 @@
$ua->get_ok( url('records.json') );
is( $ua->content, '[]' );
-my $car = Prophet::Record->new( handle => $cli->handle, type => 'Cars' );
+my $car = Prophet::Record->new( handle => $cli->app_handle->handle, type => 'Cars' );
my ($uuid) = $car->create( props => { wheels => 4, windshields => 1 } );
ok( $uuid, "Created record $uuid" );
@@ -56,7 +56,7 @@
ok( 0, "Failed to get the new record's uri" );
}
-my $car2 = Prophet::Record->new( handle => $cli->handle, type => 'Cars' );
+my $car2 = Prophet::Record->new( handle => $cli->app_handle->handle, type => 'Cars' );
$car2->load( uuid => $new_uuid );
is_deeply( $car2->get_props, { wheels => 3, seatbelts => 'sure!' }, "The thing we created remotely worked just great" );
Modified: Prophet/trunk/t/validation.t
==============================================================================
--- Prophet/trunk/t/validation.t (original)
+++ Prophet/trunk/t/validation.t Fri Apr 11 22:45:17 2008
@@ -19,7 +19,7 @@
as_alice {
my $cli = Prophet::CLI->new();
- my $rec = App::Record->new( handle => $cli->handle, type => 'foo' );
+ my $rec = App::Record->new( handle => $cli->app_handle->handle, type => 'foo' );
ok( $rec->create( props => { foo => 'bar', point => '123' } ) );
More information about the Bps-public-commit
mailing list