--- trunk2/lib/WebPAC/Tree.pm 2004/09/14 17:07:59 441 +++ trunk2/lib/WebPAC/Tree.pm 2004/10/19 17:43:52 530 @@ -5,7 +5,7 @@ use Carp; use Log::Log4perl qw(get_logger :levels); -use locale; +use YAML; =head1 NAME @@ -23,7 +23,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 +32,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 +45,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 @@ -74,7 +76,7 @@ Lookup value which will be called C<$v900> from now on. - my $v900 = $t->{'lookup_v900'}->($code,$start_code); + my $v900 = $t->{'lookup_v900'}->($code); =item lookup_term @@ -90,15 +92,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); - 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); - 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 @@ -109,24 +114,10 @@ Create new tree object my $tree = new WebPAC::Tree( - dir => './out', - html => 'browse.html', - template => './output_template/tree.tt', - js => 'tree-ids.js', tree => \@tree, log => 'log4perl.conf', ); -C is output directory in which html files and JavaScript files will be -created (think of it as C). - -C is name of output html file. - -C