| 1 | package App::KGB::Client::RelayMsg; | ||||||||||||
| 2 | 1 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | our $VERSION = 1.27; | |||||||||||
| 8 | |||||||||||||
| 9 | # vim: ts=4:sw=4:et:ai:sts=4 | ||||||||||||
| 10 | # | ||||||||||||
| 11 | # KGB - an IRC bot helping collaboration -- Simple message relay | ||||||||||||
| 12 | # Copyright © 2012 Damyan Ivanov | ||||||||||||
| 13 | # | ||||||||||||
| 14 | # This program is free software; you can redistribute it and/or modify it under | ||||||||||||
| 15 | # the terms of the GNU General Public License as published by the Free Software | ||||||||||||
| 16 | # Foundation; either version 2 of the License, or (at your option) any later | ||||||||||||
| 17 | # version. | ||||||||||||
| 18 | # | ||||||||||||
| 19 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||
| 20 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||||
| 21 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||||||||||||
| 22 | # details. | ||||||||||||
| 23 | # | ||||||||||||
| 24 | # You should have received a copy of the GNU General Public License along with | ||||||||||||
| 25 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||||||||||||
| 26 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||||||||||
| 27 | |||||||||||||
| 28 | =head1 NAME | ||||||||||||
| 29 | |||||||||||||
| 30 | App::KGB::Client::RelayMsg - Simple message relay KGB client | ||||||||||||
| 31 | |||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||
| 33 | |||||||||||||
| 34 | use App::KGB::Client::RelayMsg; | ||||||||||||
| 35 | my $client = App::KGB::Client::RelayMsg->new( | ||||||||||||
| 36 | # common App::KGB::Client parameters | ||||||||||||
| 37 | repo_id => 'my-repo', | ||||||||||||
| 38 | ... | ||||||||||||
| 39 | relay_message => "It's alive!", | ||||||||||||
| 40 | ); | ||||||||||||
| 41 | $client->process; | ||||||||||||
| 42 | |||||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||||
| 44 | |||||||||||||
| 45 | B<App::KGB::Client::RelayMsg> passes a simple text message to the bot to put | ||||||||||||
| 46 | on IRC. It is useful for notifications not connected with a source | ||||||||||||
| 47 | repository like bug submission etc. | ||||||||||||
| 48 | |||||||||||||
| 49 | See also L<kgb-client(1)>'s C<--relay-msg> option. | ||||||||||||
| 50 | |||||||||||||
| 51 | =head1 CONSTRUCTOR | ||||||||||||
| 52 | |||||||||||||
| 53 | =head2 B<new> () | ||||||||||||
| 54 | |||||||||||||
| 55 | Standard constructor. Accepts no arguments. | ||||||||||||
| 56 | |||||||||||||
| 57 | =head1 FIELDS | ||||||||||||
| 58 | |||||||||||||
| 59 | =over | ||||||||||||
| 60 | |||||||||||||
| 61 | =item B<relay_message> I<message> (B<mandatory>) | ||||||||||||
| 62 | |||||||||||||
| 63 | The message to relay. | ||||||||||||
| 64 | |||||||||||||
| 65 | =back | ||||||||||||
| 66 | |||||||||||||
| 67 | =head1 METHODS | ||||||||||||
| 68 | |||||||||||||
| 69 | =over | ||||||||||||
| 70 | |||||||||||||
| 71 | =item process | ||||||||||||
| 72 | |||||||||||||
| 73 | Overrides L<App::KGB::Client>'s process method. | ||||||||||||
| 74 | |||||||||||||
| 75 | =back | ||||||||||||
| 76 | |||||||||||||
| 77 | =cut | ||||||||||||
| 78 | |||||||||||||
| 79 | 1 | require v5.10.0; | |||||||||||
| 80 | 1 | ▶ | use base 'App::KGB::Client'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 81 | 1 | ▶ | use Carp qw(confess); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 82 | 1 | __PACKAGE__->mk_accessors(qw( relay_message)); | |||||||||||
| 83 | |||||||||||||
| 84 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 85 | 0 | my $class = shift; | |||||||||||
| 86 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||
| 87 | 0 | ▶ | defined( $self->relay_message ) or confess "relay_message is mandatory"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | |||||||||||||
| 89 | 0 | return $self; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 0 | ▶ | sub process { | ||||||||||
|
Subroutine
process: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 93 | 0 | my $self = shift; | |||||||||||
| 94 | |||||||||||||
| 95 | 0 | my @servers = $self->shuffle_servers; | |||||||||||
| 96 | |||||||||||||
| 97 | # try all servers in turn until someone succeeds | ||||||||||||
| 98 | 0 | my $failure; | |||||||||||
| 99 | 0 | for my $srv (@servers) { | |||||||||||
| 100 | 0 | ▶ | $failure = eval { | ||||||||||
|
Condition0%0/2
eval {
do {
$srv->relay_message($self, $self->relay_message, {"use_irc_notices", $self->use_irc_notices});
$self->_last_server($srv);
$self->note_last_server($srv);
0
}
} // 1
MC/DC0%0/1
eval {
do {
$srv->relay_message($self, $self->relay_message, {"use_irc_notices", $self->use_irc_notices});
$self->_last_server($srv);
$self->note_last_server($srv);
0
}
} // 1
eval {
do {
$srv->relay_message($self, $self->relay_message, {"use_irc_notices", $self->use_irc_notices});
$self->_last_server($srv);
$self->note_last_server($srv);
0
}
}
Truth table0%0/2
A
A= eval {
do {
$srv->relay_message($self, $self->relay_message, {"use_irc_notices", $self->use_irc_notices});
$self->_last_server($srv);
$self->note_last_server($srv);
0
}
}
| |||||||||||||
| 101 | 0 | $srv->relay_message( $self, $self->relay_message, | |||||||||||
| 102 | { use_irc_notices => $self->use_irc_notices } ); | ||||||||||||
| 103 | 0 | $self->_last_server($srv); | |||||||||||
| 104 | |||||||||||||
| 105 | 0 | $self->note_last_server($srv); | |||||||||||
| 106 | 0 | 0; | |||||||||||
| 107 | } // 1; | ||||||||||||
| 108 | |||||||||||||
| 109 | 0 | ▶ | warn $@ if $failure; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | last unless $failure; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 0 | ▶ | die "Unable to complete notification. All servers failed\n" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 115 | if $failure; | ||||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | 1 | 1; | |||||||||||