Sims/Random.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 6 totaltotal 85.5% 71 / 83 CC 7 SCAR 6.5
CC
7
Cov
92%
random_decimal
6.0
random_integer
2.0
random_string
2.0
CRAP 1.9
« Sims/Source.pm ↑ Summary Sims/Relationship.pm »
1 # vim: set sw=2 ft=perl:
2 package DBIx::Class::Sims::Random;
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 base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 54 our @EXPORT_OK = qw(
11 random_integer
12 random_decimal
13 random_string
14 random_regex
15 random_item
16 random_choice
17 );
18  
19 54 ▶use String::Random ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 17896 ▶sub random_integer {
Subroutine random_integer: called CC=2 SCAR=6.9
Pod undocumented
22 17896 my ($column, $min, $max) = @_;
23 17896 ▶ return $min if $column->{predictable_values};
Branch: 1 branch
BranchTrueFalseTotal
if $column->{"predictable_values"} 2540 15356 17896
24 15356 return int(rand($max-$min))+$min;
25 }
26  
27 0 ▶sub random_decimal {
Subroutine random_decimal: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my ($column, $min, $max) = @_;
29 0 ▶ return $min if $column->{predictable_values};
Branch: 1 branch
BranchTrueFalseTotal
if $column->{"predictable_values"} 0 0 0
30 0 return rand($max-$min)+$min;
31 }
32  
33 22804 ▶sub random_string {
Subroutine random_string: called CC=2 SCAR=6.9
Pod undocumented
34 22804 my ($column, $pattern, @choices) = @_;
35  
36 22804 ▶ if ( $column->{predictable_values} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column->{"predictable_values"}) 1900 20904 22804
37 54 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 54 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1900 ▶ local *{ "String::Random::_rand" } = sub { 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
40 1900 return String::Random::random_string($pattern, @choices);
41 }
42 20904 return String::Random::random_string($pattern, @choices);
43 }
44  
45 2758 ▶sub random_regex {
Subroutine random_regex: called CC=2 SCAR=6.9
Pod undocumented
46 2758 my ($column, $template) = @_;
47  
48 # This is reaching into the guts of String::Random. It may break at any time.
49 2758 ▶ if ( $column->{predictable_values} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column->{"predictable_values"}) 220 2538 2758
50 54 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 54 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 220 ▶ local *{ "String::Random::_rand" } = sub { 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
53 220 return String::Random::random_regex($template);
54 }
55 2538 return String::Random::random_regex($template);
56 }
57  
58 16353 ▶sub random_item {
Subroutine random_item: called CC=2 SCAR=6.9
Pod undocumented
59 16353 my ($column, $arr) = @_;
60 return $column->{predictable_values}
61 16353 ▶ ? $arr->[0] : $arr->[rand @$arr];
Branch: 1 branch
BranchTrueFalseTotal
$column->{'predictable_values'} ? : 1090 15263 16353
62 }
63  
64 20129 ▶sub random_choice {
Subroutine random_choice: called CC=2 SCAR=6.9
Pod undocumented
65 20129 my ($column, $threshold) = @_;
66 return $column->{predictable_values}
67 20129 ▶ ? 1 : rand() < $threshold;
Branch: 1 branch
BranchTrueFalseTotal
$column->{'predictable_values'} ? : 1680 18449 20129
68 }
69  
70 54 1;
71 __END__
« Sims/Source.pm ↑ Summary Sims/Relationship.pm »