NAME
Perinci::Access::Schemeless::Hash - Subclass of Perinci::Access::Schemeless which gets lists of entities (and metadata) from hash
VERSION
This document describes version 0.003 of Perinci::Access::Schemeless::Hash (from Perl distribution Perinci-Access-Schemeless-Hash), released on 2016-08-18.
SYNOPSIS
use Perinci::Access::Schemeless::Hash;
my $pa = Perinci::Access::Schemeless::DBI->new(hash => {
'/' => [{v=>1.1}],
'/Foo/' => [{v=>1.1}],
'/Foo/Bar/' => [{v=>1.1}],
'/Foo/Bar/func1' => [{v=>1.1, summary=>"function 1", args=>{}}],
'/Foo/Bar/func2' => [{v=>1.1, summary=>"function 2", args=>{}}],
'/Foo/Bar/Sub/' => [{v=>1.1}],
'/Foo/Baz/' => [{v=>1.1}],
'/Foo/Baz/func3' => [{v=>1.1, summary=>"function 3", args=>{a=>{schema=>["int",{},{}]}}}],
});
my $res;
# will retrieve list of code entities from hash
$res = $pa->request(list => "/Foo/");
# will also get metadata from database
$res = $pa->request(meta => "/Foo/Bar/func1");
# the rest are the same like Perinci::Access::Schemeless
$res = $pa->request(actions => "/Foo/");
DESCRIPTION
This subclass of Perinci::Access::Schemeless gets lists of code entities (currently only packages and functions) from a hash instead of from listing Perl packages on the filesystem. It can also retrieve Rinci metadata from said hash instead of from %SPEC
package variables.
As shown in the example in Synopsis, the hash's keys must be absolute URI path. For package entities, the path must end with slash. The hash's values are arrayref where the first element of the array is the Rinci metadata.
HOW IT WORKS
The subclass overrides get_meta()
and action_list()
. Thus, this modifies behaviors of the following Riap actions: list
, meta
, child_metas
.
new(%args) => OBJ
Aside from its parent class, this class recognizes these attributes:
hash => hash (required)
The hash which contains the URI paths and metadata.
fallback_on_completion => BOOL (default: 0)
If set to true, then for
complete_arg_val
andcomplete_arg_elem
, if metadata has a non-coderefcompletion
orelement_completion
in its argument spec, then will fallback to parent class Perinci::Access::Schemeless for metadata.
METHODS
FAQ
Rationale for this module?
Security: you can preload the hash with only the URLs you want to make available.
I have completion routine for my argument, completion no longer works?
For example, suppose your function metadata is something like this:
{
v => 1.1,
summary => 'Delete account',
args => {
name => {
summary => 'Account name',
completion => sub {
my %args = @_;
my $word = $args{word};
search_accounts(prefix => $word);
},
},
},
}
When this is stored in a file, most serialization formats (JSON included) don't save the code in completion
. If you use Data::Clean::JSON, by default the coderef will be replaced with plain string CODE
. This prevents completion to work e.g. if you request with this Riap request:
{action=>'complete_arg_val', uri=>..., arg=>'name'}
One solution is to fallback to its parent class Perinci::Access::Schemeless (which reads metadata from Perl source files) for meta request when doing completion. To do this, you can set the attribute fallback_on_completion
.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Perinci-Access-Schemeless-Hash.
SOURCE
Source repository is at https://github.com/perlancar/perl-Perinci-Access-Schemeless-Hash.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Access-Schemeless-Hash
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
Perinci::Access::Schemeless::DBI
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.