blib/lib/Scalar/Constant.pm

filter: Statementstmt 100% 29 / 29 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 97.7% 44 / 45 CC 6 SCAR 13.2
CC
6
Cov
97%
import
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.7
↑ Summary
1 package Scalar::Constant;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Scalar::Quote 'quote';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 $VERSION = 0.001_005;
10  
11  
12 4 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
13 4 my $module = shift;
14 4 ▶ my %constant = @_
Branch: 1 branch
BranchTrueFalseTotal
my(%constant) = or return 2 2 4
15 or return;
16  
17 2 my $calling_package = (caller)[0];
18 2 my @code;
19 2 ▶ while(my($name, $value) = each %constant) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %constant) 5 1 6
20 5 ▶ if(ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 1 4 5
21 1 croak 'References are not supported';
22 }
23 4 ▶ if(! looks_like_number($value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($value)) 2 2 4
24 2 $value = quote($value);
25 }
26 4 push @code, sprintf('*%s::%s = \ %s;', $calling_package, $name, $value);
27 }
28  
29 1 my $code = join("\n", @code);
30 1 ▶ eval $code
Branch: 1 branch
BranchTrueFalseTotal
eval $code or confess("This shouldn't happen: $@") 1 0 1
31 or confess "This shouldn't happen: $@";
32 }
33  
34 3 1; # Magic true value required at end of module
35 __END__
↑ Summary