Acme-Insult-Glax

 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-Glax/issues"
      },
      "homepage" : "https://github.com/sanko/Acme-Insult-Glax",
      "repository" : {
         "type" : "git",
         "url" : "https://github.com/sanko/Acme-Insult-Glax.git",
         "web" : "https://github.com/sanko/Acme-Insult-Glax"
      }
   },
   "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::Glax:
    file: lib/Acme/Insult/Glax.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-Glax/issues
  homepage: https://github.com/sanko/Acme-Insult-Glax
  repository: https://github.com/sanko/Acme-Insult-Glax.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/Glax.pm  view on Meta::CPAN

package Acme::Insult::Glax 1.1 {    # https://www.freepublicapis.com/insult-api
    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 adjective] ] );
    #
    use overload '""' => sub ( $s, $u, $b ) { $s->{insult} // () };
    my $api = URI->new('https://insult.mattbas.org/api/');
    #
    sub _http ( $endpoint, %params ) {
        state $http
            //= HTTP::Tiny->new( default_headers => { Accept => 'application/json' }, agent => sprintf '%s/%.2f ', __PACKAGE__, our $VERSION );
        ( my $hey = $api->clone )->path( '/api/' . $endpoint . '.json' );
        $hey->query_form(%params);
        my $res = $http->get( $hey->as_string );    # {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( insult => %args ); $ref ? bless $ref, __PACKAGE__ : $ref }

    sub adjective ( $lang //= 'en' ) {
        my $ref = _http( adjective => ( lang => $lang ) );
        $ref ? bless $ref, __PACKAGE__ : $ref;
    }
}

script/glax_insult.pl  view on Meta::CPAN

#~ @ARGV = qw[];
#~ @ARGV = qw[-j];
#~ @ARGV = qw[-who Tim];
#~ @ARGV = ( qw[-plural -who], 'Tim and John' );
#~ @ARGV = (qw[-adjective -sfw]);
#~ @ARGV = (qw[-sfw]);
#~ @ARGV = qw[-h];
#
my $raw = 0;

sub _echo ($insult) {    # JSON::Tiny is loaded in Acme::Insult::Glax anyway
    $raw ? JSON::Tiny::encode_json( {%$insult} ) : $insult;
}
GetOptions( \my %h, 'who=s', 'template=s', 'plural!', 'help' => sub { pod2usage( -exitval => 1 ) }, 'json!' => \$raw, 'adjective!', 'sfw!' );
$h{lang} = 'en_corporate' if delete $h{sfw};
my $shade = delete $h{adjective} ? Acme::Insult::Glax::adjective( $h{lang} ) : Acme::Insult::Glax::insult(%h);
exit !( $shade ? say _echo($shade) : !say( $raw ? 'null' : '' ) );
__END__

=head1 NAME

glax_insult - Generate insults on the terminal

script/glax_insult.pl  view on Meta::CPAN

    glax_insult -template='...'                  # generate insults with a specific format
    glax_insult -json                            # insult someone if you're a robot
    glax_insult -who John                        # insult someone by name
    glax_insult -plural -who "John and Alex"     # insult multiple people
    glax_insult -sfw                             # insult someone with workplace jargon
    glax_insult -adjective                       # generate a single adjective
    glax_insult -help                            # get help

=head1 OPTIONS

    -json               Echo raw JSON encoded data
    -template <layout>  Specify an insult's format
    -who                Provide a name for the person you'd like to insult
    -plural             Changes the template to third person plural
    -sfw                Use corporate jargon to generate insults
    -adjective          Generates a single adjective in plain text
    -help               Display this help message

=head1 DESCRIPTION

This script wraps Acme::Insult::Glax.



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