5 |
|
|
6 |
use Carp; |
use Carp; |
7 |
use Log::Log4perl qw(get_logger :levels); |
use Log::Log4perl qw(get_logger :levels); |
|
use locale; |
|
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
22 |
|
|
23 |
my @tree = ({ |
my @tree = ({ |
24 |
# level 0 |
# level 0 |
25 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
26 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
27 |
lookup_v900 => sub { |
lookup_v900 => sub { |
28 |
my ($c,$p) = @_; |
my ($c,$p) = @_; |
31 |
}, |
}, |
32 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
33 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
34 |
have_children => sub { defined($l->{$_[1]}) }, |
have_children => sub { return $l->{$_[1]} }, |
|
child_code => sub { return $_[1] }, |
|
35 |
},{ |
},{ |
36 |
# level 1 |
# level 1 |
37 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
38 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
39 |
lookup_v900 => sub { |
lookup_v900 => sub { |
40 |
my ($c,$p) = @_; |
my ($c,$p) = @_; |
44 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
45 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
46 |
have_children => sub { 0 }, |
have_children => sub { 0 }, |
|
child_code => sub { 0 }, |
|
47 |
)}; |
)}; |
48 |
|
|
49 |
|
You can, however, create recursion with C<have_children_at_level> discussed |
50 |
|
below, but you loose ability to limit tree depth or to specify different |
51 |
|
style for each level. |
52 |
|
|
53 |
Documentation for each element of tree is little sparse, but here it is: |
Documentation for each element of tree is little sparse, but here it is: |
54 |
|
|
55 |
=over 5 |
=over 5 |
91 |
|
|
92 |
=item have_children |
=item have_children |
93 |
|
|
94 |
Returns C<true> or C<false> depending if current node have children. |
Returns children for next iteration of tree generation or undef. |
95 |
|
|
96 |
|
my $next_lvl = $t->{'have_children'}->($code,$v900,$start_code); |
97 |
|
|
98 |
if ($t->{'have_children'}->($code,$v900,$start_code)) { ... } |
=item have_children_at_level |
99 |
|
|
100 |
=item child_code |
Returns children for next iteration and next level. |
101 |
|
|
102 |
Returns child code for next iteration of tree generation. |
my ($level,$next_lvl) = $t->{'have_children_at_level'}->($code,$v900,$start_code); |
103 |
|
|
104 |
my $child_code = $t->{'child_code'}->($code,$v900,$start_code); |
It's safe to return undef just for next level data (C<$next_lvl> in example |
105 |
|
above) to stop recursion. |
106 |
|
|
107 |
=back |
=back |
108 |
|
|
194 |
|
|
195 |
my ($level,$start_code) = @_; |
my ($level,$start_code) = @_; |
196 |
|
|
197 |
|
my $next_level = $level + 1; |
198 |
|
|
199 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
200 |
|
|
201 |
$log->logconfess("need level") unless (defined($level)); |
$log->logconfess("need level") unless (defined($level)); |
232 |
my ($link_start,$link_end) = ('',''); |
my ($link_start,$link_end) = ('',''); |
233 |
|
|
234 |
my $have_children = $tree->[$level]->{'have_children'}->($code,$v900,$start_code); |
my $have_children = $tree->[$level]->{'have_children'}->($code,$v900,$start_code); |
235 |
if ($have_children) { |
|
236 |
($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}); |
if (! $have_children) { |
|
} else { |
|
237 |
$log->debug("# $level doesn't have_children($code,$v900,$start_code)"); |
$log->debug("# $level doesn't have_children($code,$v900,$start_code)"); |
238 |
|
($next_level,$have_children) = $tree->[$level]->{'have_children_at_level'}->($code,$v900,$start_code) if ($tree->[$level]->{'have_children_at_level'}); |
239 |
|
$log->debug("# $level have_children($code,$v900,$start_code) on level $next_level") if ($have_children); |
240 |
|
|
241 |
} |
} |
242 |
|
|
243 |
|
($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}) if ($have_children); |
244 |
|
|
245 |
my $mfn_link = "thes/$mfn.html"; |
my $mfn_link = "thes/$mfn.html"; |
246 |
if (-e "out/$mfn_link") { |
if (-e "out/$mfn_link") { |
247 |
$html .= " " x $level . |
$html .= " " x $level . |
248 |
qq{<li>${link_start}${term}${link_end}}. |
qq{<li>${link_start}<span id="o$mfn">${term}</span>${link_end}}. |
249 |
qq{ <a href="$mfn_link">»</a></li>\n}; |
qq{ <a href="$mfn_link">»</a></li>\n}; |
250 |
} else { |
} else { |
251 |
$log->warn("file 'out/$mfn_link' doesn't exist, skipping"); |
$log->warn("file 'out/$mfn_link' doesn't exist, skipping"); |
272 |
push @{$self->{'show_ids'}}, "id$mfn"; |
push @{$self->{'show_ids'}}, "id$mfn"; |
273 |
} |
} |
274 |
|
|
275 |
$html .= $self->unroll($level+1, $tree->[$level]->{'child_code'}->($code,$v900,$start_code)); |
$html .= $self->unroll($next_level, $have_children); |
276 |
|
|
277 |
$html .= " " x $level . qq{</ul>\n}; |
$html .= " " x $level . qq{</ul>\n}; |
278 |
|
|
304 |
print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; |
print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; |
305 |
close(JS); |
close(JS); |
306 |
|
|
307 |
$log->debug("stored ",@{$self->{'show_ids'}}," shown and ",@{$self->{'hide_ids'}}," hidden elements"); |
$log->debug("stored ",scalar @{$self->{'show_ids'}}," shown and ",scalar @{$self->{'hide_ids'}}," hidden elements"); |
308 |
|
|
309 |
} |
} |
310 |
|
|