Bio-VertRes-Config
view release on metacpan or search on metacpan
lib/Bio/VertRes/Config/Pipelines/Common.pm view on Meta::CPAN
package Bio::VertRes::Config::Pipelines::Common;
# ABSTRACT: A set of attributes common to all pipeline config files
use Moose;
use File::Slurp;
use Bio::VertRes::Config::Types;
use Data::Dumper;
use File::Basename;
use File::Path qw(make_path);
with 'Bio::VertRes::Config::Pipelines::Roles::RootDatabaseLookup';
has 'prefix' => ( is => 'ro', isa => 'Bio::VertRes::Config::Prefix', default => '_' );
has 'pipeline_short_name' => ( is => 'ro', isa => 'Str', required => 1 );
has 'module' => ( is => 'ro', isa => 'Str', required => 1 );
has 'toplevel_action' => ( is => 'ro', isa => 'Str', required => 1 );
has 'overwrite_existing_config_file' => ( is => 'ro', isa => 'Bool', default => 0 );
has 'log' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_log' );
has 'log_base' => ( is => 'ro', isa => 'Str', required => 1 );
has 'log_file_name' => ( is => 'ro', isa => 'Str', default => 'logfile.log' );
has 'config' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_config' );
has 'config_base' => ( is => 'ro', isa => 'Str', required => 1 );
has 'config_file_name' => ( is => 'ro', isa => 'Str', default => 'global.conf' );
has 'root' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_root' );
has 'root_base' => ( is => 'ro', isa => 'Str', required => 1 );
has 'root_pipeline_suffix' => ( is => 'ro', isa => 'Str', default => 'seq-pipelines' );
has 'database' => ( is => 'ro', isa => 'Str', required => 1 );
has 'host' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_host' );
has 'port' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build_port' );
has 'user' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_user' );
has 'password' => ( is => 'ro', isa => 'Maybe[Str]', lazy => 1, builder => '_build_password' );
has 'database_connect_file' => ( is => 'ro', isa => 'Str', required => 1 );
has '_database_connection_details' =>
( is => 'ro', isa => 'Maybe[HashRef]', lazy => 1, builder => '_build__database_connection_details' );
sub _build_root {
my ($self) = @_;
join( '/', ( $self->root_base, $self->root_database_name, $self->root_pipeline_suffix ) );
}
sub _build_config {
my ($self) = @_;
my $conf_file_name = join( '_', ( $self->pipeline_short_name, $self->config_file_name ) );
join( '/', ( $self->config_base, $self->root_database_name, $self->pipeline_short_name, $conf_file_name ) );
}
sub _build_log {
my ($self) = @_;
my $log_file_name = join( '_', ( $self->pipeline_short_name, $self->log_file_name ) );
join( '/', ( $self->log_base, $self->root_database_name, $log_file_name ) );
}
sub _build_host {
my ($self) = @_;
if ( defined( $self->_database_connection_details ) ) {
return $self->_database_connection_details->{host};
}
return $ENV{VRTRACK_HOST} || 'localhost';
}
sub _build_port {
my ($self) = @_;
if ( defined( $self->_database_connection_details ) ) {
return $self->_database_connection_details->{port};
}
return $ENV{VRTRACK_PORT} || 3306;
}
sub _build_user {
my ($self) = @_;
if ( defined( $self->_database_connection_details ) ) {
return $self->_database_connection_details->{user};
}
return $ENV{VRTRACK_RW_USER} || 'root';
}
sub _build_password {
my ($self) = @_;
if ( defined( $self->_database_connection_details ) ) {
return $self->_database_connection_details->{password};
}
return $ENV{VRTRACK_PASSWORD};
}
sub _build__database_connection_details {
my ($self) = @_;
my $connection_details;
if ( -f $self->database_connect_file ) {
my $text = read_file( $self->database_connect_file );
$connection_details = eval($text);
}
return $connection_details;
}
( run in 0.725 second using v1.01-cache-2.11-cpan-39bf76dae61 )