| 1 | package TaskPipe::Sample; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use TryCatch; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use DBIx::Error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use TaskPipe::RunInfo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use TaskPipe::FileInstaller; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use TaskPipe::PathSettings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use TaskPipe::SchemaManager; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Module::Runtime 'require_module'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | with 'TaskPipe::Role::MooseType_ScopeMode'; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | has run_info => (is => 'ro', isa => 'TaskPipe::RunInfo', default => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | TaskPipe::RunInfo->new; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | has file_installer => (is => 'rw', isa => 'TaskPipe::FileInstaller', lazy => 1, default => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | TaskPipe::FileInstaller->new; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | has path_settings => (is => 'rw', isa => 'TaskPipe::PathSettings', lazy => 1, default => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | TaskPipe::PathSettings->new; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | has schema_manager => (is => 'rw', isa => 'TaskPipe::SchemaManager', lazy => 1, default => sub{ TaskPipe::SchemaManager->new }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | sub deploy_files{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy_files: not called CC=4 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $self->file_installer->create_dir( $self->path_settings->project_dir ); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | foreach my $dir ( qw(lib plan source log conf) ){ | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->file_installer->create_dir( $self->path_settings->path( $dir ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $lib_dir = $self->path_settings->path( | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'lib', | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $self->path_settings->project->task_module_prefix | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $self->file_installer->create_dir( | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | $self->path_settings->path( | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'lib', | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | $self->path_settings->project->task_module_prefix | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | foreach my $template_name ( @{$self->templates} ){ | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $template_module = 'TaskPipe::Template_'.$template_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | require_module( $template_module ); | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $template = $template_module->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $template->deploy; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | unshift @{$self->file_installer->files_created}, +$template->target_path; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->file_installer->rollback; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | confess "Rolled back changes: ".$_; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sub deploy_tables{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy_tables: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my @template_names = @{$self->schema_templates}; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $first_template_name = shift @template_names; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $self->deploy_tables_from_schema_template( $first_template_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return if $self->run_info->scope eq 'global'; # we only expect 1 schema to | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # deploy for global tables | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | #for project templates, everything after the first template | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # is a plan template (usually only one?) | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | foreach my $template_name ( @template_names ){ | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->deploy_tables_from_schema_template( $template_name, 'no_prefix' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub deploy_tables_from_schema_template{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ($self,$template_name, $no_prefix) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy_tables_from_schema_template: not called CC=9 SCAR=43.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $module = 'TaskPipe::SchemaTemplate_'.$template_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $schema = $self->schema_manager->connect_schema($module); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my @sn = $schema->sources; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $table_prefix = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $table_prefix = $self->schema_manager->settings->table_prefix unless $no_prefix; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $str = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | foreach my $sn (@sn){ | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $source = $schema->source( $sn ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $table_name = $table_prefix.$source->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $source->name( $table_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $table_exists = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $err; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $count = $schema->resultset( $sn )->count; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | } catch ( DBIx::Error $err ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=5.3
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( ( $self->schema_manager->settings->type eq 'SQLite' && $err->state eq 'S1000' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->schema_manager->settings->type eq "SQLite" and $err->state eq "S1000" or $err->state eq "42S02"
$self->schema_manager->settings->type eq "SQLite" and $err->state eq "S1000"
MC/DC0%0/3
$self->schema_manager->settings->type eq "SQLite" and $err->state eq "S1000" or $err->state eq "42S02"
$self->schema_manager->settings->type eq "SQLite"
$err->state eq "S1000"
$err->state eq "42S02"
Truth table0%0/5
A and B or C
A= $self->schema_manager->settings->type eq "SQLite"B= $err->state eq "S1000"C= $err->state eq "42S02"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | || $err->state eq "42S02" ){ | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $table_exists = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | die $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ( $table_exists ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | confess +$self->_table_exists_message($table_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $schema->deploy; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | sub _table_exists_message{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my ($self,$table_name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_exists_message: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $msg = "[B<Table $table_name appears to exist already. Have you already deployed ".$self->run_info->scope." tables"; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ($self->run_info->scope eq 'project'){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $msg.=" for project ".$self->path_settings->global->project; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $msg.="?>]"; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | TaskPipe::Sample - base class for sample projects | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | When creating sample projects for taskpipe, inherit from this class | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | Tom Gracey <tomgracey@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | Copyright (c) Tom Gracey 2018 | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | TaskPipe is free software, licensed under | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | The GNU Public License Version 3 | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||