| 1 | package Kafka::Internals; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Kafka::Internals - Constants and functions used internally. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 VERSION | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | This documentation refers to C<Kafka::Internals> version 1.07 . | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 16 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 16 | our $VERSION = '1.07'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 16 | use Exporter qw( | |||||||||||||||||||||||||||
| 24 | import | ||||||||||||||||||||||||||||
| 25 | 16 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 16 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 28 | $APIKEY_PRODUCE | ||||||||||||||||||||||||||||
| 29 | $APIKEY_FETCH | ||||||||||||||||||||||||||||
| 30 | $APIKEY_OFFSET | ||||||||||||||||||||||||||||
| 31 | $APIKEY_METADATA | ||||||||||||||||||||||||||||
| 32 | $APIKEY_FINDCOORDINATOR | ||||||||||||||||||||||||||||
| 33 | $APIKEY_APIVERSIONS | ||||||||||||||||||||||||||||
| 34 | $APIKEY_OFFSETCOMMIT | ||||||||||||||||||||||||||||
| 35 | $APIKEY_OFFSETFETCH | ||||||||||||||||||||||||||||
| 36 | $DEFAULT_RAISE_ERROR | ||||||||||||||||||||||||||||
| 37 | $MAX_CORRELATIONID | ||||||||||||||||||||||||||||
| 38 | $MAX_INT16 | ||||||||||||||||||||||||||||
| 39 | $MAX_INT32 | ||||||||||||||||||||||||||||
| 40 | $MAX_SOCKET_REQUEST_BYTES | ||||||||||||||||||||||||||||
| 41 | $PRODUCER_ANY_OFFSET | ||||||||||||||||||||||||||||
| 42 | debug_level | ||||||||||||||||||||||||||||
| 43 | _isbig | ||||||||||||||||||||||||||||
| 44 | _get_CorrelationId | ||||||||||||||||||||||||||||
| 45 | format_message | ||||||||||||||||||||||||||||
| 46 | format_reference | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 16 | ▶ | use overload; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 16 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 16 | ▶ | use Const::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 16 | ▶ | use Data::Dumper (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 16 | use Params::Util qw( | |||||||||||||||||||||||||||
| 56 | _INSTANCE | ||||||||||||||||||||||||||||
| 57 | 16 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 16 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 16 | use Kafka qw( | |||||||||||||||||||||||||||
| 61 | %ERROR | ||||||||||||||||||||||||||||
| 62 | $ERROR_MISMATCH_ARGUMENT | ||||||||||||||||||||||||||||
| 63 | 16 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | use 5.010; | ||||||||||||||||||||||||||||
| 70 | use strict; | ||||||||||||||||||||||||||||
| 71 | use warnings; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | use Kafka::Internals qw( | ||||||||||||||||||||||||||||
| 74 | $MAX_SOCKET_REQUEST_BYTES | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | my $bin_stream_size = $MAX_SOCKET_REQUEST_BYTES; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | This module is private and should not be used directly. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | In order to achieve better performance, functions of this module do | ||||||||||||||||||||||||||||
| 84 | not perform arguments validation. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 EXPORT | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | The following constants are available for export | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | #-- Api Keys | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head3 C<$APIKEY_PRODUCE> | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | The numeric code that the C<ApiKey> in the request take for the C<ProduceRequest> request type. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||
| 99 | 16 | const our $APIKEY_PRODUCE => 0; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head3 C<$APIKEY_FETCH> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | The numeric code that the C<ApiKey> in the request take for the C<FetchRequest> request type. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||
| 106 | 16 | const our $APIKEY_FETCH => 1; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head3 C<$APIKEY_OFFSET> | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | The numeric code that the C<ApiKey> in the request take for the C<OffsetRequest> request type. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||
| 113 | 16 | const our $APIKEY_OFFSET => 2; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head3 C<$APIKEY_METADATA> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | The numeric code that the C<ApiKey> in the request take for the C<MetadataRequest> request type. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||||||||||
| 120 | 16 | const our $APIKEY_METADATA => 3; | |||||||||||||||||||||||||||
| 121 | # The numeric code that the ApiKey in the request take for the C<LeaderAndIsrRequest> request type. | ||||||||||||||||||||||||||||
| 122 | 16 | const our $APIKEY_LEADERANDISR => 4; # Not used now | |||||||||||||||||||||||||||
| 123 | # The numeric code that the ApiKey in the request take for the C<StopReplicaRequest> request type. | ||||||||||||||||||||||||||||
| 124 | 16 | const our $APIKEY_STOPREPLICA => 5; # Not used now | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head3 C<$APIKEY_OFFSETCOMMIT> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | The numeric code that the ApiKey in the request take for the C<OffsetCommitRequest> request type. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | 16 | const our $APIKEY_OFFSETCOMMIT => 8; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head3 C<$APIKEY_OFFSETFETCH> | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | The numeric code that the ApiKey in the request take for the C<OffsetFetchRequest> request type. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||
| 138 | 16 | const our $APIKEY_OFFSETFETCH => 9; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head3 C<$APIKEY_FINDCOORDINATOR> | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | The numeric code that the C<ApiKey> in the request take for the C<FindCoordinator> request type. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | 16 | const our $APIKEY_FINDCOORDINATOR => 10; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head3 C<$APIKEY_APIVERSIONS> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | The numeric code that the C<ApiKey> in the request take for the C<ApiVersions> request type. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||
| 152 | 16 | const our $APIKEY_APIVERSIONS => 18; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # Important configuration properties | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =head3 C<$MAX_SOCKET_REQUEST_BYTES> | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | The maximum number of bytes in a socket request. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | The maximum size of a request that the socket server will accept. | ||||||||||||||||||||||||||||
| 161 | Default limit (as configured in F<server.properties>) is 104857600. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||
| 164 | 16 | const our $MAX_SOCKET_REQUEST_BYTES => 100 * 1024 * 1024; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head3 C<$PRODUCER_ANY_OFFSET> | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | According to Apache Kafka documentation: 'When the producer is sending messages it doesn't actually know the offset and can fill in any | ||||||||||||||||||||||||||||
| 169 | value here it likes.' | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||
| 172 | 16 | const our $PRODUCER_ANY_OFFSET => 0; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head3 C<$MAX_CORRELATIONID> | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Largest positive integer on 32-bit machines. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | 16 | const our $MAX_CORRELATIONID => 0x7fffffff; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =head3 C<$MAX_INT32> | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | Largest positive integer on 32-bit machines. | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||
| 186 | 16 | const our $MAX_INT32 => 0x7fffffff; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head3 C<$MAX_INT16> | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Largest positive int16 value. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||
| 193 | 16 | const our $MAX_INT16 => 0x7fff; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | #-- public functions ----------------------------------------------------------- | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | #-- private functions ---------------------------------------------------------- | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # Used to generate a CorrelationId. | ||||||||||||||||||||||||||||
| 200 | sub _get_CorrelationId { | ||||||||||||||||||||||||||||
| 201 | 10174 | ▶ | return( -int( rand( $MAX_CORRELATIONID ) ) ); | ||||||||||||||||||||||||||
|
Subroutine
_get_CorrelationId: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # Verifies that the argument is of Math::BigInt type | ||||||||||||||||||||||||||||
| 205 | sub _isbig { | ||||||||||||||||||||||||||||
| 206 | 10386 | ▶ | my ( $num ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_isbig: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 10386 | return defined _INSTANCE( $num, 'Math::BigInt' ); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | #-- public attributes ---------------------------------------------------------- | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =head2 METHODS | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | The following methods are defined in the C<Kafka::Internals>: | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | #-- public methods ------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head3 C<debug_level( $flags )> | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Gets or sets debug level for a particular L<Kafka|Kafka> module, based on environment variable C<PERL_KAFKA_DEBUG> or flags. | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | $flags - (string) argument that can be used to pass coma delimited module names (omit C<Kafka::>). | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | Returns C<$DEBUG> level for the module from which C<debug_level> was called. | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||
| 230 | 16 | our %_debug_levels; # per-module levels cache to speed-up multiple calls to debug_level() | |||||||||||||||||||||||||||
| 231 | sub debug_level { | ||||||||||||||||||||||||||||
| 232 | 16 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 36552 | ▶ | my $class = ref( $_[0] ) || $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
debug_level: called CC=8 SCAR=20.8
Pod
documented
Condition66%2/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 36552 | ▶ | return ${ $_debug_levels{ $class } } if @_ == 1 && exists $_debug_levels{ $class }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 and exists $Kafka::Internals::_debug_levels{$class}
MC/DC100%2/2
@_ == 1 and exists $Kafka::Internals::_debug_levels{$class}
@_ == 1
exists $Kafka::Internals::_debug_levels{$class}
Truth table100%3/3
A and B
A= @_ == 1B= exists $Kafka::Internals::_debug_levels{$class}
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 31 | ▶ | my $flags = $_[1] // $ENV{PERL_KAFKA_DEBUG}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$_[1] // $ENV{"PERL_KAFKA_DEBUG"}
MC/DC100%2/2
$_[1] // $ENV{"PERL_KAFKA_DEBUG"}
$_[1]
$ENV{"PERL_KAFKA_DEBUG"}
Truth table100%3/3
A // B
A= $_[1]B= $ENV{"PERL_KAFKA_DEBUG"}
| |||||||||||||||||||||||||||||
| 239 | 31 | ▶ | if( defined $flags ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 9 | foreach my $spec ( split /\s*,\s*/, $flags ) { | |||||||||||||||||||||||||||
| 241 | 12 | my @elements = split( /\s*:\s*/, $spec, 2 ); | |||||||||||||||||||||||||||
| 242 | 12 | my( $module_name, $level ); | |||||||||||||||||||||||||||
| 243 | 12 | ▶ | if ( scalar( @elements ) > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 8 | ( $module_name, $level ) = @elements; | |||||||||||||||||||||||||||
| 245 | } else { | ||||||||||||||||||||||||||||
| 246 | 4 | $module_name = ( $class =~ /([^:]+)$/ )[0]; | |||||||||||||||||||||||||||
| 247 | 4 | $level = $spec; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 12 | *{ "Kafka::${module_name}::DEBUG" } = \$level; ## no critic | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | 31 | $_debug_levels{ $class } = \${ "${class}::DEBUG" }; ## no critic | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 31 | return ${ $_debug_levels{ $class } }; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =head2 format_reference | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | say format_reference( $object ); | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | Dumps reference using preconfigured L<Data::Dumper>. Produces less verbose | ||||||||||||||||||||||||||||
| 263 | output than default L<Data::Dumper> settings. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =cut | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 16 | my $dumper; | |||||||||||||||||||||||||||
| 268 | 16 | my $empty_array = []; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | sub format_reference { | ||||||||||||||||||||||||||||
| 271 | 62 | ▶ | my ( $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
format_reference: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 62 | ▶ | unless( $dumper ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 5 | $dumper = Data::Dumper->new( $empty_array ) | |||||||||||||||||||||||||||
| 275 | ->Indent( 0 ) | ||||||||||||||||||||||||||||
| 276 | ->Terse( 1 ) | ||||||||||||||||||||||||||||
| 277 | ->Quotekeys( 0 ) | ||||||||||||||||||||||||||||
| 278 | ->Sortkeys( 1 ) | ||||||||||||||||||||||||||||
| 279 | ->Useperl( 1 ) # XS version seems to have a bug which sometimes results in modification of original object | ||||||||||||||||||||||||||||
| 280 | # ->Sparseseen( 1 ) # speed up since we don't use "Seen" hash | ||||||||||||||||||||||||||||
| 281 | ; | ||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 62 | my $r; | |||||||||||||||||||||||||||
| 285 | 62 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
overload::Overloaded($value) and overload::Method($value, "\"\"")
MC/DC50%1/2
overload::Overloaded($value) and overload::Method($value, "\"\"")
overload::Overloaded($value)
overload::Method($value, "\"\"")
Truth table66%2/3
A and B
A= overload::Overloaded($value)B= overload::Method($value, "\"\"")
| |||||||||||||||||||||||||||||
| 286 | overload::Overloaded( $value ) && | ||||||||||||||||||||||||||||
| 287 | overload::Method( $value, '""' ) | ||||||||||||||||||||||||||||
| 288 | ) { | ||||||||||||||||||||||||||||
| 289 | 8 | $r = "$value"; # force stringification | |||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||
| 291 | 54 | $r = $dumper->Values( [ $value ] )->Dump; | |||||||||||||||||||||||||||
| 292 | 54 | $dumper->Reset->Values( $empty_array ); | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 62 | return $r; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =head2 format_message | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | $string = format_message( 'Object %d loaded. Status: %s', $id, $message ); | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | Returns string formatted using printf-style syntax. | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | If there are more than one argument and the first argument contains C<%...> | ||||||||||||||||||||||||||||
| 305 | conversions, arguments are converted to a string message using C<sprintf()>. In this case, undefined | ||||||||||||||||||||||||||||
| 306 | values are printed as C<< <undef> >> and references are converted to strings using L</format_reference>. | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =cut | ||||||||||||||||||||||||||||
| 309 | sub format_message { | ||||||||||||||||||||||||||||
| 310 | 825 | ▶ | my $format = shift // return; | ||||||||||||||||||||||||||
|
Subroutine
format_message: called CC=9 SCAR=22.9
Pod
documented
Condition50%1/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 825 | my $got = scalar @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 825 | ▶ | return $format unless $got && $format =~ /\%/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$got and $format =~ /\%/
MC/DC0%0/2
$got and $format =~ /\%/
$got
$format =~ /\%/
Truth table33%1/3
A and B
A= $gotB= $format =~ /\%/
| |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 825 | my $expected = 0; | |||||||||||||||||||||||||||
| 317 | 825 | ▶ | while ( $format =~ /(%%|%[^%])/g ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 1821 | ▶ | next if $1 eq '%%'; # don't count escape sequence | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 1821 | ++$expected; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 825 | ▶ | Carp::cluck "Wrong number of arguments: $expected vs $got" unless $got == $expected; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | return sprintf $format, map { | ||||||||||||||||||||||||||||
| 325 | 825 | ▶ | !defined $_ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 326 | ? '<undef>' | ||||||||||||||||||||||||||||
| 327 | : ref $_ | ||||||||||||||||||||||||||||
| 328 | ? format_reference( $_ ) | ||||||||||||||||||||||||||||
| 329 | : $_ | ||||||||||||||||||||||||||||
| 330 | } @_; | ||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | #-- private attributes --------------------------------------------------------- | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | #-- private methods ------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 16 | 1; | |||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | __END__ | ||||||||||||||||||||||||||||