The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::Wizard

DESCRIPTION

This plugin provides same functionallity like Catalyst::Plugin::Wizard but in some more flexible and correct way.

SYNOPSIS

Plain:

    # create new wizard
    my $wizard = Catalyst::Wizard->new( $c );

    # add steps for that wizard
    $wizard->add_steps( -detach => '/user/login', '/user/login_submit' );
    $wizard->add_steps( -last => -redirect => '/user/logout' );

    # mark step to go to next step after this action
    $wizard->goto_next;

    # perform step (calls redirect/detach/forward/whatever)
    $wizard->perform_step;

With Catalyst::Action::Wizard and CatalystX::Wizarded:

    # just appending step
    $c->wizard( '/append_this_step' );

    # just marking as goto_next
    # NOTE: wizards can either 'die' after this (like in detach)
    # or just mark wizard as 'goto_next'
    $c->wizard->goto_next;

    # adding -last action in wizard (only one added, other
    # '-last' actions ignored). synonym for -default in C::P::W
    $c->wizard( -last => -redirect => '/logout' )->goto_next;

    # make step back (in case some errors happen)
    $c->wizard->back_to( -redirect => '/append_this_step' );

    # stash into wizard
    my $wizard_stash = $c->wizard->stash;
    $wizard_stash->{parameters} = { %{ $c->req->params } };

    if ( $c->have_wizard ) {
        $c->wizard->goto_next;
    }

In TT: [% c.wizard.id_to_form IF c.have_wizard %]

    [%  # INCORRECT! may (and will) cause errors!
        c.wizard.id_to_form %]

In real application: See there.

NOTES

This module is for general wizard'ed actions. It may be used with CatalystX::Wizarded and along in separate realization (for example in Controller base)

You can use it for creating mulitpart actions (wizards) in following cases:

  • When you need to move some items into another folder, you may:

    • keep current folders select in session (can have difficulties with duplicate selecting of same folder)

    • use it as wizard and keep that info in wizard's stash

AUTHORS

Pavel Boldin (), <davinchi@cpan.ru>

METHODS

new($c [, $wizard_id ])

Create wizard object, either new (empty, missing or equal to 'new' $wizard_id) or loaded from Catalyst::Wizard::wizard_storage.

Note that $wizard_id can also contain step number (splited from wizard_id by _).

Making steps from input of @args, passed from add_steps. You can redefine following functions to make it behave different:

$self->_get_default_flags returns default flags

$self->_check_flags( \@args, \@new_steps, $step_ref, $flags ) to check flags

$self->_is_force_add_step( \@args, \@new_steps, $step_ref, $flags ) should return true if step should added with force (e.g. even if same already exists)

$self->_handle_$1_item( \@args, $step_ref, $flags ) to handle '-$1' items in \@args

$wizard->add_steps( @args )

Add steps from @args.

@args is an array of path for steps with specification of each step:

(-redirect => 'path') or 'path'

Redirect to path. If '-redirect' is given, then no action wizard id will be append to the redirect URL. Use this for last actions in wizard.

You can append any query parameters to 'path'.

(-detach => [ 'path', @step_args ]) or (-detach => 'path')

Detaches to path.

-last => [ -forward | -detach | -redirect ] => 'path'

Last step in wizard. Only one (first) '-last' step will be added, all others will be ignored. Note that -last => step should be last in ->add_steps call, elsewhere add_steps will throw exception.

$wizard->next_step([ $shift_count ])

Shift $shift_count steps, or 1 if no $shift_count is given.

$wizard->uri_for_next

Returns URI for next step in wizard (if that step is '-redirect').

$wizard->goto_next

Mark wizard step to be performed.

If $wizard->{die_for_goto} is true will act like detach, throwing $GOTO_NEXT exception.

$wizard->back_to( [ -redirect | -detach | -forward => ] 'path' )

Return to step 'path' which will be performed by original step type or by step type you set as argument.

Will do nothing if none 'path' step if found.

$wizard->perform_step( $c )

Perform step. Function to call when step performing should be done. (called, for instance, in Catalyst::Action::Wizard _END)

$wizard->stash

Stash accessor.

$wizard->id_to_form

Get wizard id as <input> tag for <FORM>.

$wizard->load( $c )

Loads wizard (by default just installs stash).

$wizard->save( $c )

Save wizard into wizard_storage.

If $c have wizard_storage it will be called with two arguments: wizard id and wizard instance.

Elsewhere default (session) storage will be used.

Catalyst::Wizard->wizard_storage( $c, $wizard_id )

Loads $wizard_id from wizard_storage, if can.

First checked if $c can 'wizard_storage'. If yes -- it will be called, else default (session) storage will be used.

Note also that this functions purges old wizards in session.

$wizard->info and $wizard->short_info

Prints current wizard info.

short_info omits steps on print.

Note that info will skip all the inherited methods ($self->SUPER::info call).

SEE ALSO

Catalyst::Plugin::Continuation, Catalyst Plugin Wizard (DEPRECATED)

AUTHOR

Pavel Boldin <davinchi@cpan.org> for REG.RU.