| 1 | #!/usr/bin/perl | ||||||||||||||
| 2 | #declarations | ||||||||||||||
| 3 | package Fry::Lib::CDBI::Outline; | ||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | #because of use of local | ||||||||||||||
| 6 | 1 | ▶ | no strict 'vars'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | our $VERSION = '0.14'; | |||||||||||||
| 8 | #our cdbi_search = "search_abstract"; | ||||||||||||||
| 9 | |||||||||||||||
| 10 | #our ($left,$right,$even,$otlcol,$indent_char) = ('\)','\(',',','tags',"\t"); | ||||||||||||||
| 11 | #our $tree_result; | ||||||||||||||
| 12 | #our $ind; | ||||||||||||||
| 13 | |||||||||||||||
| 14 | #functions | ||||||||||||||
| 15 | 0 | ▶ | sub _default_data { | ||||||||||||
|
Subroutine
_default_data: not called CC=1 SCAR=6.9
| |||||||||||||||
| 16 | return { | ||||||||||||||
| 17 | #causes action_columns to be uninit when using Load | ||||||||||||||
| 18 | 0 | depend=>[qw/:CDBI::Basic/], | |||||||||||||
| 19 | cmds=>{outlineSearches=>{a=>'O',d=>'presents several database queries in an outline format', | ||||||||||||||
| 20 | u=>'($search_term$level_delimiter)+'}}, | ||||||||||||||
| 21 | vars=>{right_indent=>'\(',no_indent=>',',left_indent=>'\)',otlcol=>'tags',indent_char=>"\t"}, | ||||||||||||||
| 22 | #tr make_tree_simple trr make_tree_results/}, | ||||||||||||||
| 23 | #flags=>{qw/L last_tag tt triple_table/}, | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | ▶ | sub print_indented_rows { | ||||||||||||
|
Subroutine
print_indented_rows: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 28 | 0 | my $class =shift; | |||||||||||||
| 29 | 0 | my @rows = @{shift()}; | |||||||||||||
| 30 | 0 | my @columns = @{shift()}; | |||||||||||||
| 31 | 0 | my $indent = shift; | |||||||||||||
| 32 | 0 | my $data; | |||||||||||||
| 33 | 0 | my $ind = $indent_char x ($indent + 1); | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | ▶ | return "" if (@rows == 0); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | 0 | for my $row (@rows) { | |||||||||||||
| 38 | 0 | for my $c (@columns) { | |||||||||||||
| 39 | 0 | ▶ | $data .= ($row->$c || ""); | ||||||||||||
|
Condition0%0/2
$row->$c || ''
MC/DC0%0/1
$row->$c || ''
$row->$c
Truth table0%0/2
A
A= $row->$c
| |||||||||||||||
| 40 | 0 | $data .= $class->Var('field_delimiter'); | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | 0 | $data .= "\n"; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | $data =~ s/^/$ind/mg; | |||||||||||||
| 46 | 0 | return $data; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | #internals | ||||||||||||||
| 49 | 0 | ▶ | sub search_outline { | ||||||||||||
|
Subroutine
search_outline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 50 | 0 | my $class = shift; | |||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | my @search = $class->aliasInputAndSql(@_); | |||||||||||||
| 53 | 0 | my @results = $class->${\$class->Var('cdbi_search')}(@search); | |||||||||||||
| 54 | 0 | return @results; | |||||||||||||
| 55 | |||||||||||||||
| 56 | #if ($class->Flag('triple_table') && $class->can('_triple_table')) { | ||||||||||||||
| 57 | #@results = map { $_->${\$class->_triple_table->{rc23}} } | ||||||||||||||
| 58 | #map { $_->${\$class->_triple_table->{many_method}} } @results; | ||||||||||||||
| 59 | #use Data::Dumper; | ||||||||||||||
| 60 | #print Dumper \@results; | ||||||||||||||
| 61 | #} | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | 0 | ▶ | sub input_to_nodes { | ||||||||||||
|
Subroutine
input_to_nodes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 64 | 0 | my $class = shift; | |||||||||||||
| 65 | 0 | my $entry ="@_"; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | $entry =~ s/[$left$right$even]$//; | |||||||||||||
| 68 | 0 | $entry =~ s/([$left$right$even])/\n$1/g; | |||||||||||||
| 69 | 0 | $entry =~ s/^/$even/; | |||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | return split(/\n/,$entry); | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | 0 | ▶ | sub get_indents { | ||||||||||||
|
Subroutine
get_indents: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 74 | #d:create indents associated with @entry | ||||||||||||||
| 75 | #increment,decrement or do nothing too match level of $ith item | ||||||||||||||
| 76 | 0 | my $class = shift; | |||||||||||||
| 77 | 0 | my @entry = @_; | |||||||||||||
| 78 | 0 | my @indent; | |||||||||||||
| 79 | 0 | $indent[0]=0; | |||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | ▶ | for (my $i=1;$i <@entry;$i++) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | 0 | for (substr($entry[$i],0,1)) { | |||||||||||||
| 83 | 0 | ▶ | /^$left$/ && do {$indent[$i]=$indent[$i-1]-1;last }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | 0 | ▶ | /^$right$/ && do {$indent[$i]=$indent[$i-1]+1;last}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | 0 | ▶ | /^$even$/ && do {$indent[$i] = $indent[$i-1];last }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | } | ||||||||||||||
| 87 | } | ||||||||||||||
| 88 | 0 | return @indent; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | 0 | ▶ | sub get_values { | ||||||||||||
|
Subroutine
get_values: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 91 | 0 | my $class = shift; | |||||||||||||
| 92 | 0 | my @values = @_; | |||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | for (@values) {$_ = substr($_,1);} #chop first letters off of array | |||||||||||||
| 95 | 0 | return @values; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | 0 | ▶ | sub alias_otl { | ||||||||||||
|
Subroutine
alias_otl: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 98 | #d:pass search terms to list fn,have special %% term | ||||||||||||||
| 99 | 0 | my $class = shift; | |||||||||||||
| 100 | 0 | my @terms = @_; | |||||||||||||
| 101 | 0 | my (@sameterms,@normterms,$sameterm,@rows,@input); | |||||||||||||
| 102 | 0 | my $splitter = $class->Var('splitter'); | |||||||||||||
| 103 | |||||||||||||||
| 104 | #parse terms | ||||||||||||||
| 105 | 0 | for (@terms) { | |||||||||||||
| 106 | #(/=/) ? push(@normterms,$_) : push(@sameterms,$_) ; | ||||||||||||||
| 107 | #above line turned into below if/else | ||||||||||||||
| 108 | |||||||||||||||
| 109 | #default tag column assumed when no splitter present | ||||||||||||||
| 110 | 0 | ▶ | if ($_ !~ /$splitter/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | 0 | push(@input,$otlcol.$splitter.$_); | |||||||||||||
| 112 | } | ||||||||||||||
| 113 | 0 | else { push(@input,$_); } | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | return @input; | |||||||||||||
| 117 | } | ||||||||||||||
| 118 | 0 | ▶ | sub set_results { | ||||||||||||
|
Subroutine
set_results: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 119 | #d:inserts results at proper outline levels into @tags | ||||||||||||||
| 120 | 0 | my $class = shift; | |||||||||||||
| 121 | 0 | my @otl_obj = @{shift()}; | |||||||||||||
| 122 | 0 | my @stack; #stack stack for a given level | |||||||||||||
| 123 | 0 | my $max = scalar(@otl_obj); | |||||||||||||
| 124 | #turn off warnings about uninitialized comparisons | ||||||||||||||
| 125 | 0 | ▶ | local $SIG{__WARN__} = sub { return $_[0] unless $_[0] =~ m/Use of uninitialized value/; }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | ▶ | for (my $i=0;$i <$max;$i++) { #creates an array of base otl_obj for next search term | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 128 | #doesn't have child | ||||||||||||||
| 129 | 0 | ▶ | if ($otl_obj[$i]{indent} >= $otl_obj[$i+1]{indent}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 130 | 0 | $otl_obj[$i]{result} = [$class->search_outline($class->alias_otl($otl_obj[$i]{value},@stack))]; | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | |||||||||||||||
| 133 | #if next obj is a child (a greater indent) then add to stack | ||||||||||||||
| 134 | 0 | ▶ | if ($otl_obj[$i]{indent} < $otl_obj[$i+1]{indent}) {push(@stack,$otl_obj[$i]{value});} | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 135 | #if not child then pop | ||||||||||||||
| 136 | 0 | elsif ($otl_obj[$i]{indent} > $otl_obj[$i+1]{indent}) {pop(@stack);} | |||||||||||||
| 137 | } | ||||||||||||||
| 138 | 0 | pop(@otl_obj); #created accidently by autovivification | |||||||||||||
| 139 | 0 | return @otl_obj; | |||||||||||||
| 140 | } | ||||||||||||||
| 141 | 0 | ▶ | sub makeNodeOutline { | ||||||||||||
|
Subroutine
makeNodeOutline: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 142 | #d:display @otl_obj in outline format | ||||||||||||||
| 143 | 0 | my $class = shift; | |||||||||||||
| 144 | 0 | my @otl_obj = @_; | |||||||||||||
| 145 | 0 | my @tag; #tag stack for a given level | |||||||||||||
| 146 | my ($body); | ||||||||||||||
| 147 | #h: scalar works here but not in for loop | ||||||||||||||
| 148 | 0 | my $max = scalar(@otl_obj); | |||||||||||||
| 149 | #turn off warnings about uninitialized comparisons | ||||||||||||||
| 150 | 0 | ▶ | local $SIG{__WARN__} = sub { return $_[0] unless $_[0] =~ m/Use of uninitialized value/; }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 151 | |||||||||||||||
| 152 | 0 | ▶ | for (my $i=0;$i <$max;$i++) { #creates an array of base otl_obj for next search term | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 153 | 0 | $ind = $indent_char x $otl_obj[$i]{indent}; | |||||||||||||
| 154 | 0 | $body .= $ind . "$otl_obj[$i]{value}\n"; | |||||||||||||
| 155 | |||||||||||||||
| 156 | #h: need var for other tables' print columns | ||||||||||||||
| 157 | #$class->action_columns([qw/id cmd tags options notes/]) if ($class->can('_triple_table')) ; | ||||||||||||||
| 158 | #my @c3_columns = (qw/id name parent_id notes/) ; | ||||||||||||||
| 159 | 0 | my @columns = @{$class->Var('action_columns')}; | |||||||||||||
| 160 | |||||||||||||||
| 161 | #if ($class->Flag('triple_table')) { | ||||||||||||||
| 162 | #($class->can('_triple_table')) | ||||||||||||||
| 163 | #? @columns = $class->_triple_table->{c3}->columns | ||||||||||||||
| 164 | #: warn "_triple_table isn't defined"; | ||||||||||||||
| 165 | #} | ||||||||||||||
| 166 | #my @c3_columns = $class->_triple_table->{c3}->columns; | ||||||||||||||
| 167 | #my @columns = ($class->_flag->{triple_table}) ? @c3_columns : @{$class->action_columns}; | ||||||||||||||
| 168 | |||||||||||||||
| 169 | #doesn't have child + has results | ||||||||||||||
| 170 | 0 | ▶ | if ($otl_obj[$i]{indent} >= $otl_obj[$i+1]{indent}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 171 | $body .= $class->print_indented_rows ($otl_obj[$i]{result}, | ||||||||||||||
| 172 | 0 | \@columns,$otl_obj[$i]{indent}); | |||||||||||||
| 173 | } | ||||||||||||||
| 174 | } | ||||||||||||||
| 175 | 0 | return $body; | |||||||||||||
| 176 | } | ||||||||||||||
| 177 | 0 | ▶ | sub get_outline { | ||||||||||||
|
Subroutine
get_outline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 178 | #d:parses input + returns data to make outline | ||||||||||||||
| 179 | 0 | my $class = shift; | |||||||||||||
| 180 | 0 | my (@otl_obj); | |||||||||||||
| 181 | #@otl_obj are @ of % with indent,value and result keys | ||||||||||||||
| 182 | |||||||||||||||
| 183 | 0 | my @bits = $class->input_to_nodes(@_); | |||||||||||||
| 184 | 0 | my @indent = $class->get_indents(@bits); | |||||||||||||
| 185 | 0 | my @value = $class->get_values(@bits); | |||||||||||||
| 186 | |||||||||||||||
| 187 | #creating @ of % for otl_obj | ||||||||||||||
| 188 | 0 | ▶ | for (my $i=0;$i<@indent;$i++) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 189 | 0 | $otl_obj[$i]{value} = $value[$i]; | |||||||||||||
| 190 | 0 | $otl_obj[$i]{indent} = $indent[$i]; | |||||||||||||
| 191 | } | ||||||||||||||
| 192 | |||||||||||||||
| 193 | 0 | $class->set_results(\@otl_obj); | |||||||||||||
| 194 | 0 | return \@otl_obj; | |||||||||||||
| 195 | } | ||||||||||||||
| 196 | #main function calling all the above | ||||||||||||||
| 197 | 0 | ▶ | sub create_outline { | ||||||||||||
|
Subroutine
create_outline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 198 | 0 | my $class = shift; | |||||||||||||
| 199 | |||||||||||||||
| 200 | 0 | my @otl_obj = @{$class->get_outline(@_)}; | |||||||||||||
| 201 | 0 | my $body = $class->makeNodeOutline(@otl_obj); | |||||||||||||
| 202 | |||||||||||||||
| 203 | 0 | return $body; | |||||||||||||
| 204 | } | ||||||||||||||
| 205 | |||||||||||||||
| 206 | #shell function | ||||||||||||||
| 207 | 0 | ▶ | sub outlineSearches { | ||||||||||||
|
Subroutine
outlineSearches: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 208 | 0 | my $cls = shift; | |||||||||||||
| 209 | #td: change to global variables | ||||||||||||||
| 210 | 0 | local ($right,$even,$left,$otlcol,$indent_char) = | |||||||||||||
| 211 | $cls->varMany(qw/right_indent no_indent left_indent otlcol indent_char/); | ||||||||||||||
| 212 | 0 | local $tree_result; | |||||||||||||
| 213 | 0 | local $ind; | |||||||||||||
| 214 | 0 | $cls->view($cls->create_outline(@_)); | |||||||||||||
| 215 | } | ||||||||||||||
| 216 | 1 | 1; | |||||||||||||
| 217 | |||||||||||||||
| 218 | __END__ | ||||||||||||||