blib/lib/BioX/Workflow/Command/inspect/Utils/ParsePlainText.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 111 CC 10 SCAR 22.5
CC
10
Cov
0%
get_line_declarations
12.0
get_line_number_rules
12.0
get_line_number_rule_process
12.0
CRAP 9.5
1 package BioX::Workflow::Command::inspect::Utils::ParsePlainText;
2  
3 use Moose::Role;
4 use namespace::autoclean;
5 use File::Slurp;
6  
7 has 'workflow_plain_text' => (
8 is => 'rw',
9 lazy => 1,
10 default => sub {
11 my $self = shift;
12 return read_file( $self->workflow, array_ref => 1 );
13 }
14 );
15  
16 has 'line_number_rules_dec' => (
17 is => 'rw',
18 lazy => 1,
19 default => 1,
20 );
21  
22 has 'line_number_global_dec' => (
23 is => 'rw',
24 lazy => 1,
25 default => 2,
26 );
27  
28 sub get_line_declarations {
29 my $self = shift;
30  
31 my $line_number = 0;
32 foreach my $line ( @{ $self->workflow_plain_text } ) {
33 if ( $line =~ m/\s*:\s*rules\s*:/ ) {
34 my $column = $self->get_column($line);
35 $self->inspect_obj->{line_numbers}->{begin_rules} =
36 { line => $line_number, column => $column };
37 $self->line_number_rules_dec($line_number);
38 }
39 elsif ( $line =~ m/\s:\s*global\s:/ ) {
40 my $column = $self->get_column($line);
41 $self->inspect_obj->{line_numbers}->{begin_global} =
42 { line => $line_number, column => $column };
43 $self->line_number_global_dec($line_number);
44 }
45 $line_number++;
46 }
47 }
48  
49 sub get_line_number_rules {
50 my $self = shift;
51  
52 $self->inspect_obj->{line_numbers}->{rules}->{ $self->rule_name }->{local}
53 = {};
54  
55 my $rule_name = $self->rule_name;
56 my $found_rule = 0;
57 my $found_local = 0;
58  
59 for (
60 my $x = $self->line_number_rules_dec + 1 ;
61 $x < scalar @{ $self->workflow_plain_text } ;
62 $x++
63 )
64 {
65 my $line = $self->workflow_plain_text->[$x];
66 if ($found_rule) {
67 $self->get_line_number_rule_key( $line, $x );
68 $self->get_line_number_rule_process( $line, $x );
69 }
70 elsif ( ( $line =~ m/\s*-\s*$rule_name\s*:/ ) ) {
71 my $column = $self->get_column($line);
72 $self->inspect_obj->{line_numbers}->{begin_rule} = {line => $x, column => $column};
73 $found_rule = 1;
74 }
75 }
76 }
77  
78 sub get_line_number_rule_process {
79 my $self = shift;
80 my $line = shift;
81 my $line_count = shift;
82  
83 return
84 if
85 exists $self->inspect_obj->{line_numbers}->{rules}->{ $self->rule_name }
86 ->{process};
87  
88 if ( ( $line =~ m/\s*process\s*:/ ) ) {
89 my $column = $self->get_column($line);
90 $self->inspect_obj->{line_numbers}->{rules}->{ $self->rule_name }
91 ->{process} = { line => $line_count, column => $column };
92 return;
93 }
94 }
95  
96 sub get_line_number_rule_key {
97 my $self = shift;
98 my $line = shift;
99 my $line_count = shift;
100  
101 foreach my $key ( @{ $self->rule_keys } ) {
102 next
103 if exists $self->inspect_obj->{line_numbers}->{rules}
104 ->{ $self->rule_name }->{local}->{$key};
105  
106 if ( ( $line =~ m/\s*-\s*$key\s*:/ ) ) {
107 my $column = $self->get_column($line);
108 $self->inspect_obj->{line_numbers}->{rules}->{ $self->rule_name }
109 ->{local}->{$key} = { line => $line_count, column => $column, };
110 return;
111 }
112 }
113 }
114  
115 sub get_column {
116 my $self = shift;
117 my $line = shift;
118  
119 my $column = 0;
120 my @split_line = split( '', $line );
121 for ( my $x = 0 ; $x <= $#split_line ; $x++ ) {
122 if ( $split_line[$x] =~ m/^\s*$/ || $split_line[$x] =~ m/^\t*$/ ) {
123 $column = $x;
124 }
125 else {
126 last;
127 }
128 }
129 $column += 1;
130 ##Make these tabs
131 $column = $column / 4;
132 }
133 1;