Acme-Insult-Evil

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Test::Pod" : "1.41",
            "Test::Spellunker" : "v0.2.7",
            "Version::Next" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Getopt::Long" : "0",
            "HTTP::Tiny" : "0.088",
            "IO::Socket::SSL" : "1.42",
            "JSON::Tiny" : "0.58",
            "Mozilla::CA" : "0",
            "Net::SSLeay" : "1.49",
            "URI" : "0",
            "perl" : "v5.38.0"
         }
      },
      "test" : {
         "requires" : {
            "Test2::V0" : "0.000159"
         }

META.json  view on Meta::CPAN

         "web" : "https://github.com/sanko/Acme-Insult-Evil/issues"
      },
      "homepage" : "https://github.com/sanko/Acme-Insult-Evil",
      "repository" : {
         "type" : "git",
         "url" : "https://github.com/sanko/Acme-Insult-Evil.git",
         "web" : "https://github.com/sanko/Acme-Insult-Evil"
      }
   },
   "version" : "1.1",
   "x_serialization_backend" : "JSON::PP version 4.16",
   "x_static_install" : 1
}

META.yml  view on Meta::CPAN

    - author
    - builder
provides:
  Acme::Insult::Evil:
    file: lib/Acme/Insult/Evil.pm
    version: '1.1'
requires:
  Getopt::Long: '0'
  HTTP::Tiny: '0.088'
  IO::Socket::SSL: '1.42'
  JSON::Tiny: '0.58'
  Mozilla::CA: '0'
  Net::SSLeay: '1.49'
  URI: '0'
  perl: v5.38.0
resources:
  bugtracker: https://github.com/sanko/Acme-Insult-Evil/issues
  homepage: https://github.com/sanko/Acme-Insult-Evil
  repository: https://github.com/sanko/Acme-Insult-Evil.git
version: '1.1'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'

cpanfile  view on Meta::CPAN

requires 'perl', '5.038000';
requires 'Getopt::Long';
requires 'HTTP::Tiny'      => '0.088';
requires 'JSON::Tiny'      => '0.58';
requires 'IO::Socket::SSL' => '1.42';
requires 'Net::SSLeay'     => '1.49';
requires 'Mozilla::CA';
requires 'URI';
on 'test' => sub {
    requires 'Test2::V0' => 0.000159;
};
on 'configure' => sub {
    requires 'Archive::Tar';
    requires 'CPAN::Meta';

lib/Acme/Insult/Evil.pm  view on Meta::CPAN

package Acme::Insult::Evil 1.1 {    # https://www.freepublicapis.com/evil-insult-generator
    use v5.38;
    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 }
}
1;
__END__

=encoding utf-8

script/evil_insult.pl  view on Meta::CPAN

use open qw[:std :encoding(UTF-8)];

# Test
#~ @ARGV = qw[];
#~ @ARGV = qw[-json];
#~ @ARGV = qw[-language fr];
#~ @ARGV = qw[-h];
#
my $raw = 0;

sub _echo ($insult) {    # JSON::Tiny is loaded in Acme::Free::Advice::Unsolicited anyway
    $raw ? JSON::Tiny::encode_json( {%$insult} ) : $insult;
}
GetOptions( \my %h, 'language=s', 'help' => sub { pod2usage( -exitval => 1 ) }, 'json!' => \$raw );
my $shade = Acme::Insult::Evil::insult(%h);
exit !( $shade ? say _echo($shade) : !say( $raw ? 'null' : '' ) );
__END__

=head1 NAME

evil_insult - Generate evil insults on the terminal

=head1 SYNOPSIS

    evil_insult                                  # generate a random insult
    evil_insult -json                            # insult someone if you're a robot
    evil_insult -lang fr                         # generate an insult in French
    evil_insult -help                            # get help

=head1 OPTIONS

    -json               Echo raw JSON encoded data
    -lang    <code>     Generates an insult in a given language
    -help               Display this help message

=head1 DESCRIPTION

This script wraps Acme::Insult::Evil.

=head1 LICENSE & LEGAL

Copyright (C) Sanko Robinson.



( run in 1.038 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )