NAME

Net::Respite::Base - base class for Respite related modules that can be used from a server or commandline

SYNOPSIS

package Foo;
use base qw(Net::Respite::Base);
my $meta = {lib_dirs => 1, dispatch_type => 'cache'};
sub api_meta { $meta }

package Foo::Bar;
sub somecall__meta { {desc => 'A method'} }
sub somecall {
    my ($self, $args) = @_;
    return {foo => 1};
}

my $f = Foo->new;
my $data = $f->bar_somecall;


#-----------------#

package Foo;

use strict;
use warnings;
use base qw(Net::Respite::Base);

# sub api_meta { {} }  # optional configuration
sub api_meta {
    return shift->{'api_meta'} ||= { # vtable cached here
        methods => {
            foo => 'bar', # alias a method
            baz => sub { }, # custom
        },
        namespaces => {
            foo_child => 1,
            bar_child => 1,
        },
        lib_dirs => {
            $dir => 1, # load all .pm files as namespaces
        },
    };
}

sub foo__meta { {} }
sub foo {
    my ($self, $args) = @_;
    $self->validate_args($args);

    return {...};
}

my $obj = Foo->new;
$obj->run_method("foo", $args);
# will do logging and utf8 munging - used by Net::Respite::Server or Net::Respite::CommandLine

$obj->foo($args); # no logging or utf8 munging


###----------------------------------------------------------------###

use Net::Respite::Base;
my $obj = Net::Respite::Base->new({
    api_meta => {
        methods => {
            foo => 'bar',
        },
        namespaces => {
            Foo => {},
        },
    },
});

Respite_META

The module can specify a api_meta override, or a api_meta hashref can be passed to Net::Respite::Base->new. The following keys are honored from api_meta.

METHOD NAME RESOLUTION

TODO - document how we go from an Respite method name to its corresponding location.

Talk about builtins, methods overrides, namespaces, lib_dirs, and the __ prefix and __meta suffix.

METHODS

This is an outdated list from the _Respite.pm import.

The following methods are normally set when called from Net::Respite::Server or Net::Respite::CommandLine. If Net::Respite::Base is used outside of these mediums, then the corresponding $self->{'propertyname'} values must be set during initialization in order to use these methods. If namespaces are used, the child class will typically fail back and look at the ->base->method value if necessary.

RESPONSE

Responses from called methods should typically be hashrefs of data. These responses will be encoded by the appropriate system. Typically the encoding will be json (during Net::Respite::Server), but possibly other forms (Perl, JSON, YAML, CSV) such as during Net::Respite::CommandLine.

Methods can also return psgi style responses though this is typically more rare. (It allows for other encodings or page displays).

When a hashref is returned the following keys may also be returned to give additional information to the transport layer: