#!/perl/bin/perl use strict; use lib 'lib'; require HTML::Template; require Categories; my $hpc = new HTML::Template(Filename=>'tmpl/Categories/per_cat.tmpl'); my $c = new Categories; my %cats = $c->get_cats; print "Content-type: text/html\n\n"; print ""; for(sort keys %cats) { my @child_data; my $fhtml; if( $cats{ $_ }->{ children } ) { for( @{ $cats{ $_ }->{ children } } ) { my @children = _recurse( $_ ); my $html; for( reverse @children ) { $hpc->param ( title => $_->{ title }, descr => $_->{ descr }, children => $html, ); $html = $hpc->output; $hpc->clear_params; } $fhtml.=$html;; } } $hpc->param ( title => $cats{ $_ }->{ title }, descr => $cats{ $_ }->{ descr }, children => $fhtml, ); print $hpc->output; $hpc->clear_params; } print ""; sub _recurse { my $child = shift; my @data; if( ref($child->{ children }) eq 'ARRAY' ) { for( @{ $_->{ children } } ) { push @data, _recurse( $_ ); } } unshift @data,$child; return @data; }