| 1 | package TeamCity::BuildMessages; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use 5.008004; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | use version; our $VERSION = qv('v0.999.3'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | use autodie qw< :default >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use Carp qw< croak >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 3 | ▶ | use IO::Handle; # Create methods on standard filehandles like STDOUT. | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 3 | ▶ | use Exporter qw< import >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 3 | our @EXPORT_OK = | |||||||||
| 23 | qw< | ||||||||||
| 24 | teamcity_escape | ||||||||||
| 25 | teamcity_emit_build_message | ||||||||||
| 26 | >; | ||||||||||
| 27 | 3 | our %EXPORT_TAGS = ( | |||||||||
| 28 | all => [@EXPORT_OK], | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 3 | Readonly::Scalar my $IDENTIFIER_REGEX => qr< \A \w [\w\d]* \z >xms; | |||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 15 | ▶ | sub teamcity_escape { | ||||||||
|
Subroutine
teamcity_escape: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 15 | my ($original) = @_; | |||||||||
| 37 | |||||||||||
| 38 | 15 | (my $escaped = $original) =~ s< ( ['|\]] ) ><|$1>xmsg; | |||||||||
| 39 | 15 | $escaped =~ s< \n ><|n>xmsg; | |||||||||
| 40 | 15 | $escaped =~ s< \r ><|r>xmsg; | |||||||||
| 41 | |||||||||||
| 42 | 15 | return $escaped; | |||||||||
| 43 | } # end teamcity_escape() | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub teamcity_emit_build_message { ## no critic (RequireArgUnpacking) | ||||||||
|
Subroutine
teamcity_emit_build_message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | 0 | _emit_build_message_to_handle(\*STDOUT, @_); | |||||||||
| 48 | |||||||||||
| 49 | 0 | return; | |||||||||
| 50 | } # end teamcity_emit_build_message() | ||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | 10 | ▶ | sub _emit_build_message_to_handle { | ||||||||
|
Subroutine
_emit_build_message_to_handle: called CC=8 SCAR=20.8
| |||||||||||
| 54 | 10 | my ($handle, $message, @values) = @_; | |||||||||
| 55 | |||||||||||
| 56 | 10 | ▶ | croak 'No message specified.' if not $message; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 9 | ▶ | croak 'No values specified.' if not @values; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 8 | ▶ | croak qq<"$message" is not a valid message name.> | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | if $message !~ $IDENTIFIER_REGEX; | ||||||||||
| 60 | |||||||||||
| 61 | 7 | print {$handle} "##teamcity[$message"; | |||||||||
| 62 | |||||||||||
| 63 | 7 | ▶ | if (@values == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 3 | print {$handle} q< '>, teamcity_escape($values[0]), q<'>; | |||||||||
| 65 | } else { | ||||||||||
| 66 | 4 | ▶ | if (@values % 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 1 | croak 'Message property given without a value.'; | |||||||||
| 68 | } # end if | ||||||||||
| 69 | |||||||||||
| 70 | 3 | ▶ | while (@values) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 4 | my $name = shift @values; | |||||||||
| 72 | 4 | my $value = shift @values; | |||||||||
| 73 | |||||||||||
| 74 | 4 | ▶ | croak qq<"$name" is not a valid property name.> | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | if $name !~ $IDENTIFIER_REGEX; | ||||||||||
| 76 | |||||||||||
| 77 | 3 | print {$handle} qq< $name='>, teamcity_escape($value), q<'>; | |||||||||
| 78 | } # end while | ||||||||||
| 79 | } # end if | ||||||||||
| 80 | |||||||||||
| 81 | 5 | print {$handle} "]\n"; | |||||||||
| 82 | |||||||||||
| 83 | 5 | return; | |||||||||
| 84 | } # end _emit_build_message_to_handle() | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | 3 | 1; # Magic true value required at end of module. | |||||||||
| 88 | |||||||||||
| 89 | __END__ | ||||||||||