ODS/Table/Generate/Data.pm

filter: Statementstmt 86.9% 73 / 84 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 6 totaltotal 81.6% 89 / 109 CC 6 SCAR 6.1
CC
6
Cov
86%
generate
3.0
__ANON__
2.7
generate_integer
2.4
CRAP 1.8
« ODS/Angel.pm ↑ Summary ODS/Table/Column/String.pm »
1 package ODS::Table::Generate::Data;
2 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 59 ▶use YAOO;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 59 auto_build;
7  
8 59 ▶use ODS::Utils qw/load/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 59 ▶use Term::ProgressSpinner;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 59 has table_class => isa(string);
13  
14 59 has table_class_type => isa(string);
15  
16 59 has table_class_connect => isa(hash);
17  
18 59 has total => isa(integer);
19  
20 # Acme::MetaSyntactic class or one that follows the same standard
21 59 has data_class => isa(string('Acme::MetaSyntactic')), build_order(1);
22  
23 59 has data_class_theme => isa(string), build_order(2);
24  
25 59 has data_class_total => isa(integer(10));
26  
27 59 has auto_increment => isa(integer), default(0);
28  
29 has default_strings => isa(array), delay, coerce(sub {
30 59 ▶ my ($self, $data) = @_;
Subroutine __ANON__: called CC=2 SCAR=9.9
31  
32 59 ▶ if ($self->data_class_theme) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->data_class_theme) 0 59 59
33 0 load $self->data_class;
34 0 my $meta = $self->data_class->new($self->data_class_theme);
35 0 my @syntactic = $meta->name( $self->data_class_total );
36 0 return \@syntactic;
37 }
38 return [
39 59 "Barbarians",
40 "Gunga Din",
41 "Fame and Fortune",
42 "Anthem For Doomed Youth",
43 "You're My Waterloo",
44 "Belly of the Beast",
45 "Iceman",
46 "Heart of the Matter",
47 "The Milkman's Horse",
48 "Ruling Force",
49 "Worlds on Fire",
50 "Ninja",
51 "Open Eyes",
52 "Dollars and Dimes",
53 "Saturday",
54 "More Fire",
55 "Ghetto Long Time",
56 "Liberate",
57 "Today",
58 "Ave Adore",
59 "House I Built",
60 "Catch a Vibe",
61 "Chasing Cars",
62 "Gleaming Auction",
63 "Made of Stone",
64 "Bounce",
65 "Forest",
66 "Sweet Disposition",
67 "Science Of Fear",
68 "The Motto",
69 "Mysterious Ways"
70 ];
71 59 });
72  
73 59 has default_integers => isa(array([ 1 .. 100 ]));
74  
75 59 has default_floats => isa(array([ (map { sprintf "%.2f", "1.$_" } 0 .. 99) ]));
76  
77 59 has default_emails_domains => isa(array([
78 "lnation.org",
79 "world-wide.world",
80 "notifi.site",
81 "supervisor.fun",
82 "supervisor.guru",
83 "autonomous.cyou",
84 "notifi.page"
85 ]));
86  
87 59 has default_epoch => isa(array([ map { 1645016769 - (300 * $_) } 1 .. 50 ]));
88  
89 has default_phone => isa(array), delay, coerce(sub {
90 59 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
91 59 my @numbers = ();
92  
93 59 my $total = $self->data_class_total;
94  
95 59 for (1 .. $self->data_class_total) {
96 590 push @numbers, '+' . map { int(rand(10)) } 0 .. 12
97 }
98 59 return \@numbers;
99 59 });
100  
101 sub generate {
102 59 ▶ my ($self) = @_;
Subroutine generate: called CC=3 SCAR=11.0
Pod undocumented
103  
104 59 load $self->table_class;
105  
106 59 my $table = $self->table_class->connect($self->table_class_type, $self->table_class_connect);
107  
108 59 $table->table->rows([]);
109  
110 59 my $ps = Term::ProgressSpinner->new(
111 text_color => 'black on_bright_black',
112 precision => 2,
113 );
114  
115 59 $ps->start($self->total);
116  
117 59 my $i = 1;
118 59 ▶ while ($ps->advance) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ps->advance) 1711 59 1770
119 1711 my %row = ();
120 1711 for my $column ( keys %{ $table->table->columns } ) {
121 25665 $column = $table->table->columns->{$column};
122 25665 my $callback = 'generate_' . $column->{type};
123 25665 $row{$column->name} = $self->$callback($column);
124 }
125 1711 $table->create(\%row);
126 }
127 }
128  
129 sub generate_integer {
130 1711 ▶ my ($self, $row) = @_;
Subroutine generate_integer: called CC=2 SCAR=8.5
Pod undocumented
131  
132 1711 ▶ if ($row->auto_increment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->auto_increment) 1711 0 1711
133 1711 $self->auto_increment($self->auto_increment + 1);
134 1711 return $self->auto_increment;
135 }
136  
137 0 my $integers = $self->default_integers;
138  
139 0 return $integers->[int(rand(scalar @{$integers}))]
140 }
141  
142 sub generate_string {
143 17110 ▶ my ($self, $row) = @_;
Subroutine generate_string: called CC=1 SCAR=0.0
Pod undocumented
144  
145 17110 my $strings = $self->default_strings;
146  
147  
148 17110 return $strings->[int(rand(scalar @{$strings}))];
149 }
150  
151 sub generate_boolean {
152 3422 ▶ my ($self, $row) = @_;
Subroutine generate_boolean: called CC=1 SCAR=0.0
Pod undocumented
153  
154 3422 my $boolean = int(rand(2));
155  
156 3422 return \$boolean;
157 }
158  
159 sub generate_phone {
160 0 ▶ my ($self, $row) = @_;
Subroutine generate_phone: not called CC=1 SCAR=6.9
Pod undocumented
161  
162 0 my $phone = $self->default_phone;
163  
164 0 return $phone->[int(rand(scalar @{$phone}))];
165 }
166  
167 sub generate_epoch {
168 3422 ▶ my ($self, $row) = @_;
Subroutine generate_epoch: called CC=1 SCAR=0.0
Pod undocumented
169  
170 3422 my $epoch = $self->default_epoch;
171  
172 3422 return $epoch->[int(rand(scalar @{$epoch}))];
173 }
174  
175  
176 59 1;
« ODS/Angel.pm ↑ Summary ODS/Table/Column/String.pm »