NAME

Mojolicious::Plugin::Fondation::Workflow - Workflow plugin — state machines with UI and authorization for Fondation

VERSION

version 0.01

SYNOPSIS

# In your Fondation config
plugin 'Fondation' => {
    dependencies => ['Fondation::Workflow'],
};

# With a workflow YAML file
plugin 'Fondation' => {
    dependencies => ['Fondation::Workflow'],
    'Fondation::Workflow' => {
        workflows => {
            approval => 'share/workflows/approval.yaml',
        },
    },
};

# In a controller
my $wf = $c->workflow('approval');
my $wf = $c->workflow('approval', $resource_id);

# With context
my $wf = $c->workflow('approval', undef, { user_id => 42 });

# Or as a hashref
my $wf = $c->workflow({
    type        => 'approval',
    resource_id => $id,
    context     => { user_id => 42 },
});

DESCRIPTION

Fondation::Workflow wraps Workflow (the CPAN state-machine module) for Mojolicious::Plugin::Fondation. It provides:

Dependency graph

Workflow declares NO hard dependencies (dependencies => []). Soft ordering: after => ['Fondation::Model::DBIx::Async'].

This means Workflow can boot without a database backend — essential for wizards like Fondation::Setup that use Workflow::Persister::File. When Fondation::Model::DBIx::Async IS present, the after hint ensures Workflow loads after it, so the models default (Workflow, WorkflowHistory) is picked up by Action::DBIx.

NAME

Mojolicious::Plugin::Fondation::Workflow - State-machine workflows with UI, authorization and hooks for Fondation

VERSION

version 0.02

CONFIGURATION

workflows

A hashref mapping workflow types to YAML file paths:

'Fondation::Workflow' => {
    workflows => {
        approval => 'share/workflows/approval.yaml',
    },
},

Each YAML file follows the Workflow format (type, initial_state, state, action) with Fondation extensions:

persister

DBI persister configuration for DB-backed workflows:

'Fondation::Workflow' => {
    persister => {
        dsn      => 'dbi:SQLite:dbname=data/app.db',
        user     => '',
        password => '',
    },
},

The persister name is always FondationWorkflow. If no DSN is configured, the plugin logs a warning but does not die — file-backed workflows can still operate.

HELPERS

$c->workflow($type, $resource_id?, $context?)

Returns a Mojolicious::Plugin::Fondation::Workflow::Proxy wrapping a Workflow instance.

Can also be called with a single hashref:

$c->workflow({ type => 'approval', resource_id => $id, context => {...} });

CROSS-PLUGIN RELATIONS

During fondation_finalyze, if Fondation::User is present in the registry, a belongs_to relation is added:

WorkflowHistory -> belongs_to -> User (foreign.id = self.user_id)

This makes $history_entry->user available in DBIC queries without requiring Workflow to hard-depend on the User plugin.

SEE ALSO

AUTHOR

Daniel Brosseau dab@cpan.org

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Daniel Brosseau.

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

AUTHOR

Daniel Brosseau dab@cpan.org

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Daniel Brosseau.

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