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.

METHODS

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 and complete_arg_elem, if
      metadata has a non-coderef completion or element_completion in its
      argument spec, then will fallback to parent class
      Perinci::Access::Schemeless for metadata.

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.

SEE ALSO

    Riap, Rinci

    Perinci::Access::Schemeless::DBI

