This function is basically a helper for writing undoable (as well as
transactional, dry-runnable, and idempotent) function. This function will
generate a function with the basic structure, and you supply the
'business-logic' bits through the 'build_steps' and 'steps' arguments.
This generator helps because writing an undoable and transactional function is a
bit tricky. This helper shields function writer from having to interact with the
transaction manager, or writing the steps loop, or writing the rollback
mechanism on his/her own, and just focus on writing the actual steps.
Some notes:
=over
=item *
Though it generally should not die(), generated function might still die,
there is no big eval{} loop inside. But this is usually OK since a function
wrapper (like Perinci::Sub::Wrapper) has this loop.
=back
For examples, see Setup::* Perl modules.
Arguments ('*' denotes required arguments):
=over 4
=item * B<args> => I<hash> (default: {})
Specification for generated function's arguments.
This is just like the metadata property 'args'.
=item * B<build_steps>* => I<code>
Code to build steps.
This is the code that should build the steps. Code will be given the whole
function's arguments and should return an enveloped response. If response is not
a success one, it will be used as the function's response. Otherwise, code
should return the steps (an array). By convention, each step should be an array
like this: [NAME, ...] where the first element is the step name and the rest are
step arguments.
=item * B<description>* => I<śtr>
Generated function's description.
=item * B<hook_check_args>* => I<code>
Code to check function's arguments.
This is a (temporary?) hook to allow the generated function to check its
arguments. This should later be mostly unnecessary when Perinci::Sub::Wrapper
already integrates with Data::Sah to generate argument-checking code from
schema.
Code is given arguments as a I<hashref> to be able to modify them (e.g. set
defaults, etc) and should return an enveloped response. If response is not a
success one, it will be used as the function's response.
=item * B<name>* => I<str>
Fully qualified function name.
=item * B<steps>* => I<hash>
Steps specification.
=item * B<summary>* => I<str>
Generated function's summary.
=item * B<trash_dir> => I<bool> (default: 0)
Whether function needs undo trash directory.
=item * B<tx> => I<hash> (default: {})
Whether function is transactional.
Valid values include {use=>1} (meaning function can use transaction and will
utilize it if given '-tx' special argument), {req=>1} (meaning function always
require '-tx' and will return error response if not given it). Otherwise
function will not use transaction, undo data will be passed to function via
'-undoI<data' special argument and returned by function in 'undo>data' result
metadata.
=back
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.
=head1 AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
=head1 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.
=cut
Keyboard Shortcuts
Global
s
Focus search bar
?
Bring up this help dialog
GitHub
gp
Go to pull requests
gi
go to github issues (only if github is preferred repository)