App-JESP
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/JESP.pm view on Meta::CPAN
package App::JESP;
$App::JESP::VERSION = '0.016';
use Moose;
use App::JESP::Plan;
use App::JESP::Colorizer;
use JSON;
use Class::Load;
use DBI;
use DBIx::Simple;
use File::Spec;
use IO::Interactive;
use Log::Any qw/$log/;
use String::Truncate;
# Settings
## DB Connection attrbutes.
has 'dsn' => ( is => 'ro', isa => 'Str', required => 1 );
has 'username' => ( is => 'ro', isa => 'Maybe[Str]', required => 1);
has 'password' => ( is => 'ro', isa => 'Maybe[Str]', required => 1);
has 'home' => ( is => 'ro', isa => 'Str', required => 1 );
## JESP Attributes
has 'prefix' => ( is => 'ro', isa => 'Str', default => 'jesp_' );
has 'driver_class' => ( is => 'ro', isa => 'Str', lazy_build => 1);
# Operational stuff
has 'get_dbh' => ( is => 'ro', isa => 'CodeRef', default => sub{
my ($self) = @_;
return sub{
return DBI->connect( $self->dsn(), $self->username(), $self->password(),
{ RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
});
};
});
has 'dbix_simple' => ( is => 'ro', isa => 'DBIx::Simple', lazy_build => 1);
has 'patches_table_name' => ( is => 'ro', isa => 'Str' , lazy_build => 1);
has 'meta_patches' => ( is => 'ro', isa => 'ArrayRef[HashRef]',
lazy_build => 1 );
has 'plan' => ( is => 'ro', isa => 'App::JESP::Plan', lazy_build => 1);
has 'driver' => ( is => 'ro', isa => 'App::JESP::Driver', lazy_build => 1 );
has 'interactive' => ( is => 'ro' , isa => 'Bool' , lazy_build => 1 );
has 'colorizer' => ( is => 'ro', isa => 'App::JESP::Colorizer', lazy_build => 1 );
has json => ( is => "ro", lazy_build => 1 );
sub _build_json { JSON->new->relaxed(1) }
sub _build_driver{
my ($self) = @_;
return $self->driver_class()->new({ jesp => $self });
}
sub _build_driver_class{
my ($self) = @_;
my $db_name = $self->dbix_simple()->dbh()->{Driver}->{Name};
my $driver_class = 'App::JESP::Driver::'.$db_name;
$log->info("Loading driver ".$driver_class);
Class::Load::load_class( $driver_class );
return $driver_class;
}
sub _build_plan{
my ($self) = @_;
my $file = File::Spec->catfile( $self->home(), 'plan.json' );
unless( ( -e $file ) && ( -r $file ) ){
die "File $file does not exists or is not readable\n";
}
return App::JESP::Plan->new({ file => $file, jesp => $self });
}
sub _build_dbix_simple{
my ($self) = @_;
my $dbh = $self->get_dbh()->();
my $db = DBIx::Simple->connect($dbh);
}
sub _build_patches_table_name{
my ($self) = @_;
return $self->prefix().'patch';
}
# Building the meta patches, in SQLite compatible format.
sub _build_meta_patches{
my ($self) = @_;
return [
{ id => $self->prefix().'meta_zero', sql => 'CREATE TABLE '.$self->patches_table_name().' ( id VARCHAR(512) NOT NULL PRIMARY KEY, applied_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP );' }
];
}
sub _build_interactive{
my ($self) = @_;
return IO::Interactive::is_interactive();
}
sub _build_colorizer{
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.454 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )