AI-CleverbotIO
view release on metacpan or search on metacpan
my $logger = $obj->logger;
Read-only accessor to the logger object (Log::Any compatible). See
"BUILD_logger" for the default value.
nick
$obj->nick($some_string);
my $nick = $obj->nick;
Read-write accessor to the nick for invoking API calls. If not set, it
is set after a call to "create". See also "has_nick".
ua
my $ua = $obj->ua;
Read-only accessor to the user agent object (HTTP::Tiny compatible).
See BUILD_ua for the default value.
user
my $api_user = $obj->user;
Read-only accessor to the API user. MUST be provided upon
instantiation.
METHODS
BUILD_logger
Called automatically if "logger" is not set. By default, it returns
whatever "get_logger" in Log::Any provides, but you can easily override
this in a derived class.
BUILD_ua
Called automatically if "ua" is not set. By default, it returns a plain
new instance of HTTP::Tiny, without options.
ask
my $answer = $obj->ask($some_text);
Send a ask API request. The returned $answer is a hash reference
derived by the JSON decoding of the response body, e.g.:
{
status => 'success',
nick => 'NickTheRobot',
}
If the current "nick" has already been used for creation, the API call
will fail partially in that status 200 will be returned, but the status
field in the answer will contain an error about the fact that the nick
already exists (Error: reference name already exists). You can safely
ignore this error.
You can optionally pass a different other_nick. This will be set as
"nick" and used for creation (this will overwrite whatever "nick"
contains though).
has_nick
say $obj->nick if $obj->has_nick;
say 'no nick yet' unless $obj->has_nick;
Predicate to check whether a "nick" is already set or not.
BUGS AND LIMITATIONS
Report bugs either through RT or GitHub (patches welcome).
SEE ALSO
https://cleverbot.io.
AUTHOR
lib/AI/CleverbotIO.pod view on Meta::CPAN
my $logger = $obj->logger;
Read-only accessor to the logger object (L<Log::Any> compatible). See
L</BUILD_logger> for the default value.
=head2 nick
$obj->nick($some_string);
my $nick = $obj->nick;
Read-write accessor to the nick for invoking API calls. If not set, it
is set after a call to L</create>. See also L</has_nick>.
=head2 ua
my $ua = $obj->ua;
Read-only accessor to the user agent object (L<HTTP::Tiny> compatible). See
L<BUILD_ua> for the default value.
=head2 user
my $api_user = $obj->user;
Read-only accessor to the API user. MUST be provided upon instantiation.
=head1 METHODS
=head2 BUILD_logger
Called automatically if L</logger> is not set. By default, it
returns whatever L<Log::Any/get_logger> provides, but you can
easily override this in a derived class.
=head2 BUILD_ua
Called automatically if L</ua> is not set. By default, it returns
a plain new instance of L<HTTP::Tiny>, without options.
=head2 ask
my $answer = $obj->ask($some_text);
Send a I<ask> API request. The returned C<$answer> is a hash reference
derived by the JSON decoding of the response body, e.g.:
{
lib/AI/CleverbotIO.pod view on Meta::CPAN
status => 'success',
nick => 'NickTheRobot',
}
If the current L</nick> has already been used for creation, the API call
will fail partially in that status 200 will be returned, but the C<status>
field in the answer will contain an error about the fact that the nick
already exists (C<Error: reference name already exists>). You can safely
ignore this error.
You can optionally pass a different C<other_nick>. This will be set as
L</nick> and used for creation (this will overwrite whatever L</nick>
contains though).
=head2 has_nick
say $obj->nick if $obj->has_nick;
say 'no nick yet' unless $obj->has_nick;
Predicate to check whether a L</nick> is already set or not.
=head1 BUGS AND LIMITATIONS
Report bugs either through RT or GitHub (patches welcome).
=head1 SEE ALSO
L<https://cleverbot.io>.
=head1 AUTHOR
t/01-basic.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Log::Any::Adapter;
use 5.010;
use AI::CleverbotIO;
plan skip_all => 'no CLEVERBOT_API_USER/CLEVERBOT_API_KEY pair set'
unless exists($ENV{CLEVERBOT_API_USER})
&& exists($ENV{CLEVERBOT_API_KEY});
Log::Any::Adapter->set('Stderr') if $ENV{CLEVERBOT_STDERR};
my $cleverbot;
lives_ok {
$cleverbot = AI::CleverbotIO->new(
key => $ENV{CLEVERBOT_API_KEY},
nick => $ENV{CLEVERBOT_NICK} // "AI::CleverbotIO Tester",
user => $ENV{CLEVERBOT_API_USER},
);
} ## end lives_ok
'AI::CleverbotIO instantiation lives';
t/author-pod-coverage.t view on Meta::CPAN
BEGIN {
unless ($ENV{AUTHOR_TESTING}) {
require Test::More;
Test::More::plan(skip_all => 'these tests are for testing by the author');
}
}
use Test::More;
plan skip_all => "Test::Pod::Coverage - AUTHOR_TESTING not set"
unless $ENV{AUTHOR_TESTING};
eval "use Test::Pod::Coverage 1.04";
plan skip_all =>
"Test::Pod::Coverage 1.04 required for testing POD coverage"
if $@;
all_pod_coverage_ok();
( run in 1.482 second using v1.01-cache-2.11-cpan-49f99fa48dc )