AST/Data/Scan/Impl/Perl5/_BaseTypes.pm

filter: Statementstmt 52.5% 41 / 78 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 10 / 20 Podpod n/a totaltotal 38.6% 51 / 132 CC 17 SCAR 24.6
CC
17
Cov
38%
__ANON__
30.0
_rangeMessage
20.0
__ANON__
20.0
CRAP 11.7
« AST.pm ↑ Summary AST/MooseX/_BaseTypes.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Languages::IDL::AST::Data::Scan::Impl::Perl5::_BaseTypes;
5  
6 # ABSTRACT: IDL Base Types library
7  
8 3 our $VERSION = '0.007'; # VERSION
9  
10 # AUTHORITY
11  
12 use Type::Library
13 3 ▶ -base,
Subroutine BEGIN: called CC=1 SCAR=0.0
14 -declare => qw/IDL_floatingPtType
15 IDL_nativeFloatingPtType
16 IDL_signedShortIntType
17 IDL_signedLongIntType
18 IDL_signedLonglongIntType
19 IDL_unsignedShortIntType
20 IDL_unsignedLongIntType
21 IDL_unsignedLonglongIntType
22 IDL_charType
23 IDL_wideCharType
24 IDL_stringType
25 IDL_wideStringType
26 IDL_booleanType
27 IDL_octetType
28 IDL_objectType
29 IDL_valueBaseType
30 3 IDL_anyType/;
31 3 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 3 my %INT_RANGES = (
35 IDL_signedShortIntType => [ -2**15, 2**15 - 1 ],
36 IDL_signedLongIntType => [ -2**31, 2**31 - 1 ],
37 IDL_signedLonglongIntType => [ -2**63, 2**63 - 1 ],
38 IDL_unsignedShortIntType => [ 0, 2**16 - 1 ],
39 IDL_unsignedLongIntType => [ 0, 2**32 - 1 ],
40 IDL_unsignedLonglongIntType => [ 0, 2**64 - 1 ],
41 IDL_octetType => [ 0, 255 ]
42 );
43  
44 0 ▶sub _rangeMessage {
Subroutine _rangeMessage: not called CC=4 SCAR=30.0
45 0 my ($thisType, $baseType, $value) = @_;
46  
47 0 my ($min, $max) = @{$INT_RANGES{$thisType}};
48 0 ▶ return $baseType->get_message($value) if ! $baseType->check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $baseType->check($value) 0 0 0
49 0 ▶ return "$value < $min ($thisType minimum)" if $value < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $value < $min 0 0 0
50 0 ▶ return "$value > $max ($thisType maximum)" if $value > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $value > $max 0 0 0
51 0 return 'Unknown reason (!?)'
52 }
53  
54 42 ▶sub _rangeCheckInlined {
Subroutine _rangeCheckInlined: called CC=1 SCAR=0.0
55 42 my ($thisType, $constraint, $varname) = @_;
56  
57 42 my ($min, $max) = @{$INT_RANGES{$thisType}};
58 42 return $constraint->parent->inline_check($varname) . " && ($varname >= $min) && ($varname <= $max)"
59 }
60  
61 0 ▶sub _rangeCheck {
Subroutine _rangeCheck: not called CC=2 SCAR=17.9
62 0 my ($thisType, $value) = @_;
63  
64 0 my ($min, $max) = @{$INT_RANGES{$thisType}};
65 0 ▶ return ($value >= $min) && ($value <= $max)
Condition0%0/3
$value >= $min && $value <= $max
!ll&&!rl&&r
000
MC/DC0%0/2
$value >= $min && $value <= $max
$value >= $min $value <= $max
Truth table0%0/3
A && B
A= $value >= $minB= $value <= $max
ABresult
0X0
100
111
66 }
67  
68 3 class_type IDL_floatingPtType, { class => 'Math::BigFloat' };
69 3 declare IDL_nativeFloatingPtType, as Num;
70 #
71 # Ranges all share the same declaration syntax
72 #
73 3 foreach my $type (keys %INT_RANGES) {
74 declare $type, as Int,
75 0 ▶ where { return _rangeCheck ($type, $_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 42 ▶ inline_as { return _rangeCheckInlined($type, @_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 0 ▶ message { return _rangeMessage ($type, Int, $_) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 21 }
79 declare IDL_charType,
80 as Str,
81 0 ▶ where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
82 0 ▶ return (length($_) == 1) && (ord($_) <= 255)
Condition0%0/3
length $_ == 1 && ord $_ <= 255
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ == 1 && ord $_ <= 255
length $_ == 1 ord $_ <= 255
Truth table0%0/3
A && B
A= length $_ == 1B= ord $_ <= 255
ABresult
0X0
100
111
83 },
84 6 ▶ inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
85 6 my ($constraint, $varname) = @_;
86 6 return $constraint->parent->inline_check($varname) . " && (length($varname) == 1) && (ord($varname) <= 255)"
87 },
88 0 ▶ message {
Subroutine __ANON__: not called CC=4 SCAR=30.0
89 0 ▶ return Str->get_message($_) if ! Str->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Str()->check($_) 0 0 0
90 0 my $oups;
91 0 ▶ return "length must be 1 instead of $oups" if (($oups = length($_)) != 1);
Branch: 1 branch
BranchTrueFalseTotal
if ($oups = length $_) != 1 0 0 0
92 0 ▶ return "ordinal must be <= 255 instead of ". sprintf('0x%x', $oups) if (($oups = ord($_)) > 255);
Branch: 1 branch
BranchTrueFalseTotal
if ($oups = ord $_) > 255 0 0 0
93 0 return 'Unknown reason (!?)'
94 3 };
95  
96 declare IDL_wideCharType,
97 as Str,
98 0 ▶ where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 return length($_) == 1
100 },
101 6 ▶ inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 6 my ($constraint, $varname) = @_;
103 6 return $constraint->parent->inline_check($varname) . " && (length($varname) == 1)"
104 },
105 0 ▶ message {
Subroutine __ANON__: not called CC=3 SCAR=24.8
106 0 ▶ return Str->get_message($_) if ! Str->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Str()->check($_) 0 0 0
107 0 my $oups;
108 0 ▶ return "length must be 1 instead of $oups" if ($oups = length($_)) != 1;
Branch: 1 branch
BranchTrueFalseTotal
if ($oups = length $_) != 1 0 0 0
109 0 return 'Unknown reason (!?)'
110 3 };
111 declare IDL_stringType,
112 as Str,
113 0 ▶ where {
Subroutine __ANON__: not called CC=3 SCAR=24.8
114 0 my $rc = 1;
115 0 foreach (split('', $_)) {
116 0 ▶ if (ord($_) > 255) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $_ > 255) 0 0 0
117 0 $rc = undef;
118 last
119 0 }
120 }
121 0 return $rc
122 },
123 6 ▶ inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
124 6 my ($constraint, $varname) = @_;
125 6 return $constraint->parent->inline_check($varname) . " && do {my \$rc = 1; foreach (split('', $varname)) { if (ord(\$_) > 255) { \$rc = undef; last } } \$rc }"
126 },
127 0 ▶ message {
Subroutine __ANON__: not called CC=5 SCAR=34.0
128 0 ▶ return Str->get_message($_) if ! Str->check($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Str()->check($_) 0 0 0
129 0 my ($pos, $oups) = (0, undef);
130 0 foreach (split('', $_)) {
131 0 ▶ last if (($oups = ord($_)) > 255);
Branch: 1 branch
BranchTrueFalseTotal
if ($oups = ord $_) > 255 0 0 0
132 0 ++$pos
133 }
134 0 ▶ return "must not contain any ordinal > 255, but has ordinal " . sprintf('0x%x', $oups) . " at position $pos" if ($oups);
Branch: 1 branch
BranchTrueFalseTotal
if $oups 0 0 0
135 0 return 'Unknown reason (!?)';
136 3 };
137 3 declare IDL_wideStringType, as Str;
138 3 declare IDL_booleanType, as Bool;
139 3 declare IDL_objectType, as Object;
140 3 declare IDL_valueBaseType, as Object;
141 3 declare IDL_anyType, as Any;
142  
143 3 1;
144  
145 __END__
« AST.pm ↑ Summary AST/MooseX/_BaseTypes.pm »