blib/lib/String/Sprintf.pm

filter: Statementstmt 90.3% 28 / 31 Branchbran 64.2% 9 / 14 Conditioncond 63.6% 7 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 73.9% 51 / 69 CC 12 SCAR 21.4
CC
12
Cov
79%
formatter
13.0
sprintf
4.0
BEGIN
1.0
CRAP 8.5
↑ Summary
1 package String::Sprintf;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 $VERSION = '1.004';
7  
8  
9 7 ▶sub formatter { # constructor
Subroutine formatter: called CC=9 SCAR=25.6
Pod documented
10 7 my $class = shift;
11 7 ▶ (@_ % 2) and croak "Odd number of arguments";
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 and croak("Odd number of arguments") 0 7 7
12 7 my %handler = @_;
13 7 ▶ $handler{'*'} ||= 'sprintf'; # default
Condition50%1/2
$handler{"*"} ||= "sprintf"
l!l
07
MC/DC0%0/1
$handler{"*"} ||= "sprintf"
$handler{"*"}
Truth table50%1/2
A
A= $handler{"*"}
Aresult
11
00
14  
15 # sanity check
16 7 my @errors;
17 7 ▶ while(my($k, $v) = each %handler) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %handler) 11 7 18
18 11 ▶ UNIVERSAL::isa($v, 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($v, "CODE") or not defined $v or $v eq "sprintf" or push @errors, $k 11 0 11
Condition66%4/6
UNIVERSAL::isa($v, "CODE") or not defined $v or $v eq "sprintf"
l!l&&r!l&&!r
470
UNIVERSAL::isa($v, "CODE") or not defined $v
l!l&&r!l&&!r
407
MC/DC0%0/3
UNIVERSAL::isa($v, "CODE") or not defined $v or $v eq "sprintf"
UNIVERSAL::isa($v, "CODE") not defined $v $v eq "sprintf"
Truth table50%2/4
A or not(B) or C
A= UNIVERSAL::isa($v, "CODE")B= not defined $vC= $v eq "sprintf"
ABCresult
1XX1
01X1
0011
0000
19 or !defined $v
20 or $v eq 'sprintf'
21 or push @errors, $k;
22 }
23 7 ▶ if(@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 0 7 7
24 0 my $errors = join ', ', @errors;
25 0 ▶ my($s, $have) = @errors == 1 ? ('', 'has') : ('s', 'have');
Branch: 1 branch
BranchTrueFalseTotal
@errors == 1 ? : 0 0 0
26 0 croak "Format$s $errors $have no CODE ref as a handler";
27 }
28 7 return bless \%handler, $class;
29 }
30  
31 8 ▶sub sprintf {
Subroutine sprintf: called CC=4 SCAR=13.9
Pod documented
32 8 my($self, $string, @values) = @_;
33 8 my $i = 0;
34 8 $string =~ s(\%(?:\%|([+\-\d.]*)([a-zA-Z]))){
35 11 ▶ $2 ? do {
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 10 1 11
36 10 ▶ if(ref(my $handler = $self->{$2} || $self->{'*'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $handler = $self->{$2} || $self->{'*'})) { } 6 4 10
Condition66%2/3
$self->{$2} || $self->{'*'}
l!l&&r!l&&!r
640
MC/DC0%0/2
$self->{$2} || $self->{'*'}
$self->{$2} $self->{'*'}
Truth table66%2/3
A || B
A= $self->{$2}B= $self->{'*'}
ABresult
1X1
011
000
37 6 $handler->($1, $values[$i++], \@values, $2);
38 } else {
39 4 CORE::sprintf("%$1$2", $values[$i++]);
40 }
41 } : '%'
42 }ge;
43 8 return $string;
44 }
45  
46 5 42;
47  
48 __END__
↑ Summary