blib/lib/MarpaX/ESLIF/String.pm

filter: Statementstmt 50.0% 27 / 54 Branchbran 12.5% 4 / 32 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 15.6% 5 / 32 Podpod 100% 3 / 3 totaltotal 33.3% 42 / 126 CC 18 SCAR 14.2
CC
18
Cov
37%
__ANON__
6.0
__ANON__
5.7
__ANON__
5.7
CRAP 4.1
« blib/lib/MarpaX/ESLIF/Value/Type.pm ↑ Summary blib/lib/MarpaX/ESLIF/JSON/Decoder/RecognizerInterface.pm »
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 #
5 # Based on BSON::String v1.10.2
6 #
7 package MarpaX::ESLIF::String;
8 11 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: ESLIF String is any string value with encoding attribute
11  
12 11 our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY
13  
14 11 our $VERSION = '6.0.35.1'; # VERSION
15  
16  
17 4 ▶sub new {
Subroutine new: called CC=5 SCAR=16.3
Pod documented
18 4 my ($class, $value, $encoding) = @_;
19  
20 4 ▶ croak 'Undefined value' unless defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 4 4
21 4 ▶ croak 'Undefined encoding' unless defined($encoding);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $encoding 0 4 4
22  
23 4 $value = "$value"; # Make sure it is a PV
24 4 $encoding = "$encoding"; # Make sure it is a PV
25  
26 #
27 # We TRUST the encoding. If user lies, behaviour will be undetermined.
28 #
29 4 my $lcEncoding = lc($encoding);
30 4 ▶ if ($lcEncoding eq 'utf8' || $lcEncoding eq 'utf-8') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lcEncoding eq "utf8" or $lcEncoding eq "utf-8") 2 2 4
Condition66%2/3
$lcEncoding eq "utf8" or $lcEncoding eq "utf-8"
l!l&&r!l&&!r
022
MC/DC50%1/2
$lcEncoding eq "utf8" or $lcEncoding eq "utf-8"
$lcEncoding eq "utf8" $lcEncoding eq "utf-8"
Truth table66%2/3
A or B
A= $lcEncoding eq "utf8"B= $lcEncoding eq "utf-8"
ABresult
1X1
011
000
31 2 utf8::upgrade($value)
32 }
33  
34 4 return bless {value => $value, encoding => $encoding}, $class
35 }
36  
37 0 ▶sub encoding {
Subroutine encoding: not called CC=1 SCAR=6.9
Pod documented
38 # my ($self) = @_;
39 return $_[0]->{encoding} # For performance
40 0 }
41  
42 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
43 # my ($self) = @_;
44 return $_[0]->{value} # For performance
45 0 }
46  
47 11 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=5.4
48 # Unary
49 0 ▶ q{bool} => sub { !! $_[0]->{value} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 ▶ q{""} => sub { $_[0]->{value} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 ▶ q{0+} => sub { 0+ $_[0]->{value} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 ▶ q{~} => sub { ~( $_[0]->{value} ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 # Binary
54 0 ▶ ( map { $_ => eval "sub { return \$_[0]->{value} $_ \$_[1] }" } qw( + * ) ), ## no critic
Subroutine __ANON__: not called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=2.6
55 (
56 map {
57 0 ▶ $_ => eval ## no critic
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Subroutine __ANON__: not called CC=2 SCAR=17.4
Branch: 12 branches
BranchTrueFalseTotal
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
$_[2] ? : 0 0 0
58 "sub { return \$_[2] ? \$_[1] $_ \$_[0]->{value} : \$_[0]->{value} $_ \$_[1] }"
59 } qw( - / % ** << >> x <=> cmp & | ^ )
60 ),
61 (
62 0 ▶ map { $_ => eval "sub { return $_(\$_[0]->{value}) }" } ## no critic
Subroutine __ANON__: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
63 qw( cos sin exp log sqrt int )
64 ),
65 0 ▶ q{atan2} => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
66 0 ▶ return $_[2] ? atan2( $_[1], $_[0]->{value} ) : atan2( $_[0]->{value}, $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
67 },
68  
69 # Special
70 11 fallback => 1
71 11 );
72  
73  
74 11 1;
75  
76 __END__
« blib/lib/MarpaX/ESLIF/Value/Type.pm ↑ Summary blib/lib/MarpaX/ESLIF/JSON/Decoder/RecognizerInterface.pm »