RandGen/CharClass.pm

filter: Statementstmt 36.2% 21 / 58 Branchbran 11.5% 3 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod 33.3% 1 / 3 totaltotal 30.6% 31 / 101 CC 16 SCAR 33.4
CC
16
Cov
28%
pick
56.0
_buildCharset
42.0
dump
6.0
CRAP 28.3
« RandGen/Grammar.pm ↑ Summary RandGen/Condition.pm »
1 # $Revision: #5 $$Date: 2005/08/31 $$Author: jd150722 $
2 ######################################################################
3 #
4 # This program is Copyright 2003-2005 by Jeff Dutton.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of either the GNU General Public License or the
8 # Perl Artistic License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # If you do not have a copy of the GNU General Public License write to
16 # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
17 # MA 02139, USA.
18 ######################################################################
19  
20 package Parse::RandGen::CharClass;
21  
22 4 require 5.006_001;
23 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Parse::RandGen qw($Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use vars qw(@ISA $Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 @ISA = ('Parse::RandGen::Condition');
28  
29 3 ▶sub _newDerived {
Subroutine _newDerived: called CC=4 SCAR=15.2
30 3 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 3 0 3
31 3 my $type = ref($self);
32 3 my $elem = $self->element();
33 3 ▶ (ref($elem) eq "Regexp") or confess("%Error: CharClass element is not a regular expression (\"$elem\")! Must be a regular expression!");
Branch: 1 branch
BranchTrueFalseTotal
ref $elem eq "Regexp" or confess(qq[%Error: CharClass element is not a regular expression ("$elem")! Must be a regular expression!]) 3 0 3
34 3 ▶ ($elem =~ m/(\(\?[imsx]*-?[imsx]*\:)+((\[\^?.+\])|\.)/ ) or confess("%Error: CharClass element is malformed (\"$elem\")! Must be a regular expression matching a single character of a character class (e.g. (?-imsx:[^a-f\n]).");
Branch: 1 branch
BranchTrueFalseTotal
$elem =~ /(\(\?[imsx]*-?[imsx]*\:)+((\[\^?.+\])|\.)/ or confess(qq[%Error: CharClass element is malformed ("$elem")! Must be a regular expression matching a single character of a character class (e.g. (?-imsx:[^a-f\n]).]) 0 3 3
35 0 $self->_buildCharset();
36 }
37  
38 3 ▶sub isQuantSupported { return 1; }
Subroutine isQuantSupported: called CC=1 SCAR=0.0
Pod undocumented
39  
40 0 ▶sub dump {
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
41 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
42 0 return ($self->element().$self->quant());
43 }
44  
45 0 ▶sub pick {
Subroutine pick: not called CC=7 SCAR=40.3
Pod documented
46 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
47 0 my %args = ( match=>1, # Default is to pick matching data
48 @_ );
49  
50 0 my %result = $self->pickRepetitions(%args);
51 0 my $matchCnt = $result{matchCnt};
52 0 my $badOne = $result{badOne};
53  
54 0 my $min; my $max;
55 0 my $val = "";
56 0 ▶ for (my $i=0; $i < $matchCnt; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $matchCnt) 0 0 0
57 0 ▶ if (defined($badOne) && ($i==$badOne)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $badOne and $i == $badOne) { } 0 0 0
Condition0%0/3
defined $badOne and $i == $badOne
!ll&&!rl&&r
000
MC/DC0%0/2
defined $badOne and $i == $badOne
defined $badOne $i == $badOne
Truth table0%0/3
A and B
A= defined $badOneB= $i == $badOne
ABresult
0X0
100
111
58 0 $min = $self->{_charsetEndOffset};
59 0 $max = 256;
60 } else {
61 0 $min = 0;
62 0 $max = $self->{_charsetEndOffset};
63 }
64 0 my $chrOffset = $min + int(rand($max-$min));
65 0 $val .= substr($self->{_charset}, $chrOffset, 1);
66 }
67 0 my $elem = $self->element();
68 0 ▶ if ($Debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parse::RandGen::CharClass::Debug) 0 0 0
69 0 ▶ print("Parse::RandGen::CharClass($elem)::pick(match=>$args{match}, matchCnt=>$matchCnt, badOne=>".(defined($badOne)?$badOne:"undef")
Branch: 1 branch
BranchTrueFalseTotal
defined $badOne ? : 0 0 0
70 ." with value of ".$self->dumpVal($val)."\n");
71 }
72 0 return ($val);
73 }
74  
75 0 ▶sub _buildCharset {
Subroutine _buildCharset: not called CC=6 SCAR=37.4
76 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
77 0 my $elem = $self->element();
78 0 ▶ ($elem =~ /(\[\^?.+\])|\./) or confess("%Error: CharClass element is malformed (\"$elem\")! Must be a regular expression looking character class (e.g. [^a-f\n]).");
Branch: 1 branch
BranchTrueFalseTotal
$elem =~ /(\[\^?.+\])|\./ or confess(qq[%Error: CharClass element is malformed ("$elem")! Must be a regular expression looking character class (e.g. [^a-f\n]).]) 0 0 0
79  
80 0 my $reCharSet = qr/$elem/;
81 0 my $strGood = "";
82 0 my $strBad = "";
83 0 foreach my $ord (0..255) {
84 0 my $char = chr($ord);
85 0 ▶ if ($char =~ $reCharSet) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /$reCharSet/) { } 0 0 0
86 0 $strGood .= $char;
87 } else {
88 0 $strBad .= $char;
89 }
90 }
91 0 $self->{_charsetEndOffset} = length($strGood);
92 0 $self->{_charset} = ($strGood . $strBad);
93 0 my $len = length($self->{_charset});
94 0 ▶ ($len == 256) or confess("Charset length is $len (all charsets should be 256 characters)!\n");
Branch: 1 branch
BranchTrueFalseTotal
$len == 256 or confess("Charset length is $len (all charsets should be 256 characters)!\n") 0 0 0
95 }
96  
97 ######################################################################
98 #### Package return
99 4 1;
100 __END__
« RandGen/Grammar.pm ↑ Summary RandGen/Condition.pm »