--- trunk2/lib/WebPAC/Tree.pm 2004/09/14 20:57:58 443 +++ trunk2/lib/WebPAC/Tree.pm 2004/09/15 22:36:23 454 @@ -5,7 +5,6 @@ use Carp; use Log::Log4perl qw(get_logger :levels); -use locale; =head1 NAME @@ -23,7 +22,7 @@ my @tree = ({ # level 0 - code_arr => sub { @{$l->{$_[0]}} }, + code_arr => sub { @{$_[0]} }, filter_code => sub { shift }, lookup_v900 => sub { my ($c,$p) = @_; @@ -32,11 +31,10 @@ }, lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, - have_children => sub { defined($l->{$_[1]}) }, - child_code => sub { return $_[1] }, + have_children => sub { return $l->{$_[1]} }, },{ # level 1 - code_arr => sub { @{$l->{$_[0]}} }, + code_arr => sub { @{$_[0]} }, filter_code => sub { shift }, lookup_v900 => sub { my ($c,$p) = @_; @@ -46,9 +44,12 @@ lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, have_children => sub { 0 }, - child_code => sub { 0 }, )}; +You can, however, create recursion with C discussed +below, but you loose ability to limit tree depth or to specify different +style for each level. + Documentation for each element of tree is little sparse, but here it is: =over 5 @@ -90,15 +91,18 @@ =item have_children -Returns C or C depending if current node have children. +Returns children for next iteration of tree generation or undef. + + my $next_lvl = $t->{'have_children'}->($code,$v900,$start_code); - if ($t->{'have_children'}->($code,$v900,$start_code)) { ... } +=item have_children_at_level -=item child_code +Returns children for next iteration and next level. -Returns child code for next iteration of tree generation. + my ($level,$next_lvl) = $t->{'have_children_at_level'}->($code,$v900,$start_code); - 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 +above) to stop recursion. =back @@ -190,6 +194,8 @@ my ($level,$start_code) = @_; + my $next_level = $level + 1; + my $log = $self->_get_logger(); $log->logconfess("need level") unless (defined($level)); @@ -226,12 +232,16 @@ my ($link_start,$link_end) = ('',''); my $have_children = $tree->[$level]->{'have_children'}->($code,$v900,$start_code); - if ($have_children) { - ($link_start,$link_end) = (qq{},qq{}); - } else { + + if (! $have_children) { $log->debug("# $level doesn't have_children($code,$v900,$start_code)"); + ($next_level,$have_children) = $tree->[$level]->{'have_children_at_level'}->($code,$v900,$start_code) if ($tree->[$level]->{'have_children_at_level'}); + $log->debug("# $level have_children($code,$v900,$start_code) on level $next_level") if ($have_children); + } + ($link_start,$link_end) = (qq{},qq{}) if ($have_children); + my $mfn_link = "thes/$mfn.html"; if (-e "out/$mfn_link") { $html .= " " x $level . @@ -262,7 +272,7 @@ push @{$self->{'show_ids'}}, "id$mfn"; } - $html .= $self->unroll($level+1, $tree->[$level]->{'child_code'}->($code,$v900,$start_code)); + $html .= $self->unroll($next_level, $have_children); $html .= " " x $level . qq{\n};