| 1 | # vim: set sw=2 ft=perl: | ||||||||||||||||||||||||||||||
| 2 | package DBIx::Class::Sims::Types; | ||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | 54 | ▶ | use 5.010_001; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 54 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use DBIx::Class::Sims; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | DBIx::Class::Sims->set_sim_types({ | ||||||||||||||||||||||||||||||
| 10 | 54 | map { $_ => __PACKAGE__->can($_) } qw( | |||||||||||||||||||||||||||||
| 11 | email_address ip_address | ||||||||||||||||||||||||||||||
| 12 | us_firstname us_lastname us_name | ||||||||||||||||||||||||||||||
| 13 | us_address us_city us_county us_phone us_ssntin us_state us_zipcode | ||||||||||||||||||||||||||||||
| 14 | ) | ||||||||||||||||||||||||||||||
| 15 | }); | ||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | # This is to allow Sims types to be usable outside the context of a Sims run. | ||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub default_column { | ||||||||||||||||||||||||||||
|
Subroutine
default_column: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 19 | 0 | return bless { | |||||||||||||||||||||||||||||
| 20 | predictable_values => 0, | ||||||||||||||||||||||||||||||
| 21 | name => 'default', | ||||||||||||||||||||||||||||||
| 22 | source => bless { | ||||||||||||||||||||||||||||||
| 23 | name => 'default', | ||||||||||||||||||||||||||||||
| 24 | }, 'DBIx::Class::Sims::Source', | ||||||||||||||||||||||||||||||
| 25 | }, 'DBIx::Class::Sims::Column'; | ||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||
| 29 | 54 | my @tlds = qw( | |||||||||||||||||||||||||||||
| 30 | com net org gov mil co.uk co.es | ||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 12002 | ▶ | sub email_address { | ||||||||||||||||||||||||||||
|
Subroutine
email_address: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 34 | 12002 | my ($info, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 35 | 12002 | ▶ | $info //= {}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$info //= {}
MC/DC0%0/1
$info //= {}
$info
Truth table50%1/2
A
A= $info
| |||||||||||||||||||||||||||||||
| 36 | 12002 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 12002 | ▶ | my $size = $info->{data_length} // $info->{size} // 7; | ||||||||||||||||||||||||||||
|
Condition80%4/5
($info->{"data_length"} // $info->{"size"}) // 7
$info->{"data_length"} // $info->{"size"}
MC/DC50%1/2
($info->{"data_length"} // $info->{"size"}) // 7
$info->{"data_length"}
$info->{"size"}
Truth table66%2/3
A // B
A= $info->{"data_length"}B= $info->{"size"}
| |||||||||||||||||||||||||||||||
| 39 | 12002 | ▶ | if ( $size < 7 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 40 | 600 | return ''; | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | # This is okay with predictable_values because random_item() returns the | ||||||||||||||||||||||||||||||
| 44 | # 0th index. | ||||||||||||||||||||||||||||||
| 45 | 11402 | my $tld = $column->random_item(\@tlds); | |||||||||||||||||||||||||||||
| 46 | 11402 | ▶ | while ( $size - length($tld) < 4 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 47 | 148 | $tld = $column->random_item(\@tlds); | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | # Don't always create an address to fill the full amount. | ||||||||||||||||||||||||||||||
| 51 | 11402 | ▶ | if ( $size > 20 && $column->random_choice(.5) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$size > 20 and $column->random_choice("0.5")
MC/DC100%2/2
$size > 20 and $column->random_choice("0.5")
$size > 20
$column->random_choice("0.5")
Truth table100%3/3
A and B
A= $size > 20B= $column->random_choice("0.5")
| |||||||||||||||||||||||||||||||
| 52 | 5315 | $size -= $column->random_integer(0, $size-20); | |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 11402 | $size -= length($tld) + 1 + 1; # + . for $tld + @ | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | # Split size evenly-ish, but with randomness | ||||||||||||||||||||||||||||||
| 58 | 11402 | my $acct_size = int($size/2); | |||||||||||||||||||||||||||||
| 59 | 11402 | $size -= $acct_size; | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 11402 | my $acct = $column->random_string("0"x$acct_size, ['a'..'z','A'..'Z','0'..'9'] ); | |||||||||||||||||||||||||||||
| 62 | 11402 | ▶ | if ( $acct_size > 5 && $column->random_choice(.1) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$acct_size > 5 and $column->random_choice("0.1")
MC/DC100%2/2
$acct_size > 5 and $column->random_choice("0.1")
$acct_size > 5
$column->random_choice("0.1")
Truth table100%3/3
A and B
A= $acct_size > 5B= $column->random_choice("0.1")
| |||||||||||||||||||||||||||||||
| 63 | 1751 | my $n = $column->random_integer(0, $acct_size - 4) + 2; | |||||||||||||||||||||||||||||
| 64 | 1751 | substr($acct, $n, 1) = '+'; | |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 11402 | my $domain = $column->random_string("c"x$size); | |||||||||||||||||||||||||||||
| 68 | 11402 | ▶ | if ( $size > 5 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | 10129 | my $n = $column->random_integer(0, $size - 4) + 2; | |||||||||||||||||||||||||||||
| 70 | 10129 | substr($domain, $n, 1) = '.'; | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 11402 | return "${acct}\@${domain}.${tld}"; | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 54 | ▶ | sub ip_address { | ||||||||||||||||||||||||||||
|
Subroutine
ip_address: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 78 | 120 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 79 | 120 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 80 | 120 | return join '.', map { $column->random_integer(0, 256) } 1 .. 4; | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||
| 84 | 54 | my @street_names = qw( | |||||||||||||||||||||||||||||
| 85 | Main Court House Mill Wood Millwood | ||||||||||||||||||||||||||||||
| 86 | First Second Third Fourth Fifth Sixth Seventh Eight Ninth | ||||||||||||||||||||||||||||||
| 87 | Magnolia Acacia Poppy Cherry Rose Daisy Daffodil | ||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 54 | my @street_types = qw( | |||||||||||||||||||||||||||||
| 91 | Street Drive Place Avenue Boulevard Lane | ||||||||||||||||||||||||||||||
| 92 | St Dr Pl Av Ave Blvd Ln | ||||||||||||||||||||||||||||||
| 93 | St. Dr. Pl. Av. Ave. Blvd. Ln. | ||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 120 | ▶ | sub us_address { | ||||||||||||||||||||||||||||
|
Subroutine
us_address: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 97 | 120 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 98 | 120 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 99 | # Assume a varchar-like column type with enough space. | ||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | 120 | ▶ | if ( $column->random_choice(.7) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 102 | # We want to change this so that distribution is by number of digits, then | ||||||||||||||||||||||||||||||
| 103 | # randomly within the numbers. | ||||||||||||||||||||||||||||||
| 104 | 97 | my $number = $column->random_integer(1, 99999); | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | 97 | my $street_name = $column->random_item(\@street_names); | |||||||||||||||||||||||||||||
| 107 | 97 | my $street_type = $column->random_item(\@street_types); | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | 97 | return "$number $street_name $street_type"; | |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||
| 112 | 23 | ▶ | my $po = $column->random_choice(.5) ? 'PO' : 'P.O.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 113 | 23 | return "$po Box " . $column->random_integer(1, 99999); | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||
| 119 | 54 | my @city_names = qw( | |||||||||||||||||||||||||||||
| 120 | Ithaca Jonestown Marysville Ripon Minneapolis Miami Paris London Columbus | ||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||
| 122 | 54 | push @city_names, ( | |||||||||||||||||||||||||||||
| 123 | 'New York', 'Los Angeles', 'Montego By The Bay', | ||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 120 | ▶ | sub us_city { | ||||||||||||||||||||||||||||
|
Subroutine
us_city: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 127 | 120 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 128 | 120 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 129 | # Assume a varchar-like column type with enough space. | ||||||||||||||||||||||||||||||
| 130 | 120 | return $column->random_item(\@city_names); | |||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||
| 135 | 54 | my @county_names = qw( | |||||||||||||||||||||||||||||
| 136 | Adams Madison Washinton Union Clark | ||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | 120 | ▶ | sub us_county { | ||||||||||||||||||||||||||||
|
Subroutine
us_county: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 140 | 120 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 141 | 120 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 142 | # Assume a varchar-like column type with enough space. | ||||||||||||||||||||||||||||||
| 143 | 120 | return $column->random_item(\@county_names); | |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||
| 148 | 54 | my @first_names = qw( | |||||||||||||||||||||||||||||
| 149 | Aidan Bill Charles Doug Evan Frank George Hunter Ilya Jeff Kilgore | ||||||||||||||||||||||||||||||
| 150 | Liam Michael Nathan Oscar Perry Robert Shawn Thomas Urkul Victor Xavier | ||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||
| 152 | Alexandra Betty Camille Debra Ellen Fatima Georgette Hettie Imay Jaime | ||||||||||||||||||||||||||||||
| 153 | Kathrine Leticia Margaret Nellie Ophelia Patsy Regina Sybil Tricia Valerie | ||||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||
| 156 | 241 | ▶ | sub us_firstname { | ||||||||||||||||||||||||||||
|
Subroutine
us_firstname: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 157 | 241 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 158 | 241 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 159 | # Assume a varchar-like column type with enough space. | ||||||||||||||||||||||||||||||
| 160 | 241 | return $column->random_item(\@first_names); | |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||
| 165 | 54 | my @last_names = qw( | |||||||||||||||||||||||||||||
| 166 | Jones Smith Taylor Kinyon Williams Shaner Perry Raymond Moore O'Malley | ||||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||||
| 168 | # Some last names are two words. | ||||||||||||||||||||||||||||||
| 169 | 54 | push @last_names, ( | |||||||||||||||||||||||||||||
| 170 | "Von Trapp", "Van Kirk", | ||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||
| 173 | 240 | ▶ | sub us_lastname { | ||||||||||||||||||||||||||||
|
Subroutine
us_lastname: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 174 | 240 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 175 | 240 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 176 | # Assume a varchar-like column type with enough space. | ||||||||||||||||||||||||||||||
| 177 | 240 | return $column->random_item(\@last_names); | |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||||
| 182 | 54 | my @letters = ( 'A' .. 'Z' ); | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | 54 | my @suffixes = ( | |||||||||||||||||||||||||||||
| 185 | 'Jr', 'Sr', 'II', 'III', 'IV', 'Esq.', | ||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | 120 | ▶ | sub us_name { | ||||||||||||||||||||||||||||
|
Subroutine
us_name: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 189 | 120 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 190 | 120 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 191 | # Assume a varchar-like column type with enough space. | ||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||
| 193 | 120 | my @name = us_firstname(@_); | |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | # 10% chance of adding a middle initial | ||||||||||||||||||||||||||||||
| 196 | 120 | ▶ | if ( $column->random_choice(.1) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 197 | 25 | push @name, $column->random_item(\@letters) . '.'; | |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||
| 200 | 120 | push @name, us_lastname(@_); | |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||
| 202 | # 10% chance of adding a suffix | ||||||||||||||||||||||||||||||
| 203 | 120 | ▶ | if ( $column->random_choice(.1) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 204 | 28 | push @name, $column->random_item(\@suffixes); | |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | 120 | return join ' ', @name; | |||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||
| 211 | 54 | ▶ | sub us_phone { | ||||||||||||||||||||||||||||
|
Subroutine
us_phone: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 212 | 1300 | my ($info, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 213 | 1300 | ▶ | $info //= {}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$info //= {}
MC/DC0%0/1
$info //= {}
$info
Truth table50%1/2
A
A= $info
| |||||||||||||||||||||||||||||||
| 214 | 1300 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||
| 216 | # Assume a varchar-like column type. | ||||||||||||||||||||||||||||||
| 217 | 1300 | ▶ | my $length = $info->{data_length} // $info->{size} // 8; | ||||||||||||||||||||||||||||
|
Condition80%4/5
($info->{"data_length"} // $info->{"size"}) // 8
$info->{"data_length"} // $info->{"size"}
MC/DC50%1/2
($info->{"data_length"} // $info->{"size"}) // 8
$info->{"data_length"}
$info->{"size"}
Truth table66%2/3
A // B
A= $info->{"data_length"}B= $info->{"size"}
| |||||||||||||||||||||||||||||||
| 218 | 1300 | ▶ | if ( $length < 7 ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 219 | 100 | return ''; | |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||
| 221 | elsif ( $length == 7 ) { | ||||||||||||||||||||||||||||||
| 222 | 120 | return $column->random_regex('\d{7}'); | |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||
| 224 | elsif ( $length < 10 ) { | ||||||||||||||||||||||||||||||
| 225 | 360 | return $column->random_regex('\d{3}-\d{4}'); | |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||
| 227 | elsif ( $length < 12 ) { | ||||||||||||||||||||||||||||||
| 228 | 240 | return $column->random_regex('\d{10}'); | |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||
| 230 | elsif ( $length == 12 ) { | ||||||||||||||||||||||||||||||
| 231 | 120 | return $column->random_regex('\d{3}-\d{3}-\d{4}'); | |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||
| 233 | # random_regex() throws a warning no matter how I try to specify the parens. | ||||||||||||||||||||||||||||||
| 234 | # It does the right thing, but noisily. So, just concatenate them. | ||||||||||||||||||||||||||||||
| 235 | elsif ( $length == 13 ) { | ||||||||||||||||||||||||||||||
| 236 | 120 | return '(' . $column->random_regex('\d{3}') . ')' . $column->random_regex('\d{3}-\d{4}'); | |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||
| 238 | else { #if ( $length >= 14 ) { | ||||||||||||||||||||||||||||||
| 239 | 240 | return '(' . $column->random_regex('\d{3}') . ') ' . $column->random_regex('\d{3}-\d{4}'); | |||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||
| 243 | 120 | ▶ | sub us_ssntin { | ||||||||||||||||||||||||||||
|
Subroutine
us_ssntin: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 244 | 120 | my (undef, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 245 | 120 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | # Give strong preference to a SSN | ||||||||||||||||||||||||||||||
| 248 | 120 | ▶ | if ( $column->random_choice(.8) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 249 | 101 | return $column->random_regex('\d{3}-\d{2}-\d{4}'); | |||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||
| 251 | # But still generate employer TINs to mix it up. | ||||||||||||||||||||||||||||||
| 252 | else { | ||||||||||||||||||||||||||||||
| 253 | 19 | return $column->random_regex('\d{2}-\d{7}'); | |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||
| 257 | { | ||||||||||||||||||||||||||||||
| 258 | 54 | my @states = ( | |||||||||||||||||||||||||||||
| 259 | [ AL => 'Alabama' ], | ||||||||||||||||||||||||||||||
| 260 | [ AK => 'Alaska' ], | ||||||||||||||||||||||||||||||
| 261 | [ AZ => 'Arizona' ], | ||||||||||||||||||||||||||||||
| 262 | [ AR => 'Arkansas' ], | ||||||||||||||||||||||||||||||
| 263 | [ CA => 'California' ], | ||||||||||||||||||||||||||||||
| 264 | [ CO => 'Colorado' ], | ||||||||||||||||||||||||||||||
| 265 | [ CT => 'Connecticut' ], | ||||||||||||||||||||||||||||||
| 266 | [ DE => 'Delaware' ], | ||||||||||||||||||||||||||||||
| 267 | [ FL => 'Florida' ], | ||||||||||||||||||||||||||||||
| 268 | [ GA => 'Georgia' ], | ||||||||||||||||||||||||||||||
| 269 | [ HI => 'Hawaii' ], | ||||||||||||||||||||||||||||||
| 270 | [ ID => 'Idaho' ], | ||||||||||||||||||||||||||||||
| 271 | [ IL => 'Illinois' ], | ||||||||||||||||||||||||||||||
| 272 | [ IN => 'Indiana' ], | ||||||||||||||||||||||||||||||
| 273 | [ IA => 'Iowa' ], | ||||||||||||||||||||||||||||||
| 274 | [ KS => 'Kansas' ], | ||||||||||||||||||||||||||||||
| 275 | [ KY => 'Kentucky' ], | ||||||||||||||||||||||||||||||
| 276 | [ LA => 'Louisiana' ], | ||||||||||||||||||||||||||||||
| 277 | [ ME => 'Maine' ], | ||||||||||||||||||||||||||||||
| 278 | [ MD => 'Maryland' ], | ||||||||||||||||||||||||||||||
| 279 | [ MA => 'Massachusetts' ], | ||||||||||||||||||||||||||||||
| 280 | [ MI => 'Michigan' ], | ||||||||||||||||||||||||||||||
| 281 | [ MN => 'Minnesota' ], | ||||||||||||||||||||||||||||||
| 282 | [ MS => 'Mississippi' ], | ||||||||||||||||||||||||||||||
| 283 | [ MO => 'Missouri' ], | ||||||||||||||||||||||||||||||
| 284 | [ MT => 'Montana' ], | ||||||||||||||||||||||||||||||
| 285 | [ NE => 'Nebraska' ], | ||||||||||||||||||||||||||||||
| 286 | [ NJ => 'New Jersey' ], | ||||||||||||||||||||||||||||||
| 287 | [ NH => 'New Hampshire' ], | ||||||||||||||||||||||||||||||
| 288 | [ NV => 'Nevada' ], | ||||||||||||||||||||||||||||||
| 289 | [ NM => 'New Mexico' ], | ||||||||||||||||||||||||||||||
| 290 | [ NY => 'New York' ], | ||||||||||||||||||||||||||||||
| 291 | [ NC => 'North Carolina' ], | ||||||||||||||||||||||||||||||
| 292 | [ ND => 'North Dakota' ], | ||||||||||||||||||||||||||||||
| 293 | [ OH => 'Ohio' ], | ||||||||||||||||||||||||||||||
| 294 | [ OK => 'Oklahoma' ], | ||||||||||||||||||||||||||||||
| 295 | [ OR => 'Oregon' ], | ||||||||||||||||||||||||||||||
| 296 | [ PA => 'Pennsylvania' ], | ||||||||||||||||||||||||||||||
| 297 | [ RI => 'Rhode Island' ], | ||||||||||||||||||||||||||||||
| 298 | [ SC => 'South Carolina' ], | ||||||||||||||||||||||||||||||
| 299 | [ SD => 'South Dakota' ], | ||||||||||||||||||||||||||||||
| 300 | [ TN => 'Tennessee' ], | ||||||||||||||||||||||||||||||
| 301 | [ TX => 'Texas' ], | ||||||||||||||||||||||||||||||
| 302 | [ UT => 'Utah' ], | ||||||||||||||||||||||||||||||
| 303 | [ VT => 'Vermont' ], | ||||||||||||||||||||||||||||||
| 304 | [ VA => 'Virginia' ], | ||||||||||||||||||||||||||||||
| 305 | [ WA => 'Washington' ], | ||||||||||||||||||||||||||||||
| 306 | [ WV => 'West Virginia' ], | ||||||||||||||||||||||||||||||
| 307 | [ WI => 'Wisconsin' ], | ||||||||||||||||||||||||||||||
| 308 | [ WY => 'Wyoming' ], | ||||||||||||||||||||||||||||||
| 309 | # These are territories, not states, but that's okay. | ||||||||||||||||||||||||||||||
| 310 | [ AS => 'American Samoa' ], | ||||||||||||||||||||||||||||||
| 311 | [ DC => 'District Of Columbia' ], | ||||||||||||||||||||||||||||||
| 312 | [ GU => 'Guam' ], | ||||||||||||||||||||||||||||||
| 313 | [ MD => 'Midway Islands' ], | ||||||||||||||||||||||||||||||
| 314 | [ NI => 'Northern Mariana Islands' ], | ||||||||||||||||||||||||||||||
| 315 | [ PR => 'Puerto Rico' ], | ||||||||||||||||||||||||||||||
| 316 | [ VI => 'Virgin Islands' ], | ||||||||||||||||||||||||||||||
| 317 | ); | ||||||||||||||||||||||||||||||
| 318 | 480 | ▶ | sub us_state { | ||||||||||||||||||||||||||||
|
Subroutine
us_state: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 319 | 480 | my ($info, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 320 | 480 | ▶ | $info //= {}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$info //= {}
MC/DC0%0/1
$info //= {}
$info
Truth table50%1/2
A
A= $info
| |||||||||||||||||||||||||||||||
| 321 | 480 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||
| 323 | # Assume a varchar-like column type. | ||||||||||||||||||||||||||||||
| 324 | 480 | ▶ | my $length = $info->{data_length} // $info->{size} // 2; | ||||||||||||||||||||||||||||
|
Condition80%4/5
($info->{"data_length"} // $info->{"size"}) // 2
$info->{"data_length"} // $info->{"size"}
MC/DC50%1/2
($info->{"data_length"} // $info->{"size"}) // 2
$info->{"data_length"}
$info->{"size"}
Truth table66%2/3
A // B
A= $info->{"data_length"}B= $info->{"size"}
| |||||||||||||||||||||||||||||||
| 325 | 480 | ▶ | if ( $length == 2 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 326 | 240 | return $column->random_item(\@states)->[0]; | |||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||
| 328 | 240 | return substr($column->random_item(\@states)->[1], 0, $length); | |||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||
| 332 | 54 | ▶ | sub us_zipcode { | ||||||||||||||||||||||||||||
|
Subroutine
us_zipcode: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 333 | 1463 | my ($info, undef, $column) = @_; | |||||||||||||||||||||||||||||
| 334 | 1463 | ▶ | $info //= {}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$info //= {}
MC/DC0%0/1
$info //= {}
$info
Truth table50%1/2
A
A= $info
| |||||||||||||||||||||||||||||||
| 335 | 1463 | ▶ | $column //= default_column(); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$column //= default_column()
MC/DC0%0/2
$column //= default_column()
$column
default_column()
Truth table33%1/3
A //= B
A= $columnB= default_column()
| |||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||
| 337 | 1463 | my $datatype = $info->{data_type}; | |||||||||||||||||||||||||||||
| 338 | 1463 | ▶ | if ( $datatype eq 'varchar' || $datatype eq 'char' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$datatype eq "varchar" or $datatype eq "char"
MC/DC100%2/2
$datatype eq "varchar" or $datatype eq "char"
$datatype eq "varchar"
$datatype eq "char"
Truth table100%3/3
A or B
A= $datatype eq "varchar"B= $datatype eq "char"
| |||||||||||||||||||||||||||||||
| 339 | 1362 | ▶ | my $length = $info->{data_length} // $info->{size} // 10; | ||||||||||||||||||||||||||||
|
Condition100%5/5
($info->{"data_length"} // $info->{"size"}) // 10
$info->{"data_length"} // $info->{"size"}
MC/DC100%2/2
($info->{"data_length"} // $info->{"size"}) // 10
$info->{"data_length"}
$info->{"size"}
Truth table100%3/3
A // B
A= $info->{"data_length"}B= $info->{"size"}
| |||||||||||||||||||||||||||||||
| 340 | 1362 | ▶ | if ( $length < 5 ) { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 341 | 400 | return ''; | |||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||
| 343 | elsif ( $length < 9 ) { | ||||||||||||||||||||||||||||||
| 344 | 480 | return $column->random_regex('\d{5}'); | |||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||
| 346 | elsif ( $length == 9 ) { | ||||||||||||||||||||||||||||||
| 347 | 122 | return $column->random_regex('\d{9}'); | |||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||
| 349 | else { | ||||||||||||||||||||||||||||||
| 350 | 360 | return $column->random_regex('\d{5}-\d{4}'); | |||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||
| 353 | # Treat it as an int. | ||||||||||||||||||||||||||||||
| 354 | else { | ||||||||||||||||||||||||||||||
| 355 | 101 | return $column->random_integer(0, 99999); | |||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||
| 359 | 54 | 1; | |||||||||||||||||||||||||||||
| 360 | __END__ | ||||||||||||||||||||||||||||||