[Bps-public-commit] r15314 - in Prophet/trunk: . lib/Prophet lib/Prophet/CLI/Command lib/Prophet/Replica lib/Prophet/Replica/SVN lib/Prophet/Replica/svn
jesse at bestpractical.com
jesse at bestpractical.com
Wed Aug 20 23:28:26 EDT 2008
Author: jesse
Date: Wed Aug 20 23:28:26 2008
New Revision: 15314
Added:
Prophet/trunk/lib/Prophet/Replica/file.pm
Prophet/trunk/lib/Prophet/Replica/http.pm
Prophet/trunk/lib/Prophet/Replica/prophet.pm
- copied, changed from r15062, /Prophet/trunk/lib/Prophet/Replica/Native.pm
Prophet/trunk/lib/Prophet/Replica/svn/
- copied from r13802, /Prophet/trunk/lib/Prophet/Replica/SVN/
Prophet/trunk/lib/Prophet/Replica/svn.pm
- copied, changed from r15062, /Prophet/trunk/lib/Prophet/Replica/SVN.pm
Removed:
Prophet/trunk/lib/Prophet/Replica/Native.pm
Prophet/trunk/lib/Prophet/Replica/SVN/
Prophet/trunk/lib/Prophet/Replica/SVN.pm
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/App.pm
Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm
Prophet/trunk/lib/Prophet/Config.pm
Prophet/trunk/lib/Prophet/Replica.pm
Prophet/trunk/lib/Prophet/Replica/svn/ReplayEditor.pm
Prophet/trunk/lib/Prophet/Replica/svn/Util.pm
Prophet/trunk/t/config.t
Prophet/trunk/t/export.t
Log:
r43734 at jesse-vincents-macbook-air: jesse | 2008-08-20 09:47:19 -0400
- Create branch delay-load
r43743 at jesse-vincents-macbook-air: jesse | 2008-08-20 09:51:45 -0400
checkpoint
r43744 at jesse-vincents-macbook-air: jesse | 2008-08-20 09:52:42 -0400
checkpont
r43761 at jesse-vincents-macbook-air: jesse | 2008-08-20 23:24:56 -0400
* Switch replica loading code to use the URI scheme as the class name so we don't need to search
Modified: Prophet/trunk/lib/Prophet/App.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/App.pm (original)
+++ Prophet/trunk/lib/Prophet/App.pm Wed Aug 20 23:28:26 2008
@@ -11,7 +11,7 @@
my $self = shift;
my $root = $ENV{'PROPHET_REPO'} || dir($ENV{'HOME'}, '.prophet');
my $type = $self->default_replica_type;
- return Prophet::Replica->new({ url => $type.':file://' . $root });
+ return Prophet::Replica->new({ url => $type.':file://' . $root, app_handle => $self});
},
);
@@ -47,23 +47,6 @@
=cut
-sub BUILD {
- my $self = shift;
- $self->_load_replica_types();
-}
-
-sub _load_replica_types {
- my $self = shift;
- my $replica_class = blessed($self)."::Replica";
- my $except = "\Q$replica_class\E::.*::";
- Module::Pluggable->import( search_path => $replica_class, sub_name => 'app_replica_types', require => 0, except => qr/$except/);
- for my $package ( $self->app_replica_types) {
- $self->require($package);
- next unless $package->can('scheme');
- Prophet::Replica->register_replica_scheme(scheme => $package->scheme, class => $package)
- }
-}
-
sub default_replica_type {
my $self = shift;
return $ENV{'PROPHET_REPLICA_TYPE'} || DEFAULT_REPLICA_TYPE;
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm Wed Aug 20 23:28:26 2008
@@ -14,11 +14,13 @@
my $source = Prophet::Replica->new(
url => $self->arg('from'),
+ app_handle => $self->app_handle,
_alt_urls => \@alt_from,
);
my $target = Prophet::Replica->new(
url => $self->arg('to'),
+ app_handle => $self->app_handle,
_alt_urls => \@alt_to,
);
Modified: Prophet/trunk/lib/Prophet/Config.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Config.pm (original)
+++ Prophet/trunk/lib/Prophet/Config.pm Wed Aug 20 23:28:26 2008
@@ -21,7 +21,7 @@
is => 'rw',
isa => 'HashRef',
lazy => 0,
- default => sub { shift->load_from_files },
+ default => sub {shift->load_from_files;},
provides => {
get => 'get',
set => 'set',
@@ -35,8 +35,8 @@
sub app_config_file {
my $self = shift;
- $ENV{'PROPHET_APP_CONFIG'} || file( $self->app_handle->handle->fs_root => "prophetrc" )
+ $ENV{'PROPHET_APP_CONFIG'} || file( $self->app_handle->handle->fs_root => "prophetrc" ) ;
}
#my $singleton;
@@ -46,7 +46,6 @@
my $self = shift;
my @config = @_;
@config = grep { -f $_ } $self->app_config_file if !@config;
-
my $config = {};
for my $file (@config) {
Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica.pm Wed Aug 20 23:28:26 2008
@@ -41,28 +41,18 @@
default => sub { [] },
);
-use constant state_db_uuid => 'state';
-use Module::Pluggable search_path => 'Prophet::Replica', sub_name => 'core_replica_types', require => 0, except => qr/Prophet::Replica::(.*)::/;
-use Prophet::App;
-
-our $REPLICA_TYPE_MAP = {};
-our $MERGETICKET_METATYPE = '_merge_tickets';
-for ( __PACKAGE__->core_replica_types) {
-Prophet::App->require($_) or die $@; # Require here, rather than with the autorequire from Module::Pluggable as that goes too far
+has app_handle => (
+ is => 'ro',
+ isa => 'Prophet::App',
+ weak_ref => 1
+);
- # and tries to load Prophet::Replica::SVN::ReplayEditor;
- __PACKAGE__->register_replica_scheme(scheme => $_->scheme, class => $_)
-}
- # register some aliases
-__PACKAGE__->register_replica_scheme(%{ $REPLICA_TYPE_MAP->{prophet} }, scheme => 'file');
+use constant state_db_uuid => 'state';
+use Prophet::App;
-__PACKAGE__->register_replica_scheme(
- %{ $REPLICA_TYPE_MAP->{prophet} },
- scheme => 'http',
- keep_scheme => 1,
-);
+our $MERGETICKET_METATYPE = '_merge_tickets';
=head1 NAME
@@ -89,34 +79,20 @@
my $class = shift;
my %args = @_ == 1 ? %{ $_[0] } : @_;
- my ($new_class, $scheme, $url) = $class->_url_to_replica_class($args{url});
+ my ($new_class, $scheme, $url) = $class->_url_to_replica_class(%args);
if (!$new_class) {
- $class->log_fatal("$scheme isn't a replica type I know how to handle. (The Replica URL given was $args{url}). I can handle the following replica types: " . join(', ', sort keys %$REPLICA_TYPE_MAP) . ", and possibly more)");
+ $class->log_fatal("$scheme isn't a replica type I know how to handle. (The Replica URL given was $args{url}).");
}
- return $orig->($class, %args) if $class eq $new_class;
-
- Prophet::App->require($new_class);
- return $new_class->new(%args);
+ if ( $class eq $new_class) {
+ return $orig->($class, %args)
+ } else {
+ Prophet::App->require($new_class);
+ return $new_class->new(%args);
+ }
};
-=head2 register_replica_scheme { class=> Some::Perl::Class, scheme => 'scheme:' }
-
-B<Class Method>. Register a URI scheme C<scheme> to point to a replica object of type C<class>.
-
-=cut
-
-sub register_replica_scheme {
- my $class = shift;
- my %args = validate(@_, { class => 1, scheme => 1, keep_scheme => 0 });
-
- $Prophet::Replica::REPLICA_TYPE_MAP->{$args{'scheme'}} = {
- class => $args{'class'},
- keep_scheme => $args{'keep_scheme'},
- };
-}
-
=head2 _url_to_replica_class
Returns the replica class for the given url.
@@ -125,14 +101,17 @@
sub _url_to_replica_class {
my $self = shift;
- my $url = shift;
-
- my ($scheme, $real_url) = $url =~ /^([^:]*):(.*)$/;
-
- my $type_map = $Prophet::Replica::REPLICA_TYPE_MAP->{$scheme};
- $real_url = $url if $type_map->{keep_scheme};
-
- return ($type_map->{class}, $scheme, $real_url);
+ my %args = (@_);
+ my $url = $args{'url'};
+ my ( $scheme, $real_url ) = $url =~ /^([^:]*):(.*)$/;
+
+ for my $class (
+ ref( $args{app_handle} ) . "::Replica::" . $scheme,
+ "Prophet::Replica::".$scheme ) {
+ Prophet::App->try_to_require($class) || next;
+ return ( $class, $scheme, $real_url );
+ }
+ return undef;
}
sub import_changesets {
Added: Prophet/trunk/lib/Prophet/Replica/file.pm
==============================================================================
--- (empty file)
+++ Prophet/trunk/lib/Prophet/Replica/file.pm Wed Aug 20 23:28:26 2008
@@ -0,0 +1,5 @@
+package Prophet::Replica::file;
+use base 'Prophet::Replica::prophet';
+sub scheme { 'file'}
+
+1;
Added: Prophet/trunk/lib/Prophet/Replica/http.pm
==============================================================================
--- (empty file)
+++ Prophet/trunk/lib/Prophet/Replica/http.pm Wed Aug 20 23:28:26 2008
@@ -0,0 +1,5 @@
+package Prophet::Replica::http;
+use base 'Prophet::Replica::prophet';
+sub scheme { 'http'}
+
+1;
Copied: Prophet/trunk/lib/Prophet/Replica/prophet.pm (from r15062, /Prophet/trunk/lib/Prophet/Replica/Native.pm)
==============================================================================
--- /Prophet/trunk/lib/Prophet/Replica/Native.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica/prophet.pm Wed Aug 20 23:28:26 2008
@@ -1,4 +1,4 @@
-package Prophet::Replica::Native;
+package Prophet::Replica::prophet;
use Moose;
extends 'Prophet::Replica';
use Params::Validate qw(:all);
Copied: Prophet/trunk/lib/Prophet/Replica/svn.pm (from r15062, /Prophet/trunk/lib/Prophet/Replica/SVN.pm)
==============================================================================
--- /Prophet/trunk/lib/Prophet/Replica/SVN.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica/svn.pm Wed Aug 20 23:28:26 2008
@@ -1,4 +1,4 @@
-package Prophet::Replica::SVN;
+package Prophet::Replica::svn;
use Moose;
extends 'Prophet::Replica';
use Params::Validate qw(:all);
@@ -13,9 +13,9 @@
lazy => 1,
default => sub {
my $self = shift;
- require Prophet::Replica::SVN::Util;
- my ( $baton, $ref ) = SVN::Core::auth_open_helper( Prophet::Replica::SVN::Util->get_auth_providers );
- my $config = Prophet::Replica::SVN::Util->svnconfig;
+ require Prophet::Replica::svn::Util;
+ my ( $baton, $ref ) = SVN::Core::auth_open_helper( Prophet::Replica::svn::Util->get_auth_providers );
+ my $config = Prophet::Replica::svn::Util->svnconfig;
return SVN::Ra->new(url => $self->url, config => $config, auth => $baton, pool => $self->_pool);
},
);
@@ -132,8 +132,8 @@
my $self = shift;
my $rev = shift;
- require Prophet::Replica::SVN::ReplayEditor;
- my $editor = Prophet::Replica::SVN::ReplayEditor->new( _debug => 0 );
+ require Prophet::Replica::svn::ReplayEditor;
+ my $editor = Prophet::Replica::svn::ReplayEditor->new( _debug => 0 );
my $pool = SVN::Pool->new_default;
# This horrible hack is here because I have no idea how to pass custom variables into the editor
Modified: Prophet/trunk/lib/Prophet/Replica/svn/ReplayEditor.pm
==============================================================================
--- /Prophet/trunk/lib/Prophet/Replica/SVN/ReplayEditor.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica/svn/ReplayEditor.pm Wed Aug 20 23:28:26 2008
@@ -1,19 +1,19 @@
use warnings;
use strict;
-package Prophet::Replica::SVN::ReplayEditor;
+package Prophet::Replica::svn::ReplayEditor;
use SVN::Delta;
use base qw/SVN::Delta::Editor/;
=head1 NAME
-Prophet::Replica::SVN::ReplayEditor
+Prophet::Replica::svn::ReplayEditor
=head1 DESCRIPTION
This class encapsulates a Subversion "replay" editor. Prophet's
-Subversion synchronization client (L<Prophet::Replica::SVN>)
+Subversion synchronization client (L<Prophet::Replica::svn>)
uses it to turn a set of subversion
deltas into a set of L<Prophet::ChangeSet> objects.
Modified: Prophet/trunk/lib/Prophet/Replica/svn/Util.pm
==============================================================================
--- /Prophet/trunk/lib/Prophet/Replica/SVN/Util.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica/svn/Util.pm Wed Aug 20 23:28:26 2008
@@ -1,5 +1,5 @@
# XXX CARGO CULTED FROM SVK::Util;
-package Prophet::Replica::SVN::Util;
+package Prophet::Replica::svn::Util;
use Moose;
use MooseX::ClassAttribute;
@@ -9,7 +9,7 @@
=head1 NAME
-Prophet::Replica::SVN
+Prophet::Replica::svn::Util
=head1 DESCRIPTION
Modified: Prophet/trunk/t/config.t
==============================================================================
--- Prophet/trunk/t/config.t (original)
+++ Prophet/trunk/t/config.t Wed Aug 20 23:28:26 2008
@@ -11,6 +11,7 @@
# Test basic config file parsing
use_ok('Prophet::Config');
my $config = Prophet::Config->new(app_handle => Prophet::CLI->new->app_handle);
+
isa_ok($config => 'Prophet::Config');
can_ok($config => 'load_from_files');
Modified: Prophet/trunk/t/export.t
==============================================================================
--- Prophet/trunk/t/export.t (original)
+++ Prophet/trunk/t/export.t Wed Aug 20 23:28:26 2008
@@ -60,7 +60,7 @@
ok( -e $path->file('changesets.idx'), 'found changesets index' );
my $latest = $path->file('latest-sequence-no')->slurp;
is( $latest, $cli->handle->latest_sequence_no );
- use_ok('Prophet::Replica::Native');
+ use_ok('Prophet::Replica::prophet');
diag("Checking changesets in $path");
my $changesets = Prophet::Replica->new( { url => 'prophet:file://' . $path } )->fetch_changesets( after => 0 );
my @changesets = grep {$_->has_changes} @$changesets;
More information about the Bps-public-commit
mailing list