| 1 | package Mojolicious::Command::nopaste::Service::perlbot; | ||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command::nopaste::Service'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mojo::JSON qw/decode_json/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.007'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Pastes stuff to https://perl.bot/ | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 1 | has name => 'anonymous'; | |||||||||||||||||||||||||||||||
| 12 | 1 | has 'irc_handled' => 1; | |||||||||||||||||||||||||||||||
| 13 | 1 | has desc => 'I broke this'; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | has 'service_usage' => | |||||||||||||||||||||||||||||||
| 16 | qq{perl.bot specific options: | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | --get-channels Ask the pastebin about what channels it knows, and exit | ||||||||||||||||||||||||||||||||
| 19 | --get-languages Ask the pastebin about what languages it knows, and exit | ||||||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 23 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | my $p = Getopt::Long::Parser->new; | |||||||||||||||||||||||||||||||
| 26 | 0 | $p->configure("no_ignore_case", "pass_through"); | |||||||||||||||||||||||||||||||
| 27 | $p->getoptionsfromarray( \@args, | ||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | 'get-channels' => sub {$self->display_channels; exit(1)}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | 'get-languages' => sub {$self->display_languages; exit(1)}, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 30 | 0 | ); | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | $self->SUPER::run(@args); | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub display_channels { | ||||||||||||||||||||||||||||||
|
Subroutine
display_channels: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 36 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 37 | 0 | my $tx = $self->ua->get( 'https://perl.bot/api/v2/channels'); | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | unless ($tx->res->is_success) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 0 | say "Failed to get channels, try again later."; | |||||||||||||||||||||||||||||||
| 41 | 0 | exit 1; | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | my $response = decode_json $tx->res->body; | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 0 | my $output="Channels supported by perl.bot, all values subject to change.\n-----------------------------------\n"; | |||||||||||||||||||||||||||||||
| 47 | 0 | for my $channel (@{$response->{channels}}) { | |||||||||||||||||||||||||||||||
| 48 | 0 | $output .= sprintf "%15s %20s\n", $channel->{name}, $channel->{description}; | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | print $output; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub display_languages { | ||||||||||||||||||||||||||||||
|
Subroutine
display_languages: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 56 | 0 | my $tx = $self->ua->get( 'https://perl.bot/api/v2/languages'); | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ($tx->res->is_success) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | say "Failed to get languages, try again later."; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 0 | my $response = decode_json $tx->res->body; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | my $output="Languages supported by perl.bot\n-----------------------------\n"; | |||||||||||||||||||||||||||||||
| 65 | 0 | for my $lang (@{$response->{languages}}) { | |||||||||||||||||||||||||||||||
| 66 | 0 | $output .= sprintf "%15s %20s\n", $lang->{name}, $lang->{description}; | |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 0 | print $output; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | sub paste { | ||||||||||||||||||||||||||||||
|
Subroutine
paste: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 73 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | my $tx = $self->ua->post( 'https://perl.bot/api/v2/paste', form => { | ||||||||||||||||||||||||||||||
|
Condition50%3/6
$self->language || ''
$self->channel || ''
$self->desc || ''
MC/DC0%0/1
$self->language || ''
$self->language
MC/DC0%0/1
$self->channel || ''
$self->channel
MC/DC0%0/1
$self->desc || ''
$self->desc
Truth table50%1/2
A
A= $self->language
Truth table50%1/2
A
A= $self->channel
Truth table50%1/2
A
A= $self->desc
| |||||||||||||||||||||||||||||||||
| 76 | paste => $self->text, | ||||||||||||||||||||||||||||||||
| 77 | username => $self->name, | ||||||||||||||||||||||||||||||||
| 78 | language => $self->language || '', | ||||||||||||||||||||||||||||||||
| 79 | channel => $self->channel || '', | ||||||||||||||||||||||||||||||||
| 80 | description => $self->desc || '', | ||||||||||||||||||||||||||||||||
| 81 | }); | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | unless ($tx->res->is_success) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | say "Paste failed, try again later."; | |||||||||||||||||||||||||||||||
| 85 | 0 | exit 1; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 1 | my $response = decode_json $tx->res->body; | |||||||||||||||||||||||||||||||
| 89 | 1 | return $response->{url}; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 1 | 1; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||||||