NAME

UI::Dialog::Util::MenuControl - Produces a simple progress bar

SYNOPSIS

use UI::Dialog::Util::MenuControl;

my $tree = {
                title       =>  'Conditinal behaviour',
                entries     =>  [
                                    {
                                        title       =>  'entry A (prework for B)',
                                        function    =>  \&doA,
                                        condition   =>  undef,
                                    },
                                    {
                                        title       =>  'entry B',
                                        function    =>  \&doB,
                                        condition   =>  \&aWasCalled,
                                    },
                                    {
                                        title       =>  'reset A (undo prework)',
                                        function    =>  \&resetA,
                                        condition   =>  \&aWasCalled,
                                    },
                                    {
                                        title       =>  'has also submenus',
                                        entries     =>  [
                                                            {
                                                                title   =>  'sub b 1',
                                                            },
                                                            {
                                                                title   =>  'sub b 2',
                                                            },
                                                        ]
                                    },
                
                                ],
            };



my $menu_control = UI::Dialog::Util::MenuControl->new( menu => $tree );

$menu_control->run();

To build a menu, you can nest nodes with the attributes

 title
 function    a reference to a function.
 condition   a reference to a function given a boolean result whether to display the item or not
 entries     array ref to further nodes
 context     a 'self" for the called function
 
    
    ... 
    
    our $objA = Local::UsecaseA->new();
    
    
    my $tree = {
                    title       =>  'Conditinal behaviour',
                    entries     =>  [
                                        {
                                            title       =>  'entry B',
                                            function    =>  \&doB,
                                            condition   =>  \&Local::UsecaseA::check,
                                            context     =>  $objA,
                                        },
                    
                                    ],
                };

In this example an object objA has been loaded before and provides a check() method.
To run this check method in $objA context, you can tell a context to the node.

What does the absolute same:

    my $tree = {
                    title       =>  'Conditinal behaviour',
                    entries     =>  [
                                        {
                                            title       =>  'entry B',
                                            function    =>  \&doB,
                                            condition   =>  sub{ $objA->check() },
                                        },
                    
                                    ],
                };

    

Please consult the example files for more.

DESCRIPTION

It is an OO class to render a Dialog menu by a tree of array and hashes with specific form. a shell. It does not use curses and has no large dependencies.

REQUIRES

Carp

METHODS

new

$obj = UI::Dialog::Util::MenuControl->new( menu => $tree );

parameters

context             context object wich can be used for all called procedures (self)
backend             UI::Dialog Backend engine. E.g. CDialog (default), GDialog, KDialog, ...
backend_settings    Values as hash transfered to backend constructor
menu                Tree structure (see example above)

dialog

$obj->dialog();

Holds the backend dialog system.

run

$obj->run();

Main loop method. Will return when the user selected the last exit field.

showMenu

$obj->showMenu();

Main control unit, but usually called by run(). If you call it by yourself, you have to build your own loop around.

AUTHOR

Andreas Hernitscheck ahernit(AT)cpan.org

LICENSE

You can redistribute it and/or modify it under the conditions of LGPL.