NAME Setup::Multi - Setup using a series of other setup functions VERSION version 0.07 SYNOPSIS use Setup::Multi 'setup_multi'; use Setup::File::Dir 'setup_dir'; use Setup::File 'setup_file'; # simple usage (doesn't save undo data) my $res = setup_multi subs => [ setup_dir => [{name=>'/foo', should_exist=>1}, {name=>'/foo/bar', should_exist=>1}, {name=>'/foo/bar/baz', should_exist=>1}], setup_file => {name=>"/foo/bar/baz/qux", should_exist=>1}, ]; die unless $res->[0] == 200 || $res->[0] == 304; # perform setup and save undo data (undo data should be serializable) $res = setup_multi ..., -undo_action => 'do'; die unless $res->[0] == 200 || $res->[0] == 304; my $undo_data = $res->[3]{undo_data}; # perform undo $res = setup_multi ..., -undo_action => "undo", -undo_data=>$undo_data; die unless $res->[0] == 200 || $res->[0] == 304; DESCRIPTION This module uses Log::Any logging framework. This module has Rinci metadata. FAQ When to use coderef (routine refs) or string (routine names) in subs? Since the routine name is included in undo data, use string to make it easily serializable. SEE ALSO Setup FUNCTIONS setup_multi(%args) -> [status, msg, result, meta] Setup using a series of other setup functions. Accept a list of setup subroutine name and arguments, or coderefs, and call them each sequentially as steps. If one step fails, the whole steps will be rolled back using the undo data. If all steps succeed, return the concatenated undo data from each step. This function is declared as supporting the 'undo' and 'dry_run' features, so all setup functions mentioned in 'subs' argument must also support those two features (but this is not currently checked). Arguments ('*' denotes required arguments): * subs* => *array* List of setup subroutine (names/refs) and arguments. Setup subroutine can be a string (its name) or a coderef. If subroutine is a non-qualified name (i.e., foo instead of Package::foo), it will be qualified with caller's package. Argument can be a single hashref or arrayref (of hashrefs). Example, if subs are: [ 'Pkg::func1' => \%args, 'func2' => [\%args2, \%args3, \%args4], \&func3 => [\%args5], sub{...} => \%args6, ] then the subs which will be called: Pkg::func1->(%args); func2->(%args2); func2->(%args3); func2->(%args4); func3(%args5); (sub{...})->(%args6); Return value: Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information. AUTHOR Steven Haryanto COPYRIGHT AND LICENSE This software is copyright (c) 2012 by Steven Haryanto. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.