Perinci::Access::InProcessUse Rinci access protocol (Riap) to access Perl code | |
Download |
Perinci::Access::InProcess Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Steven Haryanto
- Publisher web site:
- http://search.cpan.org/~sharyanto/
Perinci::Access::InProcess Tags
Perinci::Access::InProcess Description
Perinci::Access::InProcess is a Perl class that implements Rinci access protocol (Riap) to access local Perl code. This might seem like a long-winded and slow way to access things that are already accessible from Perl like functions and metadata (in %SPEC). Indeed, if you do not need Riap, you can access your module just like any normal Perl module.But Perinci::Access::InProcess offers several benefits:- Custom location of metadata- Metadata can be placed not in %SPEC but elsewhere, like in another file or even database, or even by merging from several sources.- Function wrapping- Can be used to convert argument passing style or produce result envelope, so you get a consistent interface.- Transaction/undo- This class implements Riap::Transaction. See Perinci::Access::InProcess::Tx for more details.SYNOPSIS # in Your/Module.pm package My::Module; our %SPEC; $SPEC{mult2} = { v => 1.1, summary => 'Multiple two numbers', args => { a => { schema=>'float*', req=>1, pos=>0 }, b => { schema=>'float*', req=>1, pos=>1 }, }, examples => , }; sub mult2 { my %args = @_; ; } $SPEC{multn} = { v => 1.1, summary => 'Multiple many numbers', args => { n => { schema=>, req=>1, pos=>0, greedy=>1 }, }, }; sub multn { my %args = @_; my @n = @{$args{n}}; my $res = 0; if (@n) { $res = shift(@n); $res *= $_ while $_ = shift(@n); } return ; } 1; # in another file use Perinci::Access::InProcess; my $pa = Perinci::Access::Process->new(); # list all functions in package my $res = $pa->request(list => '/My/Module/', {type=>'function'}); # -> ] # call function my $res = $pa->request(call => '/My/Module/mult2', {args=>{a=>2, b=>3}}); # -> # get function metadata $res = $pa->request(meta => '/Foo/Bar/multn'); # -> Product's homepage
Perinci::Access::InProcess Related Software