Sub::Spec::Wrapper - Wrap subroutine to its implement Sub::Spec clauses
version 0.05
use Sub::Spec::Wrapper qw(wrap_sub); my $sub = wrap_sub(sub => sub {die "test\n"}, spec=>{}); my $res = $sub->(); # [500, "Sub died: test"]
NOTICE: This module and the Sub::Spec standard is deprecated as of Jan 2012. Rinci is the new specification to replace Sub::Spec, it is about 95% compatible with Sub::Spec, but corrects a few issues and is more generic. Perinci::* is the Perl implementation for Rinci and many of its modules can handle existing Sub::Spec sub specs.
Perinci::*
WARNING: PRELIMINARY VERSION, NOT EVERYTHING DESCRIBED IS IMPLEMENTED
This module provides wrap_sub() that implements/utilizes many spec clauses, like args, result, timeout, etc, via wrapping.
args
result
timeout
This module uses Log::Any for logging.
None are exported, but they are exportable.
Wrap subroutine to its implement Sub::Spec clauses.
Will wrap subroutine with codes that implement Sub::Spec clauses, like ~timeout~ (using Perl's eval block), ~args~ (using Sah schema), etc. Will bless subroutine (into ~Sub::Spec::Wrapped~) to mark that the subroutine has been wrapped.
Will not wrap again if input subroutine has already been wrapped (blessed), unless ~force~ argument is set to true.
Arguments (* denotes required arguments):
*
force => bool (default 0)
0
Whether to force wrap again even when sub has been wrapped.
spec* => hash
The sub spec.
sub* => code
The code to wrap.
Sub::Spec
Steven Haryanto <stevenharyanto@gmail.com>
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.
To install Sub::Spec::Wrapper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Spec::Wrapper
CPAN shell
perl -MCPAN -e shell install Sub::Spec::Wrapper
For more information on module installation, please visit the detailed CPAN module installation guide.