Acme-Insult-Evil
view release on metacpan or search on metacpan
my $shade = insult( ); # Random insult
print insult( language => 'fr' ); # stringify
```
You may request specific insults by passing parameters.
Expected parameters include:
- `language`
Insult's language. The default is `en`. Supported languages include: `en`, `fr`, `cn`, `ja`, `es`, etc.
On success, an insult is returned as a blessed hash reference containing the following data:
- `active`
Boolean value. If true, the insult is part of the public API.
- `comment`
This often provides contextual information about the insult's source of the insult itself.
lib/Acme/Insult/Evil.pm view on Meta::CPAN
use HTTP::Tiny;
use JSON::Tiny qw[decode_json];
use URI;
use parent 'Exporter';
our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw[insult] ] );
#
use overload '""' => sub ( $s, $u, $b ) { $s->{insult} // () };
#
sub _http (%params) {
state $http
//= HTTP::Tiny->new( default_headers => { Accept => 'application/json' }, agent => sprintf '%s/%.2f ', __PACKAGE__, our $VERSION );
state $api //= URI->new('https://evilinsult.com/generate_insult.php');
# API accepts languages as a param named 'lang' but returns the language in a field called 'language'... why?
$api->query_form( type => 'json', ( defined $params{language} ? ( lang => delete $params{language} ) : () ), %params );
my $res = $http->get($api); # {success} is true even when advice is not found but we'll at least know when we have valid JSON
$res->{success} ? decode_json( $res->{content} ) : ();
}
#
sub insult (%args) { my $ref = _http(%args); $ref ? bless $ref, __PACKAGE__ : $ref }
}
lib/Acme/Insult/Evil.pm view on Meta::CPAN
print insult( language => 'fr' ); # stringify
You may request specific insults by passing parameters.
Expected parameters include:
=over
=item C<language>
Insult's language. The default is C<en>. Supported languages include: C<en>, C<fr>, C<cn>, C<ja>, C<es>, etc.
=back
On success, an insult is returned as a blessed hash reference containing the following data:
=over
=item C<active>
Boolean value. If true, the insult is part of the public API.
t/00_compile.t view on Meta::CPAN
#
ok +insult(), 'stringify';
#
subtest 'evil insults in different languages' => sub {
is Acme::Insult::Evil::insult(), hash {
field active => number_ge 0;
field comment => D();
field created => D(); # ISO date
field createdby => D(); # might be filled
field insult => D();
field language => string 'en'; # default
field number => number_ge 0;
field shown => number_ge 0;
}, 'English is the default';
for my ( $code, $lang )(
en => 'English',
cn => 'Chinese',
ja => 'Japanese',
fr => 'French',
es => 'Spanish',
hi => 'Hindi',
tr => 'Turkish' # That's enough
) {
is Acme::Insult::Evil::insult( language => $code ), hash {
( run in 0.414 second using v1.01-cache-2.11-cpan-8780591d54d )