|
NAMEOpenXPKI::Server::API2::EasyPlugin - Define an OpenXPKI API pluginDESCRIPTIONTo 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:
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"; KEYWORDS (imported functions)The following functions are imported into the package that uses "OpenXPKI::Server::API2::EasyPlugin".commandDefine 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
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).
Visit the GSP FreeBSD Man Page Interface. |