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

NAME

Method::Workflow::Base - Base class for workflow elements

DESCRIPTION

You must subclass this object when defining a new workflow element class.

OVERRIDABLE METHODS

$self->init( %params )

Called by new() after construction as a hook for you to use.

@list = $self->required()

Returns a list of parameters that should be required for construction. By default it returns 'method' and 'name'.

@results = $self->run( $root )

Default defenition:

    sub run {
        my ( $self, $root ) = @_;
        $self->method->( $root, $self );
    }

Should handle the work for this element and return its results. In most cases this simply runs the codeblock provided to the keyword at construction. This method is not responsible for child elements.

$self->handle_error( @errors )

How to handle errors that are encountered.

Default implementation:

    sub handle_error {
        my $owner = shift;

        $owner->handle_error( @_ )
            if $owner->can( 'handle_error' )
           and $owner->can( 'handle_error' ) != \&handle_error;

        stack_pop( $owner );
        die @_;
    }

HOOKS

Hooks give you the opportunity to manipulate the metadata before any workflow elements of an item are run. They also let you run code after all elements have run.

$class->import_hook( $caller, $specs )

Override this if you need to do something on import. The first argument is the original caller's class. The second argument is the specs hash that comes from Exporter::Declare. Any orguments from import that start with ':' will be listed here (including import lists).

($name => $coderef, ...) = $self->pre_run_hook( %existing )

Should return a list of name => coderefs that will be run before all children when run_workflow() is called on an element that has children of your type. Name is mandatory, you can check the params to ensure the hook is not already installed.

Hook will be run with the following parameters:

    $hook->(
        owner => $owner,
        meta  => $meta,
        root  => $root,
    );
(name => $coderef, ...) = $self->post_run_hook( %existing )

Should return a list of name => coderefs that will be run after all children when run_workflow() is called on an element that has children of your type. Name is mandatory, you can check the params to ensure the hook is not already installed.

Hook will be run with the following parameters:

    $hook->(
        owner => $owner,
        meta  => $meta,
        root  => $root,
        out   => \@out,
    );

The 'out' parameter contains a reference to the array of items that will be returned by run_workflow, giving you a chance to add/remove items.

AVAILABLE METHODS

$self->new( %params )

Create a new instance.

$self->run_workflow( $owner, $root )

Run the workflow element and children.

Defaults:

    $owner ||= caller();
    $root ||= $owner;
$self->parent_trace()

Returns a stringified trace of the element and it's parents.

$self->display()

Returns the display string used te represent this item in a trace.

$self->observe()

Mark this instance as observed so that it does not generate a warning in debug mode.

$self->DESTROY

In debug mode destruction will issue a warning when the item is destroyed without having been observed. This is toggled to true when run_workflow() is called.

EXPORTS

$KEYWORD

Whatever keyword you define with the 'keyword' keyword will be exported as a construction shortcut to define elements of this type declaratively.

run_workflow()

This will be exported whenever it is not already present in the importing class.

start_class_workflow()

Used to start a class-level workflow.

end_class_workflow()

Used to end a class-level workflow.

debug( $bool )

Turns debug mode on and off (Can not be used as a method).

NOTE ON IMPORT

Do not override import() or _import().

If you need to do something on import you should override import_hook().

FENNEC PROJECT

This module is part of the Fennec project. See Fennec for more details. Fennec is a project to develop an extendable and powerful testing framework. Together the tools that make up the Fennec framework provide a potent testing environment.

The tools provided by Fennec are also useful on their own. Sometimes a tool created for Fennec is useful outside the greator framework. Such tools are turned into their own projects. This is one such project.

Fennec - The core framework

The primary Fennec project that ties them all together.

AUTHORS

Chad Granum exodist7@gmail.com

COPYRIGHT

Copyright (C) 2010 Chad Granum

Method-Workflow is free software; Standard perl licence.

Method-Workflow is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.