GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
OpenXPKI::Server::API2::EasyPlugin(3) User Contributed Perl Documentation OpenXPKI::Server::API2::EasyPlugin(3)

OpenXPKI::Server::API2::EasyPlugin - Define an OpenXPKI API plugin

To define a new API plugin simply say:

    package OpenXPKI::Server::API2::Plugin::MyTopic::MyActions;
    use OpenXPKI::Server::API2::EasyPlugin;

    command "aaa" => {
        # parameters
    } => sub {
        # actions
        ...
        $self->api->another_command();
        ...
    };

This will modify your package as follows:

  • imports "Moose" (i.e. adds "use Moose;" so you don't have to do it)
  • provides the "command" keyword (just an imported sub really) to define API commands
  • applies the Moose role OpenXPKI::Server::API2::EasyPluginRole
  • applies the Moose metaclass role (aka. "trait") OpenXPKI::Server::API2::EasyPluginMetaClassTrait

It currently does not seem to be possible to set a custom base class for your plugin, but you can instead easily add another role to it:

    package OpenXPKI::Server::API2::Plugin::MyTopic::MyActions;
    use OpenXPKI::Server::API2::EasyPlugin;

    with "OpenXPKI::Server::API2::Plugin::MyTopic::Base";

The following functions are imported into the package that uses "OpenXPKI::Server::API2::EasyPlugin".

Define an API command including input parameter types.

Example:

    command "givetheparams" => {
        name => { isa => 'Str', matching => qr/^(?!Donald).*/, required => 1 },
        size => { isa => 'Int', matching => sub { $_ > 0 } },
    } => sub {
        my ($self, $po) = @_;

        $po->name("The genious ".$po->name) if $po->has_name;

        if ($po->has_size) {
            $self->some_helper($po->size);
            $po->clear_size; # unset the attribute
        }

        $self->process($po);
    };

Note that this can be written as (except for the dots obviously)

    command(
        "givetheparams",
        {
            name => ...
            size => ...
        },
        sub {
            my ($self, $po) = @_;
            return { ... };
        }
    );

You can access the API via "$self->api" to call another command.

Parameters

  • $command_name - name of the API command
  • $params - HashRef containing the parameter specifications. Keys are the parameter names and values are HashRefs with options.

    Allows the same options as Moose's has keyword (i.e. isa, required etc.) plus the following ones:

"matching" - Regexp or CodeRef that matches if TRUE value is returned.

You can use all Moose types (Str, Int etc) plus OpenXPKI's own types defined in OpenXPKI::Server::API2::Types ("OpenXPKI::Server::API2" automatically imports them).

$function - CodeRef with the command implementation. On invocation it gets passed two parameters:
  • $self - the instance of the command class (that called "api").
  • $po - a parameter data object with Moose attributes that follow the specifications in $params above.

    For each attribute two additional methods are available on the $po: A clearer named "clear_*" to clear the attribute and a predicate "has_*" to test if it's set. See "Predicate and clearer methods" in Moose::Manual::Attributes if you don't know what that means.

2022-05-14 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.