blib/lib/Bit/Vector/String.pm

filter: Statementstmt 81.1% 138 / 170 Branchbran 77.9% 67 / 86 Conditioncond 54.1% 13 / 24 MC/DCmcdc 31.2% 5 / 16 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 6 totaltotal 74.7% 234 / 313 CC 52 SCAR 27.9
CC
52
Cov
78%
String_Export
29.0
new_String
18.5
String_Import
9.4
CRAP 16.2
« blib/lib/Bit/Vector/Overload.pm ↑ Summary Vector.xs »
1  
2 ###############################################################################
3 ## ##
4 ## Copyright (c) 2004 - 2013 by Steffen Beyer. ##
5 ## All rights reserved. ##
6 ## ##
7 ## This package is free software; you can redistribute it ##
8 ## and/or modify it under the same terms as Perl itself. ##
9 ## ##
10 ###############################################################################
11  
12 package Bit::Vector::String;
13  
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶use Bit::Vector;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 require Exporter;
20  
21 2 @ISA = qw(Exporter Bit::Vector);
22  
23 2 @EXPORT = qw();
24  
25 2 @EXPORT_OK = qw();
26  
27 2 $VERSION = '7.5';
28  
29 package Bit::Vector;
30  
31 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use Carp::Clan '^Bit::Vector\b';
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 2 my $Factor = log(10) / log(2);
35  
36 sub to_Oct
37 108 ▶{
Subroutine to_Oct: called CC=3 SCAR=12.5
Pod undocumented
38 108 ▶ croak('Usage: $vector->to_Oct();') unless (@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 108 108
39 108 my($self) = @_;
40 108 my($string) = '';
41 108 local $@;
42  
43 108 eval { $string = reverse(join('', $self->Chunk_List_Read(3))); };
44 108 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 108 108
45 {
46 0 $string = $@;
47 0 $string =~ s!^[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\(\):\s+!!;
48 0 $string =~ s!\s+at\s.*$!!;
49 0 croak($string);
50 }
51 108 return $string;
52 }
53  
54 sub from_Oct
55 27 ▶{
Subroutine from_Oct: called CC=4 SCAR=16.5
Pod undocumented
56 27 ▶ croak('Usage: $vector->from_Oct($string);') unless (@_ == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 27 27
57 27 my($self,$string) = @_;
58 27 local $@;
59  
60 27 ▶ if ($string =~ /^[0-7]+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^[0-7]+$/) { } 27 0 27
61 {
62 27 eval { $self->Chunk_List_Store(3, split(//, reverse($string))); };
63 27 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 27 27
64 {
65 0 $string = $@;
66 0 $string =~ s!^[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\(\):\s+!!;
67 0 $string =~ s!\s+at\s.*$!!;
68 0 croak($string);
69 }
70 }
71 else
72 {
73 0 croak("unknown string type");
74 }
75 27 return $self;
76 }
77  
78 sub new_Oct
79 54 ▶{
Subroutine new_Oct: called CC=5 SCAR=17.6
Pod undocumented
80 54 ▶ croak('Usage: Bit::Vector->new_Oct($bits,$string);') unless (@_ == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 54 54
81 54 my($class,$bits,$string) = @_;
82 54 my($self);
83 54 local $@;
84  
85 54 ▶ if ($string =~ /^[0-7]+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^[0-7]+$/) { } 54 0 54
86 {
87 54 ▶ unless (defined $bits) { $bits = 3 * length($string); }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 27 27 54
88 54 eval { $self = Bit::Vector->new($bits); $self->Chunk_List_Store(3, split(//, reverse($string))); };
89 54 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 54 54
90 {
91 0 $string = $@;
92 0 $string =~ s!^[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\(\):\s+!!;
93 0 $string =~ s!\s+at\s.*$!!;
94 0 croak($string);
95 }
96 }
97 else
98 {
99 0 croak("unknown string type");
100 }
101 54 return $self;
102 }
103  
104 sub String_Export
105 486 ▶{
Subroutine String_Export: called CC=18 SCAR=33.7
Pod undocumented
106 486 ▶ croak('Usage: $vector->String_Export($type);') unless (@_ == 1 or @_ == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 or @_ == 2 0 486 486
Condition33%1/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
04860
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table33%1/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
107 486 my($self,$type) = @_;
108 486 my($string) = '';
109 486 local $@;
110  
111 486 ▶ if (not defined $type or not $type)
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $type && $type) { } 0 486 486
elsif ($type eq '1' or $type =~ /^b(?:in)?$/i) { } 81 405 486
elsif ($type eq '2' or $type =~ /^o(?:ct)?$/i) { } 81 324 405
elsif ($type eq '3' or $type =~ /^d(?:ec)?$/i) { } 81 243 324
elsif ($type eq '4' or $type =~ /^(?:h(?:ex)?|x)$/i) { } 81 162 243
elsif ($type eq '5' or $type =~ /^e(?:num)?$/i) { } 81 81 162
elsif ($type eq '6' or $type =~ /^p(?:ack)?$/i) { } 81 0 81
Condition33%1/3
defined $type && $type
!ll&&!rl&&r
00486
MC/DC0%0/2
defined $type && $type
defined $type $type
Truth table33%1/3
A && B
A= defined $typeB= $type
ABresult
0X0
100
111
112 {
113 0 eval { $string = '0x' . $self->to_Hex(); };
114 }
115 ▶ elsif ($type eq '1' or $type =~ /^b(?:in)?$/i)
Condition66%2/3
$type eq 1 or $type =~ /^b(?:in)?$/i
l!l&&r!l&&!r
081405
MC/DC50%1/2
$type eq 1 or $type =~ /^b(?:in)?$/i
$type eq 1 $type =~ /^b(?:in)?$/i
Truth table66%2/3
A or B
A= $type eq 1B= $type =~ /^b(?:in)?$/i
ABresult
1X1
011
000
116 {
117 81 eval { $string = '0b' . $self->to_Bin(); };
118 }
119 ▶ elsif ($type eq '2' or $type =~ /^o(?:ct)?$/i)
Condition66%2/3
$type eq 2 or $type =~ /^o(?:ct)?$/i
l!l&&r!l&&!r
081324
MC/DC50%1/2
$type eq 2 or $type =~ /^o(?:ct)?$/i
$type eq 2 $type =~ /^o(?:ct)?$/i
Truth table66%2/3
A or B
A= $type eq 2B= $type =~ /^o(?:ct)?$/i
ABresult
1X1
011
000
120 {
121 81 eval { $string = '0o' . reverse(join('', $self->Chunk_List_Read(3))); };
122 }
123 ▶ elsif ($type eq '3' or $type =~ /^d(?:ec)?$/i)
Condition66%2/3
$type eq 3 or $type =~ /^d(?:ec)?$/i
l!l&&r!l&&!r
081243
MC/DC50%1/2
$type eq 3 or $type =~ /^d(?:ec)?$/i
$type eq 3 $type =~ /^d(?:ec)?$/i
Truth table66%2/3
A or B
A= $type eq 3B= $type =~ /^d(?:ec)?$/i
ABresult
1X1
011
000
124 {
125 81 eval { $string = $self->to_Dec(); };
126 }
127 ▶ elsif ($type eq '4' or $type =~ /^(?:h(?:ex)?|x)$/i)
Condition66%2/3
$type eq 4 or $type =~ /^(?:h(?:ex)?|x)$/i
l!l&&r!l&&!r
081162
MC/DC50%1/2
$type eq 4 or $type =~ /^(?:h(?:ex)?|x)$/i
$type eq 4 $type =~ /^(?:h(?:ex)?|x)$/i
Truth table66%2/3
A or B
A= $type eq 4B= $type =~ /^(?:h(?:ex)?|x)$/i
ABresult
1X1
011
000
128 {
129 81 eval { $string = '0x' . $self->to_Hex(); };
130 }
131 ▶ elsif ($type eq '5' or $type =~ /^e(?:num)?$/i)
Condition66%2/3
$type eq 5 or $type =~ /^e(?:num)?$/i
l!l&&r!l&&!r
08181
MC/DC50%1/2
$type eq 5 or $type =~ /^e(?:num)?$/i
$type eq 5 $type =~ /^e(?:num)?$/i
Truth table66%2/3
A or B
A= $type eq 5B= $type =~ /^e(?:num)?$/i
ABresult
1X1
011
000
132 {
133 81 eval { $string = '{' . $self->to_Enum() . '}'; };
134 }
135 ▶ elsif ($type eq '6' or $type =~ /^p(?:ack)?$/i)
Condition33%1/3
$type eq 6 or $type =~ /^p(?:ack)?$/i
l!l&&r!l&&!r
0810
MC/DC0%0/2
$type eq 6 or $type =~ /^p(?:ack)?$/i
$type eq 6 $type =~ /^p(?:ack)?$/i
Truth table33%1/3
A or B
A= $type eq 6B= $type =~ /^p(?:ack)?$/i
ABresult
1X1
011
000
136 {
137 81 eval { $string = ':' . $self->Size() . ':' . $self->Block_Read(); };
138 }
139 else
140 {
141 0 croak("unknown string type '$type'");
142 }
143 486 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 486 486
144 {
145 0 $string = $@;
146 0 $string =~ s!^[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\(\):\s+!!;
147 0 $string =~ s!\s+at\s.*$!!;
148 0 croak($string);
149 }
150 486 return $string;
151 }
152  
153 sub String_Import
154 306 ▶{
Subroutine String_Import: called CC=9 SCAR=22.4
Pod undocumented
155 306 ▶ croak('Usage: $vector->String_Import($string);') unless (@_ == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 306 306
156 306 my($self,$string) = @_;
157 306 my($type) = 0;
158 306 local $@;
159  
160 306 ▶ if ($string =~ /^(?:0[bB])?([01]+)$/)
Branch: 6 branches
BranchTrueFalseTotal
if ($string =~ /^(?:0[bB])?([01]+)$/) { } 54 252 306
elsif ($string =~ /^(?:0[oO])?([0-7]+)$/) { } 45 207 252
elsif ($string =~ /^(?:[+-])?[0-9]+$/) { } 54 153 207
elsif ($string =~ /^(?:0[hHxX])?([0-9A-Fa-f]+)$/) { } 45 108 153
elsif ($string =~ /^[(<{\[]?([0-9]+(?:-[0-9]+)?(?:,[0-9]+(?:-[0-9]+)?)*)[)>}\]]?$/) { } 54 54 108
elsif ($string =~ s/^:\d+://) { } 54 0 54
161 {
162 54 $type = 1;
163 54 eval { $self->from_Bin($1); };
164 }
165 elsif ($string =~ /^(?:0[oO])?([0-7]+)$/)
166 {
167 45 $type = 2;
168 45 eval { $self->Chunk_List_Store(3, split(//, reverse($1))); };
169 }
170 elsif ($string =~ /^(?:[+-])?[0-9]+$/)
171 {
172 54 $type = 3;
173 54 eval { $self->from_Dec($string); };
174 }
175 elsif ($string =~ /^(?:0[hHxX])?([0-9A-Fa-f]+)$/)
176 {
177 45 $type = 4;
178 45 eval { $self->from_Hex($1); };
179 }
180 elsif ($string =~ /^[(<{\[]?([0-9]+(?:-[0-9]+)?(?:,[0-9]+(?:-[0-9]+)?)*)[)>}\]]?$/)
181 {
182 54 $type = 5;
183 54 eval { $self->from_Enum($1); };
184 }
185 elsif ($string =~ s!^:\d+:!!)
186 {
187 54 $type = 6;
188 54 eval { $self->Block_Store($string); };
189 }
190 else
191 {
192 0 croak("unknown string type");
193 }
194 306 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 306 306
195 {
196 0 $string = $@;
197 0 $string =~ s!^[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\(\):\s+!!;
198 0 $string =~ s!\s+at\s.*$!!;
199 0 croak($string);
200 }
201 306 return $type;
202 }
203  
204 sub new_String
205 324 ▶{
Subroutine new_String: called CC=18 SCAR=29.2
Pod undocumented
206 324 ▶ croak('Usage: Bit::Vector->new_String($bits,$string);') unless (@_ == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 324 324
207 324 my($class,$bits,$string) = @_;
208 324 my($type) = 0;
209 324 my($self);
210 324 local $@;
211  
212 324 ▶ if ($string =~ /^(?:0[bB])?([01]+)$/)
Branch: 6 branches
BranchTrueFalseTotal
if ($string =~ /^(?:0[bB])?([01]+)$/) { } 54 270 324
elsif ($string =~ /^(?:0[oO])?([0-7]+)$/) { } 54 216 270
elsif ($string =~ /^(?:[+-])?([0-9]+)$/) { } 54 162 216
elsif ($string =~ /^(?:0[hHxX])?([0-9A-Fa-f]+)$/) { } 54 108 162
elsif ($string =~ /^[(<{\[]?([0-9]+(?:-[0-9]+)?(?:,[0-9]+(?:-[0-9]+)?)*)[)>}\]]?$/) { } 54 54 108
elsif ($string =~ s/^:(\d+)://) { } 54 0 54
213 {
214 54 $type = 1;
215 54 ▶ unless (defined $bits) { $bits = length($1); }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 27 27 54
216 54 eval { $self = Bit::Vector->new_Bin($bits,$1); };
217 }
218 elsif ($string =~ /^(?:0[oO])?([0-7]+)$/)
219 {
220 54 $type = 2;
221 54 ▶ unless (defined $bits) { $bits = 3 * length($1); }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 27 27 54
222 54 eval { $self = Bit::Vector->new($bits); $self->Chunk_List_Store(3, split(//, reverse($1))); };
223 }
224 elsif ($string =~ /^(?:[+-])?([0-9]+)$/)
225 {
226 54 $type = 3;
227 54 ▶ unless (defined $bits) { $bits = int( length($1) * $Factor + 1 ); }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 27 27 54
228 54 eval { $self = Bit::Vector->new_Dec($bits,$string); };
229 }
230 elsif ($string =~ /^(?:0[hHxX])?([0-9A-Fa-f]+)$/)
231 {
232 54 $type = 4;
233 54 ▶ unless (defined $bits) { $bits = 4 * length($1); }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 27 27 54
234 54 eval { $self = Bit::Vector->new_Hex($bits,$1); };
235 }
236 elsif ($string =~ /^[(<{\[]?([0-9]+(?:-[0-9]+)?(?:,[0-9]+(?:-[0-9]+)?)*)[)>}\]]?$/)
237 {
238 54 $type = 5;
239 54 $string = $1;
240 54 ▶ unless (defined $bits)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 27 27 54
241 {
242 27 $bits = 0;
243 27 ▶ while ($string =~ /([0-9]+)/g) { $bits = $1 if ($1 > $bits); }
Branch: 2 branches
BranchTrueFalseTotal
if ($string =~ /([0-9]+)/g) 958 27 985
if $1 > $bits 940 18 958
244 27 $bits++;
245 }
246 54 eval { $self = Bit::Vector->new_Enum($bits,$string); };
247 }
248 elsif ($string =~ s!^:(\d+):!!)
249 {
250 54 $type = 6;
251 54 ▶ $bits = $1 unless (defined $bits);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bits 27 27 54
252 54 eval { $self = Bit::Vector->new($bits); $self->Block_Store($string); };
253 }
254 else
255 {
256 0 croak("unknown string type");
257 }
258 324 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 324 324
259 {
260 0 $string = $@;
261 0 $string =~ s!^[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\(\):\s+!!;
262 0 $string =~ s!\s+at\s.*$!!;
263 0 croak($string);
264 }
265 324 ▶ if (wantarray) { return($self,$type); }
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 324 0 324
266 0 return $self;
267 }
268  
269 2 1;
270  
271 __END__
« blib/lib/Bit/Vector/Overload.pm ↑ Summary Vector.xs »