| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
#declarations |
|
3
|
|
|
|
|
|
|
package Fry::Lib::CDBI::Outline; |
|
4
|
1
|
|
|
1
|
|
1310
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
|
|
|
|
|
|
#because of use of local |
|
6
|
1
|
|
|
1
|
|
4
|
no strict 'vars'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
2118
|
|
|
7
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub _default_data { |
|
16
|
|
|
|
|
|
|
return { |
|
17
|
|
|
|
|
|
|
#causes action_columns to be uninit when using Load |
|
18
|
0
|
|
|
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
|
|
|
|
|
|
|
#print |
|
27
|
|
|
|
|
|
|
sub print_indented_rows { |
|
28
|
0
|
|
|
0
|
0
|
|
my $class =shift; |
|
29
|
0
|
|
|
|
|
|
my @rows = @{shift()}; |
|
|
0
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my @columns = @{shift()}; |
|
|
0
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $indent = shift; |
|
32
|
0
|
|
|
|
|
|
my $data; |
|
33
|
0
|
|
|
|
|
|
my $ind = $indent_char x ($indent + 1); |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
return "" if (@rows == 0); |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
for my $row (@rows) { |
|
38
|
0
|
|
|
|
|
|
for my $c (@columns) { |
|
39
|
0
|
|
0
|
|
|
|
$data .= ($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
|
|
|
|
|
|
|
sub search_outline { |
|
50
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my @search = $class->aliasInputAndSql(@_); |
|
53
|
0
|
|
|
|
|
|
my @results = $class->${\$class->Var('cdbi_search')}(@search); |
|
|
0
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub input_to_nodes { |
|
64
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub get_indents { |
|
74
|
|
|
|
|
|
|
#d:create indents associated with @entry |
|
75
|
|
|
|
|
|
|
#increment,decrement or do nothing too match level of $ith item |
|
76
|
0
|
|
|
0
|
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++) { |
|
82
|
0
|
|
|
|
|
|
for (substr($entry[$i],0,1)) { |
|
83
|
0
|
0
|
|
|
|
|
/^$left$/ && do {$indent[$i]=$indent[$i-1]-1;last }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
/^$right$/ && do {$indent[$i]=$indent[$i-1]+1;last}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
/^$even$/ && do {$indent[$i] = $indent[$i-1];last }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
0
|
|
|
|
|
|
return @indent; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
sub get_values { |
|
91
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
92
|
0
|
|
|
|
|
|
my @values = @_; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
for (@values) {$_ = substr($_,1);} #chop first letters off of array |
|
|
0
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return @values; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
sub alias_otl { |
|
98
|
|
|
|
|
|
|
#d:pass search terms to list fn,have special %% term |
|
99
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if ($_ !~ /$splitter/) { |
|
111
|
0
|
|
|
|
|
|
push(@input,$otlcol.$splitter.$_); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
|
else { push(@input,$_); } |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return @input; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
sub set_results { |
|
119
|
|
|
|
|
|
|
#d:inserts results at proper outline levels into @tags |
|
120
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
121
|
0
|
|
|
|
|
|
my @otl_obj = @{shift()}; |
|
|
0
|
|
|
|
|
|
|
|
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
|
0
|
|
0
|
|
|
local $SIG{__WARN__} = sub { return $_[0] unless $_[0] =~ m/Use of uninitialized value/; }; |
|
|
0
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
for (my $i=0;$i <$max;$i++) { #creates an array of base otl_obj for next search term |
|
128
|
|
|
|
|
|
|
#doesn't have child |
|
129
|
0
|
0
|
|
|
|
|
if ($otl_obj[$i]{indent} >= $otl_obj[$i+1]{indent}) { |
|
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
|
0
|
|
|
|
|
if ($otl_obj[$i]{indent} < $otl_obj[$i+1]{indent}) {push(@stack,$otl_obj[$i]{value});} |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#if not child then pop |
|
136
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub makeNodeOutline { |
|
142
|
|
|
|
|
|
|
#d:display @otl_obj in outline format |
|
143
|
0
|
|
|
0
|
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
|
0
|
|
0
|
|
|
local $SIG{__WARN__} = sub { return $_[0] unless $_[0] =~ m/Use of uninitialized value/; }; |
|
|
0
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
for (my $i=0;$i <$max;$i++) { #creates an array of base otl_obj for next search term |
|
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')}; |
|
|
0
|
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if ($otl_obj[$i]{indent} >= $otl_obj[$i+1]{indent}) { |
|
171
|
0
|
|
|
|
|
|
$body .= $class->print_indented_rows ($otl_obj[$i]{result}, |
|
172
|
|
|
|
|
|
|
\@columns,$otl_obj[$i]{indent}); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
} |
|
175
|
0
|
|
|
|
|
|
return $body; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
sub get_outline { |
|
178
|
|
|
|
|
|
|
#d:parses input + returns data to make outline |
|
179
|
0
|
|
|
0
|
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++) { |
|
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
|
|
|
|
|
|
|
sub create_outline { |
|
198
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
199
|
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my @otl_obj = @{$class->get_outline(@_)}; |
|
|
0
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
my $body = $class->makeNodeOutline(@otl_obj); |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
return $body; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
#shell function |
|
207
|
|
|
|
|
|
|
sub outlineSearches { |
|
208
|
0
|
|
|
0
|
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; |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
__END__ |