blib/lib/TeamCity/Message.pm

filter: Statementstmt 100% 37 / 37 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 91.0% 51 / 56 CC 7 SCAR 14.7
CC
7
Cov
91%
tc_message
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.4
↑ Summary
1 package TeamCity::Message;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7  
8 1 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ## no critic (Modules::ProhibitAutomaticExportation)
13 1 our @EXPORT = qw( tc_message );
14 ## use critic
15  
16 sub tc_message {
17 6 ▶ my %args = @_;
Subroutine tc_message: called CC=7 SCAR=19.8
Pod documented
18  
19 6 ▶ my $type = delete $args{type} || 'message';
Condition50%1/2
delete $args{'type'} || 'message'
l!l
60
MC/DC0%0/1
delete $args{'type'} || 'message'
delete $args{'type'}
Truth table50%1/2
A
A= delete $args{'type'}
Aresult
11
00
20 my $content = delete $args{content}
21 6 ▶ or die 'You must provide a content argument to tc_message()';
Branch: 1 branch
BranchTrueFalseTotal
my $content = delete $args{"content"} or die "You must provide a content argument to tc_message()" 0 6 6
22  
23 6 my $msg = "##teamcity[$type";
24  
25 6 ▶ if ( ref $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content) { } 4 2 6
26 4 for my $name ( sort keys %{$content} ) {
27 5 my $value = $content->{$name};
28 5 $msg .= qq{ $name='} . _escape($value) . q{'};
29 }
30  
31 $msg .= _timestamp()
32 4 ▶ unless $content->{timestamp};
Branch: 1 branch
BranchTrueFalseTotal
unless $content->{"timestamp"} 4 0 4
33 }
34 else {
35 2 ▶ $msg .= q{ '} . _escape($content) . q{'} or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$msg .= q[ '] . _escape($content) . q['] or die $! 0 2 2
36 }
37  
38 6 $msg .= "]\n";
39  
40 6 return $msg;
41 }
42  
43 sub _timestamp {
44 4 ▶ my $now = time;
Subroutine _timestamp: called CC=1 SCAR=0.0
45  
46 4 my ( $s, $mi, $h, $d, $mo, $y ) = ( gmtime($now) )[ 0 .. 5 ];
47  
48 4 my $float = ( $now - int($now) );
49 4 return sprintf(
50 q{ timestamp='%4d-%02d-%02dT%02d:%02d:%02d.%03d'},
51 $y + 1900, $mo + 1, $d,
52 $h, $mi, $s,
53  
54 # We only need 3 places of precision so if we multiply it be 1,000 we
55 # can just treat it as an integer.
56 $float * 1000,
57 );
58 }
59  
60 sub _escape {
61 7 ▶ my $str = shift;
Subroutine _escape: called CC=1 SCAR=0.0
62  
63 7 ( my $esc = $str ) =~ s{(['|\]])}{|$1}g;
64 7 $esc =~ s{\n}{|n}g;
65 7 $esc =~ s{\r}{|r}g;
66  
67 7 return $esc;
68 }
69  
70 1 1;
71  
72 # ABSTRACT: Generate TeamCity build messages
73  
74 __END__
↑ Summary