« lib/BioX/Workflow/Command/run/Utils/WriteMeta.pm
↑ Summary
lib/BioX/Workflow/Command/run/Utils/Files/ResolveDeps.pm »
| 1 | package BioX::Workflow::Command::run::Rules::Directives::Inspect; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Storable qw(dclone); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use YAML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use BioX::Workflow::Command::run::Rules::Directives::Exceptions::DidNotDeclare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use BioX::Workflow::Command::run::Rules::Directives::Exceptions::SyntaxError; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | with 'BioX::Workflow::Command::inspect::Utils::ParsePlainText'; | |||||||||
| 14 | |||||||||||
| 15 | has 'inspect_obj' => ( | ||||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | isa => 'HashRef', | ||||||||||
| 18 | 0 | ▶ | default => sub { return {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 1 | ); | |||||||||
| 20 | |||||||||||
| 21 | 1 | has 'path' => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | isa => 'Str', | ||||||||||
| 24 | required => 0, | ||||||||||
| 25 | predicate => 'has_path', | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub return_rule_as_obj { | ||||||||
|
Subroutine
return_rule_as_obj: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 29 | 0 | my $self = shift; | |||||||||
| 30 | 0 | my $attr = shift; | |||||||||
| 31 | |||||||||||
| 32 | 0 | my $clean = {}; | |||||||||
| 33 | 0 | $self->get_line_number_rules; | |||||||||
| 34 | |||||||||||
| 35 | 0 | foreach my $key ( @{ $self->rule_keys } ) { | |||||||||
| 36 | 0 | my $t = $self->check_path( $attr->$key ); | |||||||||
| 37 | 0 | $t =~ s/__DUMMYSAMPLE123456789__/Sample_XYZ/g; | |||||||||
| 38 | 0 | $clean->{$key} = $t; | |||||||||
| 39 | 0 | $self->get_error_message( $key, $t ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | my @haves = ( 'indir', 'outdir', 'INPUT', 'OUTPUT', 'stash' ); | |||||||||
| 43 | 0 | foreach my $h (@haves) { | |||||||||
| 44 | 0 | ▶ | next if exists $clean->{$h}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | my $t = $self->check_path( $attr->$h ); | |||||||||
| 46 | 0 | $t =~ s/__DUMMYSAMPLE123456789__/Sample_XYZ/g; | |||||||||
| 47 | 0 | $clean->{$h} = $t; | |||||||||
| 48 | 0 | $self->get_error_message( $h, $t ); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | $self->inspect_obj->{rules}->{ $self->rule_name }->{local} = $clean; | |||||||||
| 52 | $self->inspect_obj->{rules}->{ $self->rule_name }->{rule_keys} = | ||||||||||
| 53 | 0 | dclone( $self->rule_keys ); | |||||||||
| 54 | |||||||||||
| 55 | 0 | return $clean; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub return_global_as_object { | ||||||||
|
Subroutine
return_global_as_object: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 59 | 0 | my $self = shift; | |||||||||
| 60 | |||||||||||
| 61 | 0 | $self->get_global_keys; | |||||||||
| 62 | |||||||||||
| 63 | 0 | my $attr = dclone( $self->global_attr ); | |||||||||
| 64 | 0 | $attr->walk_process_data( $self->global_keys ); | |||||||||
| 65 | |||||||||||
| 66 | 0 | my $global = {}; | |||||||||
| 67 | |||||||||||
| 68 | 0 | foreach my $key ( @{ $self->global_keys } ) { | |||||||||
| 69 | 0 | $global->{$key} = $self->check_path( $attr->{$key} ); | |||||||||
| 70 | } | ||||||||||
| 71 | 0 | $self->inspect_obj->{global} = $global; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub check_path { | ||||||||
|
Subroutine
check_path: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 75 | 0 | my $self = shift; | |||||||||
| 76 | 0 | my $val = shift; | |||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | if ( ref($val) eq 'Path::Tiny' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $val = $val->stringify; | |||||||||
| 80 | } | ||||||||||
| 81 | 0 | return $val; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 0 | ▶ | sub get_error_message { | ||||||||
|
Subroutine
get_error_message: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||
| 85 | 0 | my $self = shift; | |||||||||
| 86 | 0 | my $k = shift; | |||||||||
| 87 | 0 | my $v = shift; | |||||||||
| 88 | 0 | my $keep = shift; | |||||||||
| 89 | |||||||||||
| 90 | 0 | my $msg = Dump($v); | |||||||||
| 91 | 0 | ▶ | return unless $msg =~ m/The following errors/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | |||||||||||
| 93 | 0 | my $template = <<EOF; | |||||||||
| 94 | ################################################### | ||||||||||
| 95 | # The following errors were encountered: | ||||||||||
| 96 | (.*) | ||||||||||
| 97 | #################################################### | ||||||||||
| 98 | EOF | ||||||||||
| 99 | |||||||||||
| 100 | 0 | my (@match) = $msg =~ m/$template/sg; | |||||||||
| 101 | 0 | ▶ | return unless @match; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 0 | my $error; | |||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | if ($keep) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | $error = join( "\n", @match ); | |||||||||
| 106 | } | ||||||||||
| 107 | else { | ||||||||||
| 108 | 0 | $error = $match[0]; | |||||||||
| 109 | } | ||||||||||
| 110 | 0 | ▶ | return unless $error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | |||||||||||
| 112 | 0 | $error =~ s/__DUMMYSAMPLE123456789__/Sample_XYZ/g; | |||||||||
| 113 | 0 | my @split = split( "\n", $error ); | |||||||||
| 114 | 0 | shift @split; | |||||||||
| 115 | |||||||||||
| 116 | 0 | @split = map { my $t = $_; $t =~ s/# //; $t } @split; | |||||||||
| 117 | 0 | $error = join( "\n\t", @split ); | |||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | return unless $error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | |||||||||||
| 121 | $self->inspect_obj->{errors}->{rules}->{ $self->rule_name }->{local}->{$k}->{msg} = | ||||||||||
| 122 | 0 | $error; | |||||||||
| 123 | |||||||||||
| 124 | $self->app_log->warn( 'Error for key \'' | ||||||||||
| 125 | . $k | ||||||||||
| 126 | . '\' Line #: ' | ||||||||||
| 127 | . $self->inspect_obj->{line_numbers}->{rules}->{ $self->rule_name } | ||||||||||
| 128 | 0 | ▶ | ->{local}->{$k}->{line} ) if $self->inspect_obj->{line_numbers}->{rules}->{ $self->rule_name }->{local}->{$k}->{line}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | $self->inspect_obj->{errors}->{rules}->{ $self->rule_name }->{local}->{$k} | ||||||||||
| 130 | 0 | ->{error_types} = $self->get_error_types( $k, $error ); | |||||||||
| 131 | |||||||||||
| 132 | 0 | return $error; | |||||||||
| 133 | } | ||||||||||
| 134 | |||||||||||
| 135 | 0 | ▶ | sub get_error_types { | ||||||||
|
Subroutine
get_error_types: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 136 | 0 | my $self = shift; | |||||||||
| 137 | 0 | my $k = shift; | |||||||||
| 138 | 0 | my $error = shift; | |||||||||
| 139 | |||||||||||
| 140 | 0 | my @error_types = (); | |||||||||
| 141 | 0 | my $print_error = 0; | |||||||||
| 142 | 0 | ▶ | if ( $error =~ m/Did you declare/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 0 | my $except = | |||||||||
| 144 | BioX::Workflow::Command::run::Rules::Directives::Exceptions::DidNotDeclare | ||||||||||
| 145 | ->new( info => '[ERROR DidNotDeclare]: ' ); | ||||||||||
| 146 | 0 | $except->warn( $self->app_log ); | |||||||||
| 147 | 0 | push( @error_types, 'DidNotDeclare' ); | |||||||||
| 148 | } | ||||||||||
| 149 | 0 | ▶ | if ( $error =~ m/syntax/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | 0 | my $except = | |||||||||
| 151 | BioX::Workflow::Command::run::Rules::Directives::Exceptions::SyntaxError | ||||||||||
| 152 | ->new( info => '[ERROR Syntax]: ' ); | ||||||||||
| 153 | 0 | $except->warn( $self->app_log ); | |||||||||
| 154 | 0 | push( @error_types, 'Syntax' ); | |||||||||
| 155 | } | ||||||||||
| 156 | 0 | $self->app_log->warn( $error . "\n" ); | |||||||||
| 157 | |||||||||||
| 158 | 0 | return \@error_types; | |||||||||
| 159 | |||||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | 1 | 1; | |||||||||