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


CatalystX::Menu::Tree - Generate Catalyst application menus


 my $tree = CatalystX::Menu::Tree->new(
    context => $c,
    namespaces => [ $c->namespace ],
    filter => sub {
        my ($c, %action) = @_;
        # return the list of k/v pairs that meet criteria
    menupath_attr => 'MenuPath',
    menutitle_attr => 'MenuTitle',
    add_nodes => [
            menupath => '/Bargains',
            menutitle => 'Cheap stuff',
            uri => '/products/cheap',
            menupath => '/Returns',
            menutitle => 'Return a product',
            uri => '/products/returns',


Builds the tree used by CatalystX::Menu::Suckerfish to construct an HTML UL element for use as a degradable, CSS-styled menu or horizontal navbar.

Catalyst actions with the Private attribute are excluded from the tree.

Names the action attribute that contains the menu path:

 menupath_attr => 'MenuPath'

 # and in your controller:

 sub foobar :Local
 :MenuTitle('Foobar and stuff')
 { ... }

Only actions with the menupath_attr attribute are processed. This attribute's value determines where the action's menu item is placed in the menu structure (HTML UL).

Depending on the attribute values collected from the processed actions, there may be menu items containing only text. If you want a link to a landing page, for example, instead of text, include an action for the landing page with the appropriate MenuPath attribute in your controller, or add an entry manually with the add_nodes parameter.

The menutitle_attr attribute will be used to add the HTML title attribute to each list item. This should result in a balloon text with the title when the pointing device hovers over each list item.

Suckerfish menus:

Superfish jQuery menu plugin:


new( %params )

Return an instance of this class.



The Catalyst application context (usually $c or $ctx in your controller).

The action attribute that contains the menu tree path to the menu item to be inserted for each action.

The action attribute that contains text describing each action. This text is applied as a "title" attribute to the menu item's HTML container so that a tooltip will be displayed when the pointer hovers over the menu item.

This text can be used anywhere in your application where a description of an action is useful.


A reference to an array of action namespaces from which actions with the menupath_attr attribute should be collected.


A reference to a subroutine that takes the Catalyst context and a hash of action name/action object and returns the name/action pairs that meet certain criteria.


A list of hash references containing data defining arbitrary menu items to be merged into the menu tree.



Create and store a reference to a hash containing a tree of menu data.


Build a hash of Catalyst::Action objects.


David P.C. Wollmann <>


This is brand new code, so use at your own risk.


Copyright 2009 by David P.C. Wollmann

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.