The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


HTML::TreeStructured - Perl extension for generating tree structured HTML


        use HTML::TreeStructured;

        ### Describe tree via collection of Node and its properties

        ### Method 1: Via ArrayRef
        ### Node can be a string or '/' concatenated strings to show ancestry
        ### Properties are name/value pairs

        my $tree1 = [
                ['/aaa',        color => 'green'],
                ['/aaa/bbb'     mouseover => 'This is addl info'],
                ['/aaa/ccc',    color => 'red', active => 0]

        ### Method 2: Via Hashref

        my $tree2 = {
                aaa => {
                        color => 'green',
                        bbb   => {
                                mouseover => 'This is addl info',
                        ccc   => {
                                color   => 'red',
                                active  => 0,

        Interpreted Node Properties:

        color           = Color of the node name
        mouseover       = Mouse Over text for the node (Info image is displayed next to node)
        active          = 0 would cause strike thru on node
        highlight       = color code used for marker highlight of node
        url             = URL to hyperlink the node
        tooltip         = popup when mouse is over the link (together with url) (See HTML::Tooltip::Javascript)
        closed          = 1 if node be closed on default display (default, all nodes are open)
        comment         = Text to display next to node in bold
        weight          = A numeric value on node which will be used for sorting node position in at sibling level
                          (Default, nodes are sorted in ascending order per dictionary order)

        ### Now get HTML equivalent for the tree
        ### The associated JavaScript for nodes close/open and ExpandAll/CollapseAll is generated alongside

        $tree_html = HTML::TreeStructured->new(
                name         => 'tree_name',
                image_path   => '/images/',
                data         => $tree1,
                title        => "My Tree",
                title_width  => 300,
                level        => {},     ### If scalar, close BEYOND this depth. Depth start at 0.
                                        ### If Hash, close for depths specified in keys

        ### The same module can be used to generate FAQ - see "examples/faq.cgi"


Ramana Mokkapati, <> 10 May 2004

I have been using HTML tables for structuring HTML presentation. After seeing HTML::PopupTreeSelect from Sam Tregar <> I liked the idea of stylesheets to indent HTML and adapted the same.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.