<commit_before>package OpenXPKI::Service::Default::CommandApi2;
use Moose;

=head1 NAME

OpenXPKI::Service::Default::CommandApi2 - Execute commands via new API

=cut

# Project modules
use OpenXPKI::Exception;
use OpenXPKI::Server::API2;

=head1 DESCRIPTION

Default service command class to execute commands via the new API (API2).

=cut

has api => (
    is => 'rw',
    isa => 'OpenXPKI::Server::API2',
    lazy => 1,
    default => sub { OpenXPKI::Server::API2->new(enable_acls => 0) },
);

has command => (
    is => 'ro',
    isa => 'Str',
    required => 1,
);

has params => (
    is => 'ro',
    isa => 'HashRef',
    required => 1,
);


=head1 METHODS

=head2 new

Stores command and parameters for later execution via API.

B<Parameters>

=over

=item * C<command> I<Str> - API command name

=item * C<params> I<HashRef> - command parameters

=head2 execute

Executes the command via API.

Returns a data structure that can be serialized and directly returned to the
client:
<commit_msg>Fix POD error<commit_after>package OpenXPKI::Service::Default::CommandApi2;
use Moose;

=head1 NAME

OpenXPKI::Service::Default::CommandApi2 - Execute commands via new API

=cut

# Project modules
use OpenXPKI::Exception;
use OpenXPKI::Server::API2;

=head1 DESCRIPTION

Default service command class to execute commands via the new API (API2).

=cut

has api => (
    is => 'rw',
    isa => 'OpenXPKI::Server::API2',
    lazy => 1,
    default => sub { OpenXPKI::Server::API2->new(enable_acls => 0) },
);

has command => (
    is => 'ro',
    isa => 'Str',
    required => 1,
);

has params => (
    is => 'ro',
    isa => 'HashRef',
    required => 1,
);


=head1 METHODS

=head2 new

Stores command and parameters for later execution via API.

B<Parameters>

=over

=item * C<command> I<Str> - API command name

=item * C<params> I<HashRef> - command parameters

=back

=head2 execute

Executes the command via API.

Returns a data structure that can be serialized and directly returned to the
client:

{'fraction_non_alphanumeric': 0.13030454318522217, 'fraction_numerical': 0.014977533699450823, 'mean_word_length': 3.8289156626506022, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '973704', 'n_tokens_mistral': 706, 'n_tokens_neox': 677, 'n_words': 221}