| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::Insult::Evil 1.1 { # https://www.freepublicapis.com/evil-insult-generator |
|
2
|
1
|
|
|
1
|
|
203357
|
use v5.38; |
|
|
1
|
|
|
|
|
4
|
|
|
3
|
1
|
|
|
1
|
|
789
|
use HTTP::Tiny; |
|
|
1
|
|
|
|
|
53557
|
|
|
|
1
|
|
|
|
|
87
|
|
|
4
|
1
|
|
|
1
|
|
539
|
use JSON::Tiny qw[decode_json]; |
|
|
1
|
|
|
|
|
2574
|
|
|
|
1
|
|
|
|
|
69
|
|
|
5
|
1
|
|
|
1
|
|
1352
|
use URI; |
|
|
1
|
|
|
|
|
5396
|
|
|
|
1
|
|
|
|
|
58
|
|
|
6
|
1
|
|
|
1
|
|
10
|
use parent 'Exporter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw[insult] ] ); |
|
8
|
|
|
|
|
|
|
# |
|
9
|
1
|
|
33
|
1
|
|
108
|
use overload '""' => sub ( $s, $u, $b ) { $s->{insult} // () }; |
|
|
1
|
|
|
3
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
32
|
|
|
|
3
|
|
|
|
|
642
|
|
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
5
|
|
|
10
|
|
|
|
|
|
|
# |
|
11
|
9
|
|
|
9
|
|
20
|
sub _http (%params) { |
|
|
9
|
|
|
|
|
27
|
|
|
|
9
|
|
|
|
|
17
|
|
|
12
|
9
|
|
66
|
|
|
73
|
state $http |
|
13
|
|
|
|
|
|
|
//= HTTP::Tiny->new( default_headers => { Accept => 'application/json' }, agent => sprintf '%s/%.2f ', __PACKAGE__, our $VERSION ); |
|
14
|
9
|
|
66
|
|
|
163
|
state $api //= URI->new('https://evilinsult.com/generate_insult.php'); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# API accepts languages as a param named 'lang' but returns the language in a field called 'language'... why? |
|
17
|
9
|
100
|
|
|
|
9436
|
$api->query_form( type => 'json', ( defined $params{language} ? ( lang => delete $params{language} ) : () ), %params ); |
|
18
|
9
|
|
|
|
|
2181
|
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 |
|
19
|
9
|
50
|
|
|
|
841329
|
$res->{success} ? decode_json( $res->{content} ) : (); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
# |
|
22
|
9
|
50
|
|
9
|
1
|
236278
|
sub insult (%args) { my $ref = _http(%args); $ref ? bless $ref, __PACKAGE__ : $ref } |
|
|
9
|
|
|
|
|
34
|
|
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
33
|
|
|
|
9
|
|
|
|
|
5100
|
|
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
1; |
|
25
|
|
|
|
|
|
|
__END__ |