blib/lib/App/KGB/Client.pm

filter: Statementstmt 17.1% 55 / 320 Branchbran 0.0% 0 / 188 Conditioncond 0.0% 0 / 88 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 48.4% 16 / 33 Podpod 100% 15 / 15 totaltotal 12.3% 86 / 699 CC 134 SCAR 59.1
CC
134
Cov
9%
format_message
1260.0
detect_branch_and_module
306.0
new
240.0
CRAP 369.8
« blib/lib/App/KGB/Client/CVS.pm ↑ Summary blib/lib/App/KGB/Client/ServerRef.pm »
1 package App::KGB::Client;
2 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 require v5.10.0;
4  
5 8 ▶use feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 our $VERSION = '1.34';
10  
11 # vim: ts=4:sw=4:et:ai:sts=4
12 #
13 # KGB - an IRC bot helping collaboration
14 # Copyright © 2008 Martina Ferrari
15 # Copyright © 2009,2010,2011,2012,2013 Damyan Ivanov
16 # Copyright © 2018 Colin Finck <colin@reactos.org>
17 #
18 # This program is free software; you can redistribute it and/or modify it under
19 # the terms of the GNU General Public License as published by the Free Software
20 # Foundation; either version 2 of the License, or (at your option) any later
21 # version.
22 #
23 # This program is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
26 # details.
27 #
28 # You should have received a copy of the GNU General Public License along with
29 # this program; if not, write to the Free Software Foundation, Inc., 51
30 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31  
32 =head1 NAME
33  
34 App::KGB::Client - relay commits to KGB servers
35  
36 =head1 SYNOPSIS
37  
38 use App::KGB::Client;
39 my $client = App::KGB::Client( <parameters> );
40 $client->run;
41  
42 =head1 DESCRIPTION
43  
44 B<App::KGB::Client> is the backend behind L<kgb-client(1)>. It handles
45 the repository-independent parts of sending the notifications to the KGB server,
46 L<kgb-bot(1)>. Details about extracting change from commits, branches and
47 modules is done by sub-classes specific to the version control system in use.
48  
49 =head1 CONFIGURATION
50  
51 The following parameters are accepted in the constructor:
52  
53 =over
54  
55 =item B<repo_id> I<repository name>
56  
57 Short repository identifier. Will be used for identifying the repository to the
58 KGB daemon, which will also use this for IRC notifications. B<Mandatory>.
59  
60 =item B<uri> I<URI>
61  
62 URI of the KGB server. Something like C<http://some.server:port>. B<Mandatory>
63 either as a top-level parameter or as a sub-parameter of B<servers> array.
64  
65 =item B<proxy> I<URI>
66  
67 URI of the SOAP proxy. If not given, it is the value of the B<uri> option, with
68 C<?session=KGB> added.
69  
70 =item B<password> I<password>
71  
72 Password for authentication to the KGB server. B<Mandatory> either as a
73 top-level parameter or as a sub-parameter of B<servers> array.
74  
75 =item B<timeout> I<seconds>
76  
77 Timeout for server communication. Default is 15 seconds, as we want instant IRC
78 and commit response.
79  
80 =item B<servers>
81  
82 An array of servers, each an instance of L<App::KGB::Client::ServerRef> class.
83  
84 When several servers are configured, the list is shuffled and then the servers
85 are tried one after another until a successful request is done, or the list is
86 exhausted, in which case an exception is thrown.
87  
88 When shuffling, preference is added to the last server used by the client, or
89 by other clients (given C<status_dir> is configured).
90  
91 =item B<batch_messages>
92  
93 If true, the notifications are sent as a batch in one request to the server.
94 Useful with VCS that send many changes a time (e.g. Git).
95  
96 Defaults to false, but will be changed later after some grace period for server
97 upgrade.
98  
99 =item B<br_mod_re>
100  
101 A list of regular expressions (simple strings, not L<qr> objects) that serve
102 for detection of branch and module of commits. Each item from the list is tried
103 in turn, until an item is found that matches all the paths that were modified
104 by the commit. Regular expressions must have two captures: the first one giving
105 the branch name, and the second one giving the module name.
106  
107 All the paths that were modified by the commit must resolve to the same branch
108 and module in order for the branch and module to be transmitted to the KGB
109 server.
110  
111 Example: ^/(trunk)/([^/]+)/
112 # /trunk/module/file
113 ^/branches/([^/]+)/([^/]+)/
114 # /branches/test/module/file
115  
116 =item B<mod_br_re>
117  
118 Same as B<br_mod_re>, but captures module name first and branch name second.
119  
120 Example: ^/branches/([^/]+)/([^/]+)/
121 # /branches/test/module/file
122  
123 =item B<ignore_branch>
124  
125 When most of the development is in one branch, transmitting it to the KGB
126 server and seeing it on IRC all the time can be annoying. Therefore, if you
127 define B<ignore_branch>, and a given commit is in a branch with that name, the
128 branch name is not transmitted to the server. Module name is still transmitted.
129  
130 =item B<module>
131  
132 Forces explicit module name, overriding the branch and module detection. Useful
133 in Git-hosted sub-projects that want to share single configuration file, but
134 still want module indication in notifications.
135  
136 =item B<single_line_commits> I<off|forced|auto>
137  
138 Request different modes of commit message processing:
139  
140 =over
141  
142 =item I<off>
143  
144 No processing is done. The commit message is printed as was given, with each
145 line in a separate IRC message, blank lines omitted. This is the only possible
146 behaviour in versions before 1.14.
147  
148 =item I<forced>
149  
150 Only the first line is sent to IRC, regardless of whether it is followed by a
151 blank line or not.
152  
153 =item I<auto>
154  
155 If the first line is followed by an empty line, only the first line is sent to
156 IRC and the rest is ignored. This is the default since version 1.14.
157  
158 =back
159  
160 =item B<use_irc_notices>
161  
162 If true signals the server that it should use IRC notices instead of regular
163 messages. Use this if regular messages are too distracting for your channel.
164  
165 =item B<use_color>
166  
167 If true (the default) signals the server that it should use colors for commit
168 notifications.
169  
170 =item B<status_dir>
171  
172 Specifies a directory to store information about the last server contacted
173 successfully. The client would touch files in that directory after successful
174 completion of a notification with remote server.
175  
176 Later, when asked to do another notification, the client would start from the
177 most recently contacted server. If that was contacted too far in the past, the
178 information in the directory is ignored and a random server is picked, as
179 usual.
180  
181 =item B<verbose>
182  
183 Print diagnostic information.
184  
185 =item B<protocol> I<version>
186  
187 Use specified protocol version. If C<auto> (the default), the version of the
188 protocol C<2>, unless B<web_link> is also given, in which case protocol version
189 C<3> is default;
190  
191 =item B<web_link> I<template>
192  
193 A web link template to be sent to the server. The following items are expanded:
194  
195 =over
196  
197 =item ${branch}
198  
199 =item ${module}
200  
201 =item ${commit}
202  
203 =item ${project}
204  
205 =back
206  
207 =item B<short_url_service> I<service>
208  
209 A L<WWW::Shorten> service to use for shortening the B<web_link>. See
210 L<WWW::Shorten> for the list of supported services.
211  
212 =item B<msg_template> I<string>
213  
214 Provides a way to customize the notifications' appearance on IRC. When present,
215 all message construction is done on the client and the prepared messages
216 (possibly with colors etc) are sent to the server for relaying to IRC.
217  
218 The following special items are recognized and replaced with the respective
219 commit elements.
220  
221 =over
222  
223 =item ${project_id}
224  
225 The ID of the project.
226  
227 =item ${author_login}
228  
229 The login of the author (e.g. "joe").
230  
231 =item ${author_name}
232  
233 The name of the commit author (e.g. "Joe Random")
234  
235 =item ${author_via}
236  
237 The name of the commit author, plus the name of the committer if that is
238 different (e.g. "Joe Random" or "Joe Random (via Max Random)")
239  
240 =item ${branch}
241  
242 The branch of the commit.
243  
244 =item ${module}
245  
246 The module of the commit.
247  
248 =item ${commit}
249 =item ${revision}
250  
251 The ID of the commit.
252  
253 =item ${path}
254  
255 The changed path(s).
256  
257 =item ${log}
258  
259 The log message of the commit.
260  
261 =item ${web}
262  
263 The web link associated with the commit. Replaced with the empty string unless
264 the B<web_link> option is also given.
265  
266 =back
267  
268 =item B<style> I<hash reference>
269  
270 Provides a color map for different parts of the message. The following keys are
271 supported. Defaults are used when keys are missing in the hash. B<use_color>
272 must be true for this to have any effect. Used only when B<msg_template> is
273 also given.
274  
275 =over
276  
277 =item revision
278 =item commit_id
279  
280 Commit ID. Default: none.
281  
282 =item path
283  
284 Changed path. Default: teal.
285  
286 Depending on the action performed to the path, additional coloring is made:
287  
288 =over
289  
290 =item addition
291  
292 Used for added paths. Default: green.
293  
294 =item modification
295  
296 Used for modified paths. Default: teal.
297  
298 =item deletion
299  
300 Used for deleted paths. Default: bold red.
301  
302 =item replacement
303 Used for replaced paths (a Subversion concept). Default: brown.
304  
305 =item prop_change
306  
307 Used for paths with changed properties (a Subversion concept), combined with
308 other colors depending on the action -- addition, modification or replacement.
309 Default: underline.
310  
311 =back
312  
313 =item author
314  
315 Commit author. Default: green.
316  
317 =item branch
318  
319 Commit branch. Default: brown.
320  
321 =item module
322  
323 Project module. Default: purple.
324  
325 =item web
326  
327 URL to commit information. Default: silver.
328  
329 =item separator
330  
331 The separator before the commit log. Default: none.
332  
333 =back
334  
335 =back
336  
337 =cut
338  
339 8 require v5.10.0;
340 8 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
341 8 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
342 8 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
343 8 ▶use DirHandle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
344 8 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
345 8 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
346 8 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
347 8 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
348 8 ▶use User::pwent;
Subroutine BEGIN: called CC=1 SCAR=0.0
349 8 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
350 8 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
351 8 __PACKAGE__->mk_accessors(
352 qw( repo_id servers br_mod_re mod_br_re module ignore_branch
353 single_line_commits use_irc_notices use_color status_dir verbose protocol
354 web_link short_url_service _last_server
355 msg_template
356 style colors painter
357 batch_messages
358 _full_user_name
359 )
360 );
361  
362 =head1 CONSTRUCTOR
363  
364 =head2 new ( { I<initial values> } )
365  
366 Standard constructor with initial values in a hashref.
367  
368 my $c = App::KGB::Client->new(
369 { repo_id => 'my-repo',
370 servers => \@servers,
371 ...
372 }
373 );
374  
375 See L<|FIELDS> above.
376  
377 =cut
378  
379 0 ▶sub new {
Subroutine new: not called CC=15 SCAR=54.8
Pod documented
380 0 my ( $class, $init ) = @_;
381  
382 0 my $self = $class->SUPER::new(
383 { use_color => 1,
384 %$init,
385 }
386 );
387  
388 0 ▶ print "Configuration: " . YAML::Dump(@_) if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
389  
390 0 ▶ defined( $self->repo_id )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->repo_id or confess("'repo_id' is mandatory") 0 0 0
391 or confess "'repo_id' is mandatory";
392 0 ▶ $self->br_mod_re( [ $self->br_mod_re // () ] )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->br_mod_re 0 0 0
Condition0%0/3
$self->br_mod_re // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->br_mod_re // ()
$self->br_mod_re ()
Truth table0%0/3
A // B
A= $self->br_mod_reB= ()
ABresult
1X1
011
000
393 if not ref( $self->br_mod_re );
394 0 ▶ $self->mod_br_re( [ $self->mod_br_re // () ] )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->mod_br_re 0 0 0
Condition0%0/3
$self->mod_br_re // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->mod_br_re // ()
$self->mod_br_re ()
Truth table0%0/3
A // B
A= $self->mod_br_reB= ()
ABresult
1X1
011
000
395 if not ref( $self->mod_br_re );
396  
397 0 ▶ $self->servers( [] ) unless defined( $self->servers );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->servers 0 0 0
398  
399 0 ▶ ref( $self->servers ) and ref( $self->servers ) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $self->servers and ref $self->servers eq "ARRAY" or confess("'servers' must be an arrayref") 0 0 0
Condition0%0/3
ref $self->servers and ref $self->servers eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->servers and ref $self->servers eq "ARRAY"
ref $self->servers ref $self->servers eq "ARRAY"
Truth table0%0/3
A and B
A= ref $self->serversB= ref $self->servers eq "ARRAY"
ABresult
0X0
100
111
400 or confess "'servers' must be an arrayref";
401  
402 0 ▶ @{ $self->servers } or confess "No 'servers' specified";
Branch: 1 branch
BranchTrueFalseTotal
@{$self->servers;} or confess("No 'servers' specified") 0 0 0
403  
404 0 ▶ if ( $self->status_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->status_dir) 0 0 0
405 0 ▶ if ( not -e $self->status_dir ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -e $self->status_dir) { } 0 0 0
elsif (not -d $self->status_dir) { } 0 0 0
406 0 warn "Status directory ".$self->status_dir." doesn't exist.\n";
407 0 $self->status_dir(undef);
408 }
409 elsif ( not -d $self->status_dir ) {
410 0 warn $self->status_dir." is not a directory\n";
411 0 $self->status_dir(undef);
412 }
413 }
414  
415 0 ▶ $self->protocol('auto') unless defined( $self->protocol );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->protocol 0 0 0
416  
417 0 return $self;
418 }
419  
420 =head1 METHODS
421  
422 =over
423  
424 =item detect_branch_and_module ( $changes )
425  
426 Given a set of changes (an arrayref of L<App::KGB::Change> objects), runs all
427 the regular expressions as listed in B<br_mod_re> and B<mod_br_re> and if a
428 regular expression that matches all the changed paths and returns the branch
429 and module.
430  
431 ( $branch, $module ) = $client->detect_branch_and_module($changes);
432  
433 =cut
434  
435 0 ▶sub _run_matches {
Subroutine _run_matches: not called CC=6 SCAR=37.4
436 0 my ( $safe, $changes, $res, $swap ) = @_;
437  
438 0 for my $re (@$res) {
439 0 $re =~ s{,}{\\,}g; # escape commas
440 0 ▶ my $matching = "m,$re,; " . ( $swap ? '($2,$1)' : '($1,$2)' );
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 0 0
441  
442 0 local $_ = $changes->path;
443 0 my ( $branch, $module ) = $safe->reval($matching);
444 0 ▶ die "Error while evaluating `$re': $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
445  
446 0 ▶ if ( defined($branch) and defined($module) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $branch and defined $module) 0 0 0
Condition0%0/3
defined $branch and defined $module
!ll&&!rl&&r
000
MC/DC0%0/2
defined $branch and defined $module
defined $branch defined $module
Truth table0%0/3
A and B
A= defined $branchB= defined $module
ABresult
0X0
100
111
447 0 return ( $re, $branch, $module );
448 }
449 }
450 0 return ( undef, undef, undef );
451 }
452  
453 0 ▶sub detect_branch_and_module {
Subroutine detect_branch_and_module: not called CC=17 SCAR=57.2
Pod documented
454 0 my ( $self, $changes ) = @_;
455 0 ▶ return () unless $self->br_mod_re;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->br_mod_re 0 0 0
456  
457 0 require Safe;
458 0 my $safe = Safe->new;
459 0 $safe->permit_only(
460 qw(padany lineseq match const leaveeval
461 rv2gv rv2sv pushmark list warn)
462 );
463  
464 0 my ( $branch, $module, $matched_re );
465  
466 # for a successful branch/module extraction, we require that all the
467 # changes share the same branch/module
468 0 for my $c (@$changes) {
469 0 my ( $change_branch, $change_module );
470  
471 0 ( $matched_re, $change_branch, $change_module )
472 = _run_matches( $safe, $c, $self->br_mod_re, 0 );
473 0 ▶ ( $matched_re, $change_branch, $change_module )
Branch: 1 branch
BranchTrueFalseTotal
unless $matched_re and defined $change_branch and defined $change_module 0 0 0
Condition0%0/6
$matched_re and defined $change_branch and defined $change_module
!ll&&!rl&&r
000
$matched_re and defined $change_branch
!ll&&!rl&&r
000
MC/DC0%0/3
$matched_re and defined $change_branch and defined $change_module
$matched_re defined $change_branch defined $change_module
Truth table0%0/4
A and B and C
A= $matched_reB= defined $change_branchC= defined $change_module
ABCresult
0XX0
10X0
1100
1111
474 = _run_matches( $safe, $c, $self->mod_br_re, 1 )
475 unless $matched_re
476 and defined($change_branch)
477 and defined($change_module);
478  
479 # some change cannot be tied to a branch and a module?
480 0 ▶ if ( !defined( $change_branch // $change_module ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($change_branch // $change_module)) 0 0 0
Condition0%0/3
$change_branch // $change_module
l!l&&r!l&&!r
000
MC/DC0%0/2
$change_branch // $change_module
$change_branch $change_module
Truth table0%0/3
A // B
A= $change_branchB= $change_module
ABresult
1X1
011
000
481 0 $branch = $module = $matched_re = undef;
482 0 last;
483 }
484  
485 0 ▶ if ( defined($branch) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $branch) { } 0 0 0
486  
487 # this change is for a different branch/module?
488 0 ▶ if ( $branch ne $change_branch or $module ne $change_module ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($branch ne $change_branch or $module ne $change_module) 0 0 0
Condition0%0/3
$branch ne $change_branch or $module ne $change_module
l!l&&r!l&&!r
000
MC/DC0%0/2
$branch ne $change_branch or $module ne $change_module
$branch ne $change_branch $module ne $change_module
Truth table0%0/3
A or B
A= $branch ne $change_branchB= $module ne $change_module
ABresult
1X1
011
000
489 0 $branch = $module = $matched_re = undef;
490 0 last;
491 }
492 }
493 else {
494  
495 # first change, store branch and module
496 0 $branch = $change_branch;
497 0 $module = $change_module;
498 }
499 }
500  
501 # remove the part that have matched as it contains information about the
502 # branch and module that we provide otherwise
503 0 ▶ if ($matched_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matched_re) 0 0 0
504  
505 #warn "Branch: ".($branch||"NONE");
506 #warn "Module: ".($module||"NONE");
507 0 $safe->permit(qw(subst));
508 0 for my $c (@$changes) {
509  
510 #warn "FROM ".$c->{path};
511 0 $_ = $c->path;
512 0 $safe->reval("s,.*$matched_re,,");
513 0 ▶ die "Eror while evaluating s/.*$matched_re//: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
514 0 $c->path($_);
515  
516 #warn " TO $_";
517 }
518 }
519  
520 0 ▶ if ( $self->verbose and $branch ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose and $branch) 0 0 0
Condition0%0/3
$self->verbose and $branch
!ll&&!rl&&r
000
MC/DC0%0/2
$self->verbose and $branch
$self->verbose $branch
Truth table0%0/3
A and B
A= $self->verboseB= $branch
ABresult
0X0
100
111
521 0 ▶ print "Detected branch '$branch' and module '"
Condition0%0/2
$module // "NONE"
l!l
00
MC/DC0%0/1
$module // "NONE"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
522 . ( $module // 'NONE' ) . "'\n";
523 }
524  
525 0 return ( $branch, $module );
526 }
527  
528 =item shuffle_servers
529  
530 Returns a shuffled variant of C<< $self-E<gt>servers >>. It considers the last
531 successfully used server by this client instance and puts it first. If there is
532 no such server, it considers the state in C<status_dir> and picks the last
533 server noted there, if it was used in the last 5 minutes.
534  
535 =cut
536  
537 0 ▶sub shuffle_servers {
Subroutine shuffle_servers: not called CC=14 SCAR=53.5
Pod documented
538 0 my $self = shift;
539  
540 0 my @servers = List::Util::shuffle( @{ $self->servers } );
541  
542 0 ▶ if ( $self->_last_server ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_last_server) { } 0 0 0
elsif ($self->status_dir) { } 0 0 0
543 # just put the last server first in the list
544 @servers = sort {
545 0 ▶ return -1 if $a->uri eq $self->_last_server->uri;
Branch: 1 branch
BranchTrueFalseTotal
if $a->uri eq $self->_last_server->uri 0 0 0
546 0 ▶ return +1 if $b->uri eq $self->_last_server->uri;
Branch: 1 branch
BranchTrueFalseTotal
if $b->uri eq $self->_last_server->uri 0 0 0
547 0 return 0;
548 } @servers;
549 }
550 elsif ( $self->status_dir ) {
551 # pick a server from the status directory
552 0 my %hashes;
553 0 do {
554 0 my $i = 0;
555 0 for (@servers) {
556 0 $hashes{ md5_hex( $_->uri ) } = $i++;
557 }
558 };
559 0 my $d = DirHandle->new( $self->status_dir );
560 0 my $latest_stamp;
561 my $latest_hash;
562 0 ▶ if ( defined $d ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d) { } 0 0 0
563 0 my $now = time;
564 0 ▶ while( defined( my $f = $d->read ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $f = $d->read)) 0 0 0
565 next
566 unless $f =~ /^kgb-client.([0-9a-f]+)$/
567 0 ▶ and exists( $hashes{$1} );
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /^kgb-client.([0-9a-f]+)$/ and exists $hashes{$1} 0 0 0
Condition0%0/3
$f =~ /^kgb-client.([0-9a-f]+)$/ and exists $hashes{$1}
!ll&&!rl&&r
000
MC/DC0%0/2
$f =~ /^kgb-client.([0-9a-f]+)$/ and exists $hashes{$1}
$f =~ /^kgb-client.([0-9a-f]+)$/ exists $hashes{$1}
Truth table0%0/3
A and B
A= $f =~ /^kgb-client.([0-9a-f]+)$/B= exists $hashes{$1}
ABresult
0X0
100
111
568  
569 0 my $file = File::Spec->catdir($self->status_dir, $f);
570  
571 0 my $stamp = (stat $file)[9];
572  
573 0 ▶ if ( $latest_stamp ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($latest_stamp) { } 0 0 0
elsif ($stamp >= $now - 300) { } 0 0 0
574 0 ▶ if( $latest_stamp < $stamp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($latest_stamp < $stamp) 0 0 0
575 0 $latest_stamp = $stamp;
576 0 $latest_hash = $1;
577 }
578 }
579 elsif ( $stamp >= ( $now - 300 ) ) {
580 # accessed in the last 5 minutes, consider it
581 0 $latest_stamp = $stamp;
582 0 $latest_hash = $1;
583 }
584 }
585  
586 0 ▶ if ( $latest_stamp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($latest_stamp) 0 0 0
587 0 my $winner = splice( @servers, $hashes{$latest_hash}, 1 );
588 0 unshift @servers, $winner;
589 }
590 }
591 else {
592 0 warn "Unable to read directory ".$self->status_dir."\n";
593 0 $self->status_dir(undef);
594 }
595 }
596  
597 0 return @servers;
598 }
599  
600 =item expand_link ($string, \%data)
601  
602 Expands items in the form I<${item}> in I<$string>, using the data in the
603 supplied hash reference.
604  
605 Passing
606  
607 "http://git/${module}.git?commit=${commit}",
608 { module => 'dh-make-perl', commit => '225ceca' }
609  
610 would result in C<http://git/dh-make-perl.git?commit=225ceca>.
611  
612 =cut
613  
614 0 ▶sub expand_link {
Subroutine expand_link: not called CC=5 SCAR=34.0
Pod documented
615 0 my ( $self, $input, $data ) = @_;
616  
617 0 my $output = '';
618 0 my $re = qr/\$\{([^{}]+)\}/p;
619  
620 0 ▶ while ( $input =~ $re ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /$re/) 0 0 0
621 0 my $f = $1;
622 0 my $v;
623 0 ▶ if ( exists $data->{$f} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{$f}) { } 0 0 0
624 0 ▶ $v = $data->{$f} // '';
Condition0%0/2
$data->{$f} // ""
l!l
00
MC/DC0%0/1
$data->{$f} // ""
$data->{$f}
Truth table0%0/2
A
A= $data->{$f}
Aresult
11
00
625 }
626 else {
627 0 $v = '';
628 0 warn "Unknown substitution '$f'\n";
629 }
630  
631 0 $output .= ${^PREMATCH} . $v;
632 0 $input = ${^POSTMATCH};
633 }
634  
635 0 ▶ warn "Web link expanded to $output\n" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
636  
637 0 return $output;
638 }
639  
640 =item shorten_url (url)
641  
642 Uses the configured I<short_url_service> to shorten the given URL. If no
643 shortening service is configured, the original URL is returned.
644  
645 =cut
646  
647 0 ▶sub shorten_url {
Subroutine shorten_url: not called CC=4 SCAR=30.0
Pod documented
648 0 my ( $self, $url ) = @_;
649 0 ▶ return $url unless my $service = $self->short_url_service;
Branch: 1 branch
BranchTrueFalseTotal
unless my $service = $self->short_url_service 0 0 0
650  
651 0 my $ok = eval {
652 0 require WWW::Shorten;
653 0 WWW::Shorten->import( $service, ':short' );
654 0 1;
655 };
656  
657 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
658 0 warn "Unable to load URL shortening service '$service': $@";
659 0 warn "Sending plain URL.\n";
660 0 return $url;
661 }
662  
663 0 my $short_url = short_link($url);
664  
665 0 ▶ return $short_url if defined($short_url);
Branch: 1 branch
BranchTrueFalseTotal
if defined $short_url 0 0 0
666  
667 0 warn "URL shortening service '$service' failed.\n";
668 0 warn "Sending plain URL.\n";
669 0 return $url;
670 }
671  
672 =item note_last_server($srv)
673  
674 If C<status_dir> is configured, notes $srv as the last used server to be used
675 in subsequent requests.
676  
677 =cut
678  
679 0 ▶sub note_last_server {
Subroutine note_last_server: not called CC=2 SCAR=17.9
Pod documented
680 0 my ( $self, $srv ) = @_;
681  
682 0 ▶ return unless $self->status_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status_dir 0 0 0
683  
684 0 require File::Touch;
685 0 File::Touch::touch(
686 File::Spec->catfile(
687 $self->status_dir,
688 sprintf( "kgb-client.%s", md5_hex( $srv->uri ) )
689 )
690 );
691 }
692  
693 8 ▶use constant rev_prefix => '';
Subroutine BEGIN: called CC=1 SCAR=0.0
694  
695 =item init_painter
696  
697 Creates an internal instance of L<App::KGB::Painter> used to color message
698 elements.
699  
700 Does nothing if I<use_color> is false or if painter has been already created.
701  
702 =cut
703  
704 0 ▶sub init_painter {
Subroutine init_painter: not called CC=3 SCAR=24.8
Pod documented
705 0 my $self = shift;
706  
707 0 ▶ return unless $self->use_color;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->use_color 0 0 0
708 0 ▶ return if $self->painter;
Branch: 1 branch
BranchTrueFalseTotal
if $self->painter 0 0 0
709  
710 0 require App::KGB::Painter;
711 0 $self->painter(
712 App::KGB::Painter->new( { item_colors => $self->colors } ) );
713 }
714  
715 =item colorize I<category> =E<gt> I<text>
716  
717 Returns a colored version of I<text>. If there is no painter, returns just
718 I<text>.
719  
720 =cut
721  
722 0 ▶sub colorize {
Subroutine colorize: not called CC=2 SCAR=17.9
Pod documented
723 0 my ( $self, $category, $text ) = @_;
724  
725 0 ▶ return $text unless $self->painter;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->painter 0 0 0
726  
727 0 return $self->painter->colorize( $category => $text );
728 }
729  
730 8 our %action_styles = (
731 A => 'addition',
732 M => 'modification',
733 D => 'deletion',
734 R => 'replacement',
735 );
736  
737 =item colorize_change I<change>
738  
739 returns a colorized string representing a single change
740  
741 =cut
742  
743 0 ▶sub colorize_change {
Subroutine colorize_change: not called CC=2 SCAR=17.9
Pod documented
744 0 my ( $self, $c ) = @_;
745  
746 0 my $action_style = $action_styles{ $c->action };
747  
748 0 my $text = $self->colorize( $action_style => $c->path );
749  
750 0 ▶ $text = $self->colorize( 'prop_change' => $text ) if $c->prop_change;
Branch: 1 branch
BranchTrueFalseTotal
if $c->prop_change 0 0 0
751  
752 0 return $text;
753 }
754  
755 8 our $MAGIC_MAX_FILES = 4;
756  
757 =item colorize_changes \@changes
758  
759 returns a colorized string of all commit's changes
760  
761 =cut
762  
763 0 ▶sub colorize_changes {
Subroutine colorize_changes: not called CC=7 SCAR=40.3
Pod documented
764 0 my ( $self, $changes ) = @_;
765  
766 0 my @info;
767  
768 0 my $changed_files = scalar @$changes;
769  
770 0 ▶ my $common_dir = App::KGB::Change->detect_common_dir($changes) // '';
Condition0%0/2
"App::KGB::Change"->detect_common_dir($changes) // ""
l!l
00
MC/DC0%0/1
"App::KGB::Change"->detect_common_dir($changes) // ""
"App::KGB::Change"->detect_common_dir($changes)
Truth table0%0/2
A
A= "App::KGB::Change"->detect_common_dir($changes)
Aresult
11
00
771  
772 0 ▶ push @info, $self->colorize( path => "$common_dir/" ) if $common_dir ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $common_dir ne "" 0 0 0
773  
774 0 ▶ if ( $changed_files > $MAGIC_MAX_FILES ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed_files > $App::KGB::Client::MAGIC_MAX_FILES) { } 0 0 0
775 0 my %dirs;
776 0 for my $c (@$changes) {
777 0 my $dir = dirname( $c->path );
778 0 $dirs{$dir}++;
779 }
780  
781 0 my $dirs = scalar( keys %dirs );
782  
783 0 ▶ my $path_string = join( ' ',
Branch: 1 branch
BranchTrueFalseTotal
$dirs > 1 ? : 0 0 0
784 ( $dirs > 1 )
785 ? sprintf( "(%d files in %d dirs)", $changed_files, $dirs )
786 : sprintf( "(%d files)", $changed_files ) );
787  
788 0 push @info, $self->colorize( path => $path_string );
789 }
790 else {
791 0 ▶ push @info, join( ' ', map { $self->colorize_change($_) } @$changes )
Branch: 1 branch
BranchTrueFalseTotal
if @$changes 0 0 0
792 if @$changes;
793 }
794  
795 0 return join( ' ', @info );
796 }
797  
798 =item format_message $template %details
799  
800 Returns a formatted message, ready to be sent to the servers. The message is
801 formatted according to the B<message_format> configuration parameter, honouring
802 B<colors> and B<use_color>.
803  
804 =cut
805  
806 0 ▶sub format_message {
Subroutine format_message: not called CC=35 SCAR=71.4
Pod documented
807 0 my ( $self, $msg, %p ) = @_;
808  
809 0 my $commit = $p{commit};
810  
811 0 $self->init_painter;
812  
813 0 my $result = '';
814 0 warn "# msg = '$msg'" if 0;
815  
816 0 ▶ if ($commit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($commit) 0 0 0
817 0 ▶ $p{author_login} = $commit->author if ($commit->author);
Branch: 1 branch
BranchTrueFalseTotal
if $commit->author 0 0 0
818 0 ▶ $p{author_name} = $commit->author_name if ($commit->author_name);
Branch: 1 branch
BranchTrueFalseTotal
if $commit->author_name 0 0 0
819 0 ▶ $p{author_via} = $commit->author_via if ($commit->author_via);
Branch: 1 branch
BranchTrueFalseTotal
if $commit->author_via 0 0 0
820 0 ▶ $p{branch} = $commit->branch if ($commit->branch);
Branch: 1 branch
BranchTrueFalseTotal
if $commit->branch 0 0 0
821 0 ▶ $p{commit_id} = $commit->id if ($commit->id);
Branch: 1 branch
BranchTrueFalseTotal
if $commit->id 0 0 0
822 0 ▶ $p{log} = $commit->log if ($commit->log);
Branch: 1 branch
BranchTrueFalseTotal
if $commit->log 0 0 0
823 }
824 0 ▶ $p{author_name} ||= $p{author_login};
Condition0%0/3
$p{"author_name"} ||= $p{"author_login"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"author_name"} ||= $p{"author_login"}
$p{"author_name"} $p{"author_login"}
Truth table0%0/3
A ||= B
A= $p{"author_name"}B= $p{"author_login"}
ABresult
1X1
011
000
825 0 ▶ $p{author_login} ||= $p{author_name};
Condition0%0/3
$p{"author_login"} ||= $p{"author_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"author_login"} ||= $p{"author_name"}
$p{"author_login"} $p{"author_name"}
Truth table0%0/3
A ||= B
A= $p{"author_login"}B= $p{"author_name"}
ABresult
1X1
011
000
826 0 ▶ $p{author_via} ||= $p{author_name};
Condition0%0/3
$p{"author_via"} ||= $p{"author_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"author_via"} ||= $p{"author_name"}
$p{"author_via"} $p{"author_name"}
Truth table0%0/3
A ||= B
A= $p{"author_via"}B= $p{"author_name"}
ABresult
1X1
011
000
827 0 ▶ if (defined($self->module)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->module) { } 0 0 0
elsif ($commit and defined $commit->module) { } 0 0 0
828 0 $p{module} = $self->module;
829 ▶ } elsif ($commit and defined($commit->module)) {
Condition0%0/3
$commit and defined $commit->module
!ll&&!rl&&r
000
MC/DC0%0/2
$commit and defined $commit->module
$commit defined $commit->module
Truth table0%0/3
A and B
A= $commitB= defined $commit->module
ABresult
0X0
100
111
830 0 $p{module} = $commit->module;
831 }
832  
833 0 ▶ while ( $msg =~ /\$\{([^{}]+)?\{([^{}]+)\}([^{}]+)?\}/ps ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ /\$\{([^{}]+)?\{([^{}]+)\}([^{}]+)?\}/ps) 0 0 0
834 0 my ( $pre, $token, $post ) = ( $1, $2, $3 );
835 0 warn "# pre = '$pre' token = '$token' post = '$post'" if 0;
836 0 $result .= ${^PREMATCH};
837 0 $msg = ${^POSTMATCH};
838 0 warn "# msg is now '$msg'" if 0;
839 0 my @r;
840  
841 0 ▶ if ( $token eq 'project' ) {
Branch: 11 branches
BranchTrueFalseTotal
if ($token eq 'project') { } 0 0 0
elsif ($token eq 'author-login') { } 0 0 0
elsif ($token eq 'author-name') { } 0 0 0
elsif ($token eq 'author-via') { } 0 0 0
elsif ($token eq 'branch') { } 0 0 0
elsif ($token eq 'module') { } 0 0 0
elsif ($token eq 'web-link') { } 0 0 0
elsif ($token eq 'commit') { } 0 0 0
elsif ($token eq 'log') { } 0 0 0
elsif ($token eq 'log-first-line') { } 0 0 0
elsif ($token eq 'changes') { } 0 0 0
842 0 push @r, project => $self->repo_id;
843 }
844 elsif ( $token eq 'author-login' ) {
845 0 push @r, author => $p{author_login};
846 }
847 elsif ( $token eq 'author-name' ) {
848 0 push @r, author => $p{author_name};
849 }
850 elsif ( $token eq 'author-via' ) {
851 0 push @r, author => $p{author_via};
852 }
853 elsif ( $token eq 'branch' ) {
854 0 push @r, branch => $p{branch};
855 }
856 elsif ( $token eq 'module' ) {
857 0 push @r, module => $p{module};
858 }
859 elsif ( $token eq 'web-link' ) {
860 0 push @r, web => $p{web_link};
861 }
862 elsif ( $token eq 'commit' ) {
863 0 push @r, commit_id => $p{commit_id};
864 }
865 elsif ( $token eq 'log' ) {
866 0 push @r, log => $p{log};
867 }
868 elsif ( $token eq 'log-first-line' ) {
869 0 push @r, log => ( split( /\n/, $p{log} ) )[0];
870 }
871 elsif ( $token eq 'changes' ) {
872 0 ▶ push @r, '' => $self->colorize_changes( $commit->changes )
Branch: 1 branch
BranchTrueFalseTotal
if $commit and $commit->changes 0 0 0
Condition0%0/3
$commit and $commit->changes
!ll&&!rl&&r
000
MC/DC0%0/2
$commit and $commit->changes
$commit $commit->changes
Truth table0%0/3
A and B
A= $commitB= $commit->changes
ABresult
0X0
100
111
873 if $commit and $commit->changes;
874 }
875 else {
876 0 push @r, '' => "Unknown item '$_'";
877 }
878  
879 0 my ( $category, $item ) = @r;
880  
881 0 warn "# item = '$item'" if 0;
882 0 ▶ next unless defined($item) and $item ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item and $item ne "" 0 0 0
Condition0%0/3
defined $item and $item ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $item and $item ne ""
defined $item $item ne ""
Truth table0%0/3
A and B
A= defined $itemB= $item ne ""
ABresult
0X0
100
111
883  
884 0 ▶ if ( defined($pre) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pre) 0 0 0
885 # avoid adding multi-spaces or spaces at the beginning
886 0 ▶ $pre =~ s/^\s+// if $result =~ /\s$/ or $result eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $result =~ /\s$/ or $result eq "" 0 0 0
Condition0%0/3
$result =~ /\s$/ or $result eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
$result =~ /\s$/ or $result eq ""
$result =~ /\s$/ $result eq ""
Truth table0%0/3
A or B
A= $result =~ /\s$/B= $result eq ""
ABresult
1X1
011
000
887 0 $result .= $pre;
888 }
889 $result .=
890 0 ▶ ( $category eq '' )
Branch: 1 branch
BranchTrueFalseTotal
$category eq '' ? : 0 0 0
891 ? $item
892 : $self->colorize( $category => $item );
893 0 ▶ $result .= $post // '';
Condition0%0/2
$post // ""
l!l
00
MC/DC0%0/1
$post // ""
$post
Truth table0%0/2
A
A= $post
Aresult
11
00
894 }
895 0 $result .= $msg;
896  
897 0 return $result;
898 }
899  
900 =item process_commit ($commit)
901  
902 Processes a single commit, returning something for sending to the remote
903 server. I<Something> is either a reference to array of arguments to be passed
904 to L<App::KGB::ServerRef>'s send_changes method, or, in message-relay mode, a
905 plain scalar string representing the commit.
906  
907 If $commit is a plain scalar (not a reference), then it is assumed to be an
908 already processed string and is returned directly.
909  
910 =cut
911  
912 0 ▶sub process_commit {
Subroutine process_commit: not called CC=15 SCAR=54.8
Pod documented
913 0 my ( $self, $commit ) = @_;
914  
915 # plain strings are already processed by the VCS-specific module
916 0 ▶ return $commit unless ref($commit);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $commit 0 0 0
917  
918 0 ▶ my $module = $self->module // $commit->module;
Condition0%0/3
$self->module // $commit->module
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->module // $commit->module
$self->module $commit->module
Truth table0%0/3
A // B
A= $self->moduleB= $commit->module
ABresult
1X1
011
000
919 0 my $branch = $commit->branch;
920  
921 0 ▶ if ( not defined($module) or not defined($branch) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module and defined $branch) 0 0 0
Condition0%0/3
defined $module and defined $branch
!ll&&!rl&&r
000
MC/DC0%0/2
defined $module and defined $branch
defined $module defined $branch
Truth table0%0/3
A and B
A= defined $moduleB= defined $branch
ABresult
0X0
100
111
922 0 my ( $det_branch, $det_module )
923 = $self->detect_branch_and_module( $commit->changes );
924  
925 0 ▶ $branch //= $det_branch;
Condition0%0/3
$branch //= $det_branch
l!l&&r!l&&!r
000
MC/DC0%0/2
$branch //= $det_branch
$branch $det_branch
Truth table0%0/3
A //= B
A= $branchB= $det_branch
ABresult
1X1
011
000
926 0 ▶ $module //= $det_module;
Condition0%0/3
$module //= $det_module
l!l&&r!l&&!r
000
MC/DC0%0/2
$module //= $det_module
$module $det_module
Truth table0%0/3
A //= B
A= $moduleB= $det_module
ABresult
1X1
011
000
927 }
928  
929 0 my $web_link = $self->web_link;
930 0 ▶ if ( defined($web_link) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $web_link) 0 0 0
931 0 $web_link = $self->expand_link(
932 $web_link,
933 { branch => $branch,
934 module => $module,
935 commit => $commit->id,
936 project => $self->repo_id
937 }
938 );
939 0 $web_link = $self->shorten_url($web_link);
940 }
941  
942 $branch = undef
943 0 ▶ if $branch and $branch eq ( $self->ignore_branch // '' );
Branch: 1 branch
BranchTrueFalseTotal
if $branch and $branch eq ($self->ignore_branch // "") 0 0 0
Condition0%0/5
$branch and $branch eq ($self->ignore_branch // "")
!ll&&!rl&&r
000
$self->ignore_branch // ""
l!l
00
MC/DC0%0/2
$branch and $branch eq ($self->ignore_branch // "")
$branch $branch eq ($self->ignore_branch // "")
MC/DC0%0/1
$self->ignore_branch // ""
$self->ignore_branch
Truth table0%0/3
A and B
A= $branchB= $branch eq ($self->ignore_branch // "")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $self->ignore_branch
Aresult
11
00
944  
945 # All data prepared. Now, how do we represent this commit?
946  
947 # A pre-formatted, pre-coloured string, if msg_template is configured
948 0 ▶ return $self->format_message(
Branch: 1 branch
BranchTrueFalseTotal
if $self->msg_template 0 0 0
949 $self->msg_template,
950 commit => $commit,
951 branch => $branch,
952 module => $module,
953 web_link => $web_link
954 ) if $self->msg_template;
955  
956 # otherwise, prepare things for send_changes()
957 0 my @args = ( $commit, $branch, $module );
958 0 my %extra;
959 0 ▶ $extra{web_link} = $web_link if defined($web_link);
Branch: 1 branch
BranchTrueFalseTotal
if defined $web_link 0 0 0
960 0 ▶ $extra{use_irc_notices} = $self->use_irc_notices
Branch: 1 branch
BranchTrueFalseTotal
if $self->use_irc_notices 0 0 0
961 if $self->use_irc_notices;
962 0 $extra{use_color} = $self->use_color;
963 0 ▶ push @args, \%extra if %extra;
Branch: 1 branch
BranchTrueFalseTotal
if %extra 0 0 0
964  
965 0 return \@args;
966 }
967  
968 =item process
969  
970 The main processing method. Calls B<describe_commit> and while it returns true
971 values, gives them to B<process_commit> and send the result to the server.
972  
973 If B<batch_messages> flag is true, relays accumulated messages after
974 processing.
975  
976 =cut
977  
978 0 ▶sub process {
Subroutine process: not called CC=6 SCAR=37.4
Pod documented
979 0 my $self = shift;
980  
981 0 my @messages;
982  
983 0 ▶ while ( my $commit = $self->describe_commit ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $commit = $self->describe_commit) 0 0 0
984 0 my $data = $self->process_commit($commit);
985  
986 0 ▶ if (ref($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) { } 0 0 0
987 # a structure to be interpreted by the server
988 0 $self->send_changes($data);
989 }
990 else {
991 # a plain string
992 0 ▶ if ( $self->batch_messages ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->batch_messages) { } 0 0 0
993 # batch it, will send the whole batch in one transaction below
994 0 push @messages, $data;
995 }
996 else {
997 # relay immediately
998 0 $self->relay_message($data);
999 }
1000 }
1001 }
1002  
1003 0 ▶ $self->relay_message( \@messages ) if $self->batch_messages and @messages;
Branch: 1 branch
BranchTrueFalseTotal
if $self->batch_messages and @messages 0 0 0
Condition0%0/3
$self->batch_messages and @messages
!ll&&!rl&&r
000
MC/DC0%0/2
$self->batch_messages and @messages
$self->batch_messages @messages
Truth table0%0/3
A and B
A= $self->batch_messagesB= @messages
ABresult
0X0
100
111
1004 }
1005  
1006 =item send_changes \@args
1007  
1008 Tries to send the changes described in the given array reference to all
1009 configured servers.
1010  
1011 =cut
1012  
1013 0 ▶sub send_changes {
Subroutine send_changes: not called CC=6 SCAR=37.4
Pod documented
1014 0 my ( $self, $args ) = @_;
1015  
1016 0 my @servers = $self->shuffle_servers;
1017  
1018 # try all servers in turn until someone succeeds
1019 0 my $failure;
1020 0 for my $srv (@servers) {
1021 0 ▶ $failure = eval {
Condition0%0/2
eval { do { $srv->send_changes($self, $self->protocol, @$args); $self->_last_server($srv); $self->note_last_server($srv); 0 } } // 1
l!l
00
MC/DC0%0/1
eval { do { $srv->send_changes($self, $self->protocol, @$args); $self->_last_server($srv); $self->note_last_server($srv); 0 } } // 1
eval { do { $srv->send_changes($self, $self->protocol, @$args); $self->_last_server($srv); $self->note_last_server($srv); 0 } }
Truth table0%0/2
A
A= eval { do { $srv->send_changes($self, $self->protocol, @$args); $self->_last_server($srv); $self->note_last_server($srv); 0 } }
Aresult
11
00
1022 0 $srv->send_changes( $self, $self->protocol, @$args );
1023 0 $self->_last_server($srv);
1024  
1025 0 $self->note_last_server($srv);
1026 0 0;
1027 } // 1;
1028  
1029 0 ▶ warn $@ if $failure;
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 0 0
1030  
1031 0 ▶ last unless $failure;
Branch: 1 branch
BranchTrueFalseTotal
unless $failure 0 0 0
1032 }
1033  
1034 0 ▶ die "Unable to complete notification. All servers failed\n"
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 0 0
1035 if $failure;
1036 }
1037  
1038 =item relay_message I<message>
1039  
1040 Send a simple message to servers for relaying. Implements the --relay-msg
1041 command line option.
1042  
1043 =cut
1044  
1045 0 ▶sub relay_message {
Subroutine relay_message: not called CC=7 SCAR=40.3
Pod documented
1046 0 my $self = shift;
1047 0 ▶ my $msg = shift // die "Syntax: \$client->relay_message(msg)";
Condition0%0/2
shift() // die("Syntax: \$client->relay_message(msg)")
l!l
00
MC/DC0%0/1
shift() // die("Syntax: \$client->relay_message(msg)")
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1048  
1049 0 my @servers = $self->shuffle_servers;
1050  
1051 # try all servers in turn until someone succeeds
1052 0 my $failure;
1053 0 for my $srv (@servers) {
1054 0 ▶ $failure = eval {
Condition0%0/2
eval { do { $srv->relay_message($self, $msg, {"use_irc_notices", $self->use_irc_notices}); $self->_last_server($srv); $self->note_last_server($srv); 0 } } // 1
l!l
00
MC/DC0%0/1
eval { do { $srv->relay_message($self, $msg, {"use_irc_notices", $self->use_irc_notices}); $self->_last_server($srv); $self->note_last_server($srv); 0 } } // 1
eval { do { $srv->relay_message($self, $msg, {"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, $msg, {"use_irc_notices", $self->use_irc_notices}); $self->_last_server($srv); $self->note_last_server($srv); 0 } }
Aresult
11
00
1055 0 $srv->relay_message( $self, $msg,
1056 { use_irc_notices => $self->use_irc_notices } );
1057 0 $self->_last_server($srv);
1058  
1059 0 $self->note_last_server($srv);
1060 0 0;
1061 } // 1;
1062  
1063 0 ▶ warn $@ if $failure;
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 0 0
1064  
1065 0 ▶ last unless $failure;
Branch: 1 branch
BranchTrueFalseTotal
unless $failure 0 0 0
1066 }
1067  
1068 0 ▶ die "Unable to relay message. All servers failed\n"
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 0 0
1069 if $failure;
1070 }
1071  
1072 0 ▶sub _get_full_user_name {
Subroutine _get_full_user_name: not called CC=4 SCAR=30.0
1073 0 my $self = shift;
1074 0 ▶ my $login = shift // $ENV{USER};
Condition0%0/3
shift() // $ENV{"USER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $ENV{"USER"}
shift() $ENV{"USER"}
Truth table0%0/3
A // B
A= shift()B= $ENV{"USER"}
ABresult
1X1
011
000
1075  
1076 0 ▶ return $self->_full_user_name if $self->_full_user_name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_full_user_name 0 0 0
1077  
1078 0 my $user = getpwnam($login);
1079 0 my $full_name = $login;
1080 0 ▶ ( $full_name = $user->gecos ) =~ s/,.*// if defined $user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $user 0 0 0
1081  
1082 0 utf8::decode($full_name);
1083  
1084 0 $self->_full_user_name($full_name);
1085  
1086 0 return $full_name;
1087 }
1088  
1089 8 1;
1090  
1091 __END__
« blib/lib/App/KGB/Client/CVS.pm ↑ Summary blib/lib/App/KGB/Client/ServerRef.pm »