App-SD
view release on metacpan or search on metacpan
lib/App/SD/ForeignReplica.pm view on Meta::CPAN
package App::SD::ForeignReplica;
use Any::Moose;
use Params::Validate qw/:all/;
use Try::Tiny;
use URI;
extends 'Prophet::ForeignReplica';
has uuid => (
lazy => 1,
isa => 'Str',
is => 'ro',
default => sub {
my $self = shift;
$self->uuid_for_url( $self->_uuid_url );
}
);
=head2 save_username_and_token( $username, $token )
Saves the given username and token to the replica-specific config file,
so the user doesn't have to enter it every time.
=cut
sub save_username_and_token {
my ($self, $username, $password) = @_;
# make sure replica is initialized, since this method is generally called
# in the BUILD method of an object, which makes it end up being called
# before the initialize call in clone
$self->app_handle->handle->after_initialize( sub { shift->app_handle->set_db_defaults } );
$self->app_handle->handle->initialize;
my $replica_username_key = 'replica.' . $self->scheme . ":" . $self->{url} . '.username';
my $replica_token_key = 'replica.' . $self->scheme . ":" . $self->{url} . '.secret_token';
if ( !$self->app_handle->config->get( key => $replica_username_key ) ) {
print "Setting replica's username and token in the config file";
$self->app_handle->config->group_set(
$self->app_handle->config->replica_config_file,
[ {
key => $replica_username_key,
value => $username,
}, {
key => $replica_token_key,
value => $password,
} ],
);
}
}
sub integrate_changeset {
my $self = shift;
my %args = validate(
@_,
{ changeset => { isa => 'Prophet::ChangeSet' },
resolver => { optional => 1 },
resolver_class => { optional => 1 },
resdb => { optional => 1 },
conflict_callback => { optional => 1 },
reporting_callback => { optional => 1 }
( run in 1.799 second using v1.01-cache-2.11-cpan-d8267643d1d )