use UI::State; my $state = UI::State->new; # Define the states we will use $state->add_states( qw/ menu new open options / ); $state->state( menu => { # Class that handles this state class => 'My::UI::Menu', # States allowed to jump to. The 'exit' # state is always implicitly available. next => [qw/ new open options exit /], }); $state->state( new => { class => 'My::UI::New', next => [qw/ menu exit /], }); $state->state( open => { class => 'My::UI::Open', next => [qw/ menu exit /], }); $state->state( options => { class => 'My::UI::Options', next => [qw/ menu /], }); # Error! State 'foo' was not declared in add_states() $state->state( foo => { class => 'My::UI::Foo', next => [qw/ menu exit /], }); $state->state( new => { class => 'My::UI::New', # Error! State 'bar' was not declared in add_states() next => [qw/ menu bar exit /], }); # Start running from 'menu' $state->run( 'menu' );