| 1 | package DBIx::Class::MockData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | our $VERSION = qv('v1.0.0'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | our $AUTHORITY = 'cpan:MANWAR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | DBIx::Class::MockData - Generate mock test data for DBIx::Class schemas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Version 1.0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | use DBIx::Class::MockData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | my $schema = MyApp::Schema->connect($dsn, $user, $pass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Basic usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ->deploy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Fast data refresh (recommended for most test scenarios) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | rows => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ->truncate # Empties tables quickly, preserves structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Complete schema reset (use sparingly) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | rows => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | verbose => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | seed => 42, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ->wipe # Destructive: drops and recreates tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Populate only selected tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | only => [qw(Author Book)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ->truncate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Populate all tables except selected ones | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | exclude => [qw(AuditLog SessionToken)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ->truncate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Use custom generators for specific columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | generators => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | email => sub { "user".int(rand(1000))."\@example.com" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | status => sub { "active" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | created_at => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | my ($col, $info, $n, $mock) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | return DateTime->now->datetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ->truncate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # Set different row counts per table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | rows => 5, # default for all tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | rows_per_table => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | Author => 10, # override for Author | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Book => 3, # override for Book | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ->truncate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Preview data without inserting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | schema_dir => 't/lib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | rows => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ->dry_run; # Prints generated values, no database changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Accepts a connected L<DBIx::Class::Schema> object, the return value of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | C<< YourSchema->connect(...) >>, introspects every result source, resolves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | foreign-key insertion order via topological sort, and inserts randomly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | generated rows. Values are produced from each column's declared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | C<data_type>. Unique and primary-key columns are salted with a per-run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | random value to avoid cross-run collisions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Connection and schema loading are entirely the caller's responsibility. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | C<schema_dir> is accepted only to ensure the lib root is present in C<@INC> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | so result classes remain resolvable at runtime. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | All public methods return C<$self>, enabling call chaining. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | ▶ | use UUID::Tiny qw(:std); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | use feature qw(state); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | my $mock = DBIx::Class::MockData->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | schema => $connected_schema, # required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | schema_dir => 't/lib', # required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | rows => 5, # rows per table (default: 5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | verbose => 0, # debug output (default: 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | seed => 42, # random seed (optional) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | B<ARGUMENTS> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =item schema B<(required)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | A connected L<DBIx::Class::Schema> instance - the return value of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | C<< YourSchema->connect(...) >>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =item schema_dir B<(required)> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | The lib root containing your schema classes. Added to C<@INC> so result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | classes referenced by relationships remain resolvable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | =item rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | Number of rows to generate per table. Default: C<5>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | =item verbose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Print debug output. Default: C<0>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | =item seed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Integer seed passed to C<srand> for reproducible output. Optional. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | =item only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | Array reference of source names to populate. When supplied, only the listed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | tables are processed (in FK-safe order). Cannot be combined with C<exclude>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | only => [qw(Author Book)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | =item exclude | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | Array reference of source names to skip. All other tables are populated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | Cannot be combined with C<only>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | exclude => [qw(AuditLog SessionToken)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=45 SCAR=52.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 11 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | croak "schema is required" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 11 | ▶ | unless $args{schema}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | croak "schema must be a DBIx::Class::Schema instance" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 10 | ▶ | unless blessed($args{schema}) && $args{schema}->isa('DBIx::Class::Schema'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($args{"schema"}) and $args{"schema"}->isa("DBIx::Class::Schema")
MC/DC50%1/2
builtin::blessed($args{"schema"}) and $args{"schema"}->isa("DBIx::Class::Schema")
builtin::blessed($args{"schema"})
$args{"schema"}->isa("DBIx::Class::Schema")
Truth table66%2/3
A and B
A= builtin::blessed($args{"schema"})B= $args{"schema"}->isa("DBIx::Class::Schema")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | croak "schema_dir is required" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | ▶ | unless $args{schema_dir}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 8 | my $dir = File::Spec->rel2abs($args{schema_dir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 8 | ▶ | croak "schema_dir '$dir' does not exist" unless -d $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 8 | ▶ | push @INC, $dir unless grep { $_ eq $dir } @INC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | croak "only and exclude cannot both be specified" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | ▶ | if $args{only} && $args{exclude}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"only"} and $args{"exclude"}
MC/DC0%0/2
$args{"only"} and $args{"exclude"}
$args{"only"}
$args{"exclude"}
Truth table33%1/3
A and B
A= $args{"only"}B= $args{"exclude"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | croak "only must be an arrayref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | ▶ | if $args{only} && ref($args{only}) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"only"} and ref $args{"only"} ne "ARRAY"
MC/DC0%0/2
$args{"only"} and ref $args{"only"} ne "ARRAY"
$args{"only"}
ref $args{"only"} ne "ARRAY"
Truth table33%1/3
A and B
A= $args{"only"}B= ref $args{"only"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | croak "exclude must be an arrayref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | ▶ | if $args{exclude} && ref($args{exclude}) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"exclude"} and ref $args{"exclude"} ne "ARRAY"
MC/DC0%0/2
$args{"exclude"} and ref $args{"exclude"} ne "ARRAY"
$args{"exclude"}
ref $args{"exclude"} ne "ARRAY"
Truth table33%1/3
A and B
A= $args{"exclude"}B= ref $args{"exclude"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Validate numeric arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | ▶ | if (defined $args{rows}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | croak "rows must be a positive integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 6 | ▶ | unless $args{rows} =~ /^\d+$/ && $args{rows} > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"rows"} =~ /^\d+$/ and $args{"rows"} > 0
MC/DC0%0/2
$args{"rows"} =~ /^\d+$/ and $args{"rows"} > 0
$args{"rows"} =~ /^\d+$/
$args{"rows"} > 0
Truth table33%1/3
A and B
A= $args{"rows"} =~ /^\d+$/B= $args{"rows"} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | ▶ | if (defined $args{seed}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | croak "seed must be a positive integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | ▶ | unless $args{seed} =~ /^\d+$/ && $args{seed} > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"seed"} =~ /^\d+$/ and $args{"seed"} > 0
MC/DC0%0/2
$args{"seed"} =~ /^\d+$/ and $args{"seed"} > 0
$args{"seed"} =~ /^\d+$/
$args{"seed"} > 0
Truth table33%1/3
A and B
A= $args{"seed"} =~ /^\d+$/B= $args{"seed"} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | ▶ | if (defined $args{verbose}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | croak "verbose must be 0 or 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | unless $args{verbose} =~ /^[01]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # Validate rows_per_table if provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | if (defined $args{rows_per_table}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | croak "rows_per_table must be a hashref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | unless ref($args{rows_per_table}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | while (my ($table, $count) = each %{ $args{rows_per_table} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | croak "rows_per_table value for '$table' must be a positive integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count =~ /^\d+$/ and $count > 0
MC/DC0%0/2
$count =~ /^\d+$/ and $count > 0
$count =~ /^\d+$/
$count > 0
Truth table33%1/3
A and B
A= $count =~ /^\d+$/B= $count > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | unless $count =~ /^\d+$/ && $count > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # Validate generators if provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 8 | ▶ | if (defined $args{generators}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | croak "generators must be a hashref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | unless ref($args{generators}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | while (my ($col, $gen) = each %{ $args{generators} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | croak "generator for '$col' must be a code reference or scalar" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $gen eq "CODE" or not ref $gen
MC/DC0%0/2
ref $gen eq "CODE" or not ref $gen
ref $gen eq "CODE"
not ref $gen
Truth table0%0/3
A or not(B)
A= ref $gen eq "CODE"B= not ref $gen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | unless ref($gen) eq 'CODE' || !ref($gen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | _schema => $args{schema}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | rows => $args{rows} // 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | verbose => $args{verbose} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | quiet => $args{quiet} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | rows_per_table => $args{rows_per_table} || {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | generators => $args{generators} || {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | _salt => int(rand(9_000_000)) + 1_000_000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | _only => $args{only} ? { map { $_ => 1 } @{ $args{only} } } : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | _exclude => $args{exclude} ? { map { $_ => 1 } @{ $args{exclude} } } : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%8/10
$args{"rows"} // 5
$args{"verbose"} // 0
$args{"quiet"} // 0
$args{'rows_per_table'} || {}
$args{'generators'} || {}
MC/DC100%1/1
$args{"rows"} // 5
$args{"rows"}
MC/DC0%0/1
$args{"verbose"} // 0
$args{"verbose"}
MC/DC100%1/1
$args{"quiet"} // 0
$args{"quiet"}
MC/DC100%1/1
$args{'rows_per_table'} || {}
$args{'rows_per_table'}
MC/DC0%0/1
$args{'generators'} || {}
$args{'generators'}
Truth table100%2/2
A
A= $args{"rows"}
Truth table50%1/2
A
A= $args{"verbose"}
Truth table100%2/2
A
A= $args{"quiet"}
Truth table100%2/2
A
A= $args{'rows_per_table'}
Truth table50%1/2
A
A= $args{'generators'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 8 | ▶ | if (defined $args{seed}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | srand($args{seed}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | $self->{_salt} = int(rand(9_000_000)) + 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 8 | ▶ | if (defined $args{start_year}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | croak "start_year must be a 4-digit year" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | unless $args{start_year} =~ /^\d{4}$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $self->{start_year} = $args{start_year}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 8 | ▶ | if (defined $args{end_year}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | croak "end_year must be a 4-digit year" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | unless $args{end_year} =~ /^\d{4}$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $self->{end_year} = $args{end_year}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 8 | ▶ | $self->{start_year} ||= 2010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"start_year"} ||= 2010
MC/DC0%0/1
$self->{"start_year"} ||= 2010
$self->{"start_year"}
Truth table50%1/2
A
A= $self->{"start_year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 8 | ▶ | $self->{end_year} ||= 2026; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"end_year"} ||= 2026
MC/DC0%0/1
$self->{"end_year"} ||= 2026
$self->{"end_year"}
Truth table50%1/2
A
A= $self->{"end_year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 8 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | =head2 deploy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | $mock->deploy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | $mock->deploy->generate; # chainable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | Creates all tables that do not yet exist. Safe to call when some or all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | tables are already present. Returns C<$self>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 5 | ▶ | sub deploy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: called CC=4 SCAR=20.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | my $schema = $self->{_schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 5 | $self->_log("Deploying schema (creating missing tables)..."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 5 | my $ddl = eval { $schema->deployment_statements }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 5 | ▶ | if ($@ || !$ddl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not $ddl
MC/DC0%0/2
$@ or not $ddl
$@
not $ddl
Truth table33%1/3
A or not(B)
A= $@B= not $ddl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 5 | eval { $schema->deploy({ add_drop_table => 0, ignore_errors => 1 }) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 5 | ▶ | croak "Deploy failed: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $schema->storage->dbh_do(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my (undef, $dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | for my $stmt (split /;\s*/m, $ddl) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $stmt =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | next unless length $stmt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | eval { $dbh->do($stmt) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | $self->_debug(" Skipped (exists?): " . substr($stmt, 0, 60)) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $self->_log("Deploy complete"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | =head2 truncate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | $mock->truncate->generate; # chainable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | Truncates (empties) all tables while preserving table structure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | Safer than C<wipe> as it doesn't drop and recreate tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | Returns C<$self>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub truncate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
truncate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $schema = $self->{_schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $self->_log("Truncating all tables..."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # Get tables in reverse dependency order to avoid FK issues | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my @all_sources = $schema->sources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my @sources = $self->_active_sources(@all_sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my ($deps, $rsrc) = $self->_build_dep_graph(\@sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my @ordered = reverse $self->_topo_sort($deps, \@sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | $schema->storage->dbh_do(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my (undef, $dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | for my $name (@ordered) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $source = $schema->source($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $table = $source->from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | $table = $$table if ref($table) eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $self->_debug(" Truncating: $table"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # Different DBs have different truncate syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $driver = $schema->storage->dbh->{Driver}->{Name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($driver eq 'SQLite') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $dbh->do("DELETE FROM $table"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # Reset autoincrement sequences if they exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Check if sqlite_sequence table exists and has entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # for this table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $seq_exists = $dbh->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | "SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if ($seq_exists) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $has_seq = $dbh->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | "SELECT name FROM sqlite_sequence WHERE name=?", {}, $table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ($has_seq) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $dbh->do("DELETE FROM sqlite_sequence WHERE name='$table'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | elsif ($driver =~ /mysql|mariadb/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $dbh->do("TRUNCATE TABLE $table"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | elsif ($driver =~ /postgres|pg/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $dbh->do("TRUNCATE TABLE $table RESTART IDENTITY CASCADE"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $dbh->do("DELETE FROM $table"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | croak "Truncate failed: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $self->_log("Truncate complete"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | =head2 wipe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | $mock->wipe->generate; # chainable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | Drops B<all> tables then redeploys the schema. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | B<Destructive -- for test environments only.> Returns C<$self>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | sub wipe { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wipe: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my $schema = $self->{_schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | warn "[WARN] wipe() is destructive and drops tables. Consider using truncate() instead.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | unless $self->{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $self->_log("Wiping all tables..."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | $schema->storage->dbh_do(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my (undef, $dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | for my $src (reverse $schema->sources) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $table = $schema->source($src)->from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | $table = $$table if ref($table) eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $self->_debug(" Dropping: $table"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $dbh->do("DROP TABLE IF EXISTS $table"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | croak "Wipe failed: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $schema->deploy({ add_drop_table => 0 }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $self->_log("Wipe and redeploy complete"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | =head2 generate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | $mock->generate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | Inserts mock rows into every table respecting FK insertion order, data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | types, nullability, and uniqueness constraints. Returns C<$self>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 2 | ▶ | sub _active_sources { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_active_sources: called CC=5 SCAR=25.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 2 | my ($self, @all) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 2 | my %known = map { $_ => 1 } @all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 2 | ▶ | if ($self->{_only}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my @unknown = grep { !$known{$_} } keys %{ $self->{_only} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | croak "Unknown source(s) in 'only': " . join(', ', sort @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | return grep { $self->{_only}{$_} } @all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 2 | ▶ | if ($self->{_exclude}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my @unknown = grep { !$known{$_} } keys %{ $self->{_exclude} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | croak "Unknown source(s) in 'exclude': " . join(', ', sort @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | return grep { !$self->{_exclude}{$_} } @all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | return @all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 2 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=14 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | my $schema = $self->{_schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | my @all_sources = $schema->sources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | croak "No result sources found in schema" unless @all_sources; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | my @sources = $self->_active_sources(@all_sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 2 | ▶ | croak "No sources to populate after applying only/exclude filters" unless @sources; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 2 | $self->_log("Found sources: " . join(', ', sort @sources)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | my ($deps, $rsrc) = $self->_build_dep_graph(\@sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 2 | my @ordered = $self->_topo_sort($deps, \@sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 2 | $self->_log("Insertion order: " . join(' -> ', @ordered)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | my %inserted_pks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 2 | for my $name (@ordered) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 5 | $self->_log("\n--- Table: $name ---"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 5 | my $source = $rsrc->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 5 | my @cols = $source->columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 5 | my %col_info = map { $_ => $source->column_info($_) } @cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 5 | my @pk_cols = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 5 | my %pk_set = map { $_ => 1 } @pk_cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 5 | my %unique = $self->_unique_cols($source, \@pk_cols, \%col_info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 5 | my %fk = $self->_build_fk_map($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 5 | ▶ | $self->_debug(" Unique cols: " . join(', ', sort keys %unique)) if %unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 5 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 5 | ▶ | my $rows = $self->{rows_per_table}{$name} // $self->{rows}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"rows_per_table"}{$name} // $self->{"rows"}
MC/DC0%0/2
$self->{"rows_per_table"}{$name} // $self->{"rows"}
$self->{"rows_per_table"}{$name}
$self->{"rows"}
Truth table33%1/3
A // B
A= $self->{"rows_per_table"}{$name}B= $self->{"rows"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | for my $n (1 .. $rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 18 | my %row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 18 | for my $col (@cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 101 | my $info = $col_info{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 101 | ▶ | next if $pk_set{$col} && $self->_is_auto_pk($info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pk_set{$col} and $self->_is_auto_pk($info)
MC/DC0%0/2
$pk_set{$col} and $self->_is_auto_pk($info)
$pk_set{$col}
$self->_is_auto_pk($info)
Truth table66%2/3
A and B
A= $pk_set{$col}B= $self->_is_auto_pk($info)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 101 | ▶ | if (exists $fk{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 11 | ▶ | my $pool = $inserted_pks{ $fk{$col}{source} } // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$inserted_pks{$fk{$col}{"source"}} // []
MC/DC0%0/1
$inserted_pks{$fk{$col}{"source"}} // []
$inserted_pks{$fk{$col}{"source"}}
Truth table50%1/2
A
A= $inserted_pks{$fk{$col}{"source"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 11 | ▶ | if (@$pool) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | $row{$col} = $pool->[ ($n-1) % @$pool ]{ $fk{$col}{col} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | elsif ($info->{is_nullable}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $row{$col} = undef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 11 | $row{$col} = $self->_generate_value($col, $info, $n, $unique{$col}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 90 | $row{$col} = $self->_generate_value($col, $info, $n, $unique{$col}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 18 | push @rows, \%row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 5 | $self->_insert_rows($source, $name, \@rows, \@pk_cols, \%inserted_pks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | =head2 dry_run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | $mock->dry_run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | Prints the values that I<would> be inserted without touching the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | Returns C<$self>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | sub dry_run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dry_run: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $schema = $self->{_schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | my @sources = sort $self->_active_sources($schema->sources); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | for my $name (@sources) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $source = $schema->source($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my @cols = $source->columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my %col_info = map { $_ => $source->column_info($_) } @cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my @pk_cols = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my %pk_set = map { $_ => 1 } @pk_cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my %unique = $self->_unique_cols($source, \@pk_cols, \%col_info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | print "\n--- DRY RUN: $name ---\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | for my $n (1 .. $self->{rows}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | print " Row $n:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | for my $col (@cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | next if $pk_set{$col} && $self->_is_auto_pk($col_info{$col}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pk_set{$col} and $self->_is_auto_pk($col_info{$col})
MC/DC0%0/2
$pk_set{$col} and $self->_is_auto_pk($col_info{$col})
$pk_set{$col}
$self->_is_auto_pk($col_info{$col})
Truth table0%0/3
A and B
A= $pk_set{$col}B= $self->_is_auto_pk($col_info{$col})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | my $val = $self->_generate_value($col, $col_info{$col}, $n, $unique{$col}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | printf " %-30s => %s\n", $col, defined $val ? "'$val'" : 'NULL'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # PRIVATE METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 5 | ▶ | sub _unique_cols { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unique_cols: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 5 | my ($self, $source, $pk_cols, $col_info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 5 | my %unique; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # Non-auto PKs must be unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 5 | $unique{$_} = 1 for grep { !$self->_is_auto_pk($col_info->{$_}) } @$pk_cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # Explicit unique constraints (skip 'primary' -- handled above) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 5 | ▶ | if ($source->can('unique_constraints')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 5 | my %ucs = $source->unique_constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 5 | for my $name (keys %ucs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 8 | ▶ | next if $name eq 'primary'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 3 | $unique{$_} = 1 for @{ $ucs{$name} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 5 | return %unique; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 2 | ▶ | sub _build_dep_graph { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_dep_graph: called CC=14 SCAR=32.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 2 | my ($self, $sources) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 2 | my $schema = $self->{_schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 2 | my (%deps, %rsrc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 2 | for my $name (@$sources) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 5 | my $source = $schema->source($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 5 | $rsrc{$name} = $source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 5 | ▶ | $deps{$name} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$deps{$name} //= []
MC/DC0%0/1
$deps{$name} //= []
$deps{$name}
Truth table50%1/2
A
A= $deps{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 5 | for my $rel ($source->relationships) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 6 | my $info = $source->relationship_info($rel); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 6 | ▶ | my $attrs = $info->{attrs} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info->{'attrs'} || {}
MC/DC0%0/1
$info->{'attrs'} || {}
$info->{'attrs'}
Truth table50%1/2
A
A= $info->{'attrs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # Check if this is a foreign key constraint relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 6 | ▶ | next unless $attrs->{is_foreign_key_constraint}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # belongs_to, has_one, might_have all create FK dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | # but in different directions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 3 | ▶ | my $accessor = $attrs->{accessor} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs->{'accessor'} || ''
MC/DC0%0/1
$attrs->{'accessor'} || ''
$attrs->{'accessor'}
Truth table50%1/2
A
A= $attrs->{'accessor'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 3 | ▶ | my $parent = eval { $source->related_source($rel)->source_name } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 3 | ▶ | next if $parent eq $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 3 | ▶ | if ($accessor eq 'single') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # belongs_to - current table depends on parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 3 | push @{ $deps{$name} }, $parent | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | unless grep { $_ eq $parent } @{ $deps{$name} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | elsif ($accessor eq 'multi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | # has_many - parent depends on current table? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # Actually has_many doesn't create FK constraint in current table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # So no dependency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | # might_have, has_one - parent depends on current table? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # These create FK in current table pointing to parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # So current table depends on parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | if ($attrs->{is_foreign_key_constraint}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | push @{ $deps{$name} }, $parent | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | unless grep { $_ eq $parent } @{ $deps{$name} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | return (\%deps, \%rsrc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 2 | ▶ | sub _topo_sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_topo_sort: called CC=9 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 2 | my ($self, $deps, $nodes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 2 | my %in = map { $_ => 0 } @$nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 2 | my %adj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 2 | for my $node (@$nodes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 5 | for my $dep (@{ $deps->{$node} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 3 | ▶ | next unless exists $in{$dep}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 3 | $in{$node}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 3 | push @{ $adj{$dep} }, $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 2 | my @queue = sort grep { $in{$_} == 0 } @$nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 2 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 2 | ▶ | while (@queue) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 5 | my $n = shift @queue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 5 | push @result, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 5 | ▶ | push @queue, $_ for grep { --$in{$_} == 0 } @{ $adj{$n} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$adj{$n} // []
MC/DC100%1/1
$adj{$n} // []
$adj{$n}
Truth table100%2/2
A
A= $adj{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # Check for cycles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 2 | my @remaining = grep { $in{$_} > 0 } @$nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 2 | ▶ | if (@remaining) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | if ($self->{ignore_cycles}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # Best effort - append remaining nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | push @result, @remaining; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | my $cycle = $self->_find_cycle(\%adj, $remaining[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | croak "Cyclic dependency detected in relationships: " . join(' -> ', @$cycle); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 2 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | ▶ | sub _find_cycle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_cycle: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | my ($self, $adj, $start) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | my @path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | my $dfs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | $dfs = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | return if $seen{$node}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | push @path, $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | $seen{$node} = scalar @path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | ▶ | for my $next (@{ $adj->{$node} // [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$adj->{$node} // []
MC/DC0%0/1
$adj->{$node} // []
$adj->{$node}
Truth table0%0/2
A
A= $adj->{$node}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | if (my $pos = $seen{$next}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # Found a cycle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return [ @path[$pos-1 .. $#path], $next ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $cycle = $dfs->($next); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | return $cycle if $cycle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | pop @path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | $seen{$node} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | return $dfs->($start) || [$start]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
&$dfs($start) || [$start]
MC/DC0%0/1
&$dfs($start) || [$start]
&$dfs($start)
Truth table0%0/2
A
A= &$dfs($start)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 5 | ▶ | sub _build_fk_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_fk_map: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 5 | my ($self, $source) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 5 | my %fk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 5 | for my $rel ($source->relationships) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 6 | my $info = $source->relationship_info($rel); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 6 | ▶ | next unless $self->_is_belongs_to($info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 3 | ▶ | my $related = eval { $source->related_source($rel) } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 3 | my $cond = $info->{cond}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 3 | ▶ | next unless ref($cond) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 3 | ▶ | while (my ($fcol, $scol) = each %$cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 3 | $scol =~ s/^self\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 3 | $fcol =~ s/^foreign\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 3 | $fk{$scol} = { source => $related->source_name, col => $fcol }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 5 | return %fk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 6 | ▶ | sub _is_belongs_to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_belongs_to: called CC=10 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 6 | my ($self, $info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 6 | ▶ | my $a = $info->{attrs} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info->{"attrs"} // {}
MC/DC0%0/1
$info->{"attrs"} // {}
$info->{"attrs"}
Truth table50%1/2
A
A= $info->{"attrs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 6 | ▶ | return 1 if ($a->{accessor} // '') eq 'single' && ($a->{is_foreign_key_constraint} // 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition57%4/7
($a->{"accessor"} // "") eq "single" and $a->{"is_foreign_key_constraint"} // 0
$a->{"accessor"} // ""
$a->{"is_foreign_key_constraint"} // 0
MC/DC0%0/2
($a->{"accessor"} // "") eq "single" and $a->{"is_foreign_key_constraint"} // 0
$a->{"accessor"}
$a->{"is_foreign_key_constraint"}
Truth table33%1/3
A and B
A= $a->{"accessor"}B= $a->{"is_foreign_key_constraint"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 3 | ▶ | return 1 if ($a->{accessor} // '') eq 'single' && !($a->{join_type} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition28%2/7
($a->{"accessor"} // "") eq "single" and not $a->{"join_type"} // ""
$a->{"accessor"} // ""
$a->{"join_type"} // ""
MC/DC0%0/2
($a->{"accessor"} // "") eq "single" and not $a->{"join_type"} // ""
$a->{"accessor"}
$a->{"join_type"}
Truth table0%0/3
A and not(B)
A= $a->{"accessor"}B= $a->{"join_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 23 | ▶ | sub _is_auto_pk { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_auto_pk: called CC=7 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 23 | my ($self, $info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 23 | ▶ | return 1 if lc($info->{data_type} // '') =~ /\b(serial|bigserial|autoincrement)\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$info->{"data_type"} // ""
MC/DC0%0/1
$info->{"data_type"} // ""
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 23 | ▶ | return 1 if ($info->{extra}{auto_increment} // 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$info->{"extra"}{"auto_increment"} // 0
MC/DC0%0/1
$info->{"extra"}{"auto_increment"} // 0
$info->{"extra"}{"auto_increment"}
Truth table50%1/2
A
A= $info->{"extra"}{"auto_increment"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 23 | ▶ | return 1 if ($info->{sequence} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$info->{"sequence"} // ""
MC/DC0%0/1
$info->{"sequence"} // ""
$info->{"sequence"}
Truth table50%1/2
A
A= $info->{"sequence"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 23 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 101 | ▶ | sub _generate_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_value: called CC=24 SCAR=34.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 101 | my ($self, $col, $info, $n, $is_unique) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 101 | my $salt = $self->{_salt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 101 | ▶ | my $dtype = lc($info->{data_type} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info->{"data_type"} // ""
MC/DC0%0/1
$info->{"data_type"} // ""
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 101 | ▶ | my $size = $info->{size} // 255; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$info->{"size"} // 255
MC/DC100%1/1
$info->{"size"} // 255
$info->{"size"}
Truth table100%2/2
A
A= $info->{"size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 101 | ▶ | $size = ref($size) eq 'ARRAY' ? $size->[0] : ($size || 255); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$size or 255
MC/DC0%0/1
$size or 255
$size
Truth table50%1/2
A
A= $size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 101 | ▶ | return undef if !$is_unique && ($info->{is_nullable} // 0) && int(rand(6)) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%8/8
not $is_unique and $info->{"is_nullable"} // 0 and int rand 6 == 0
not $is_unique and $info->{"is_nullable"} // 0
$info->{"is_nullable"} // 0
MC/DC100%3/3
not $is_unique and $info->{"is_nullable"} // 0 and int rand 6 == 0
not $is_unique
$info->{"is_nullable"}
int rand 6 == 0
Truth table100%4/4
not(A) and B and C
A= not $is_uniqueB= $info->{"is_nullable"}C= int rand 6 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 97 | ▶ | if (my $gen = $self->{generators}{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | return $gen->($col, $info, $n, $self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 97 | ▶ | if ($dtype =~ /\b(int|integer|bigint|smallint|tinyint|serial|bigserial)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 33 | ▶ | return $is_unique ? $salt + $n : int(rand(999_999)) + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 64 | ▶ | if ($dtype =~ /\b(numeric|decimal|float|double|real|money)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 7 | return sprintf '%.2f', rand(10_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 57 | ▶ | if ($dtype =~ /\b(bool|boolean|tinyint\(1\))\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 4 | return int(rand(2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 53 | ▶ | if ($dtype =~ /\b(datetime|timestamp)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 7 | return $self->_rand_datetime; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 46 | ▶ | if ($dtype =~ /\bdate\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 3 | return $self->_rand_date; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 43 | ▶ | if ($dtype =~ /\btime\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | return sprintf '%02d:%02d:%02d', int(rand(24)), int(rand(60)), int(rand(60)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 43 | ▶ | if ($dtype =~ /\buuid\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | return create_uuid_as_string(UUID_V4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 43 | ▶ | if ($dtype =~ /\bjsonb?\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | return qq({"generated":true,"row":$n}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 43 | ▶ | if ($dtype =~ /\[\]$/ || $dtype =~ /^array/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dtype =~ /\[\]$/ or $dtype =~ /^array/
MC/DC0%0/2
$dtype =~ /\[\]$/ or $dtype =~ /^array/
$dtype =~ /\[\]$/
$dtype =~ /^array/
Truth table33%1/3
A or B
A= $dtype =~ /\[\]$/B= $dtype =~ /^array/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | return '{value1,value2}'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 43 | ▶ | if ($dtype =~ /\b(text|varchar|character varying|char|nvarchar|nchar|string|citext|tinytext|mediumtext|longtext)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 43 | ▶ | return $self->_contextual_string($col, $n, int($size) || 255, $is_unique); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
int $size || 255
MC/DC0%0/1
int $size || 255
int $size
Truth table50%1/2
A
A= int $size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | ▶ | return $is_unique ? "${col}_${n}_${salt}" : "${col}_${n}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 43 | ▶ | sub _contextual_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contextual_string: called CC=4 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 43 | my ($self, $col, $n, $max, $is_unique) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 43 | my $salt = $self->{_salt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | state $templates = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | [ qr/\b(first_?name|fname)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 4 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 4 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 4 | my $value = (qw(Alice Bob Carol Dave Eve Frank Grace Hank Iris Jack))[$n%10]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 4 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | [ qr/\b(last_?name|lname|surname)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 4 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 4 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 4 | my $value = (qw(Smith Jones Taylor Brown Wilson Davies Evans Thomas Roberts))[$n%9]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 4 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | [ qr/\bname\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 3 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 3 | my $value = "Name $n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 3 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | [ qr/\b(username|login)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | my $value = "user$n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | [ qr/\bemail\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 7 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 7 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 7 | my $local = "user$n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 7 | ▶ | $local .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 7 | return "${local}\@example.com"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | [ qr/\b(phone|mobile|fax)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | return sprintf '+1555%04d%04d', $salt % 10000, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | [ qr/\b(street|address|addr)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | my $value = "$n Main Street"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | [ qr/\b(city|town)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | my $value = (qw(London Paris Berlin Madrid Rome Amsterdam Brussels Vienna))[$n%8]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | [ qr/\bcountry\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | my $value = (qw(UK US DE FR ES IT NL AT))[$n%8]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | [ qr/\b(zip|postcode|postal)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | return sprintf '%05d', (10000 + $n + $salt) % 99999; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | [ qr/\b(state|province|region)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | my $value = (qw(CA NY TX FL WA IL PA OH))[$n%8]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | [ qr/\b(description|desc|summary|notes?|comment|body|content)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 3 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 3 | return "Sample text for record $n (run $salt)."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | [ qr/\b(title|heading|subject)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 4 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 4 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 4 | my $value = "Title $n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 4 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | [ qr/\bslug\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 4 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 4 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 4 | my $value = "slug-$n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 4 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | [ qr/\b(code|ref|reference)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | my $value = sprintf 'CODE%04d', $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | [ qr/\bsku\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | my $value = sprintf 'SKU%04d', $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | [ qr/\b(token|secret|key|hash)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | return sprintf '%016x%08x', $salt, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | [ qr/\b(url|link|href|website)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 0 | my $value = "https://example.com/item/$n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | [ qr/\b(status|state)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 3 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 3 | my $value = (qw(active inactive pending approved rejected))[$n%5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 3 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 3 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | [ qr/\b(type|kind|category|cat)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | my $value = (qw(typeA typeB typeC typeD))[$n%4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | [ qr/\b(colour|color)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | my $value = (qw(red green blue yellow purple orange))[$n%6]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | [ qr/\b(lang|language|locale)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | my $value = (qw(en fr de es it nl pt))[$n%7]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | [ qr/\b(version|ver)\b/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | my ($n, $is_unique, $salt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | my $value = "1.$n.0"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 0 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 43 | } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 43 | for my $t (@$templates) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 510 | ▶ | if ($col =~ $t->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 32 | my $value = $t->[1]->($n, $is_unique, $salt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 32 | return substr($value, 0, $max); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # Default case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 11 | my $value = "${col}_${n}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 11 | ▶ | $value .= "_${salt}" if $is_unique; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 11 | return substr($value, 0, $max); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 5 | ▶ | sub _insert_rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_rows: called CC=3 SCAR=13.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 5 | my ($self, $source, $name, $rows, $pk_cols, $inserted_pks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 5 | my $rs = $self->{_schema}->resultset($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 5 | eval { $rs->populate($rows) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 5 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 5 | warn "[WARN] Bulk insert failed for $name: $@\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | my @inserted = $rs->search({}, { rows => scalar(@$rows) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | for my $row (@inserted) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | push @{ $inserted_pks->{$name} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | { map { $_ => $row->get_column($_) } @$pk_cols }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | $self->_log("Inserted " . scalar(@$rows) . " rows into $name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 3 | ▶ | sub _rand_date { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rand_date: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 3 | my $year = $self->{start_year} + int(rand($self->{end_year} - $self->{start_year} + 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 3 | sprintf '%d-%02d-%02d', $year, rand(12)+1, rand(28)+1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 7 | ▶ | sub _rand_datetime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rand_datetime: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 7 | my $year = $self->{start_year} + int(rand($self->{end_year} - $self->{start_year} + 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 7 | sprintf '%d-%02d-%02d %02d:%02d:%02d', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | $year, rand(12)+1, rand(28)+1, rand(24), rand(60), rand(60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 14 | ▶ | sub _log { print "[INFO] $_[1]\n"; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 5 | ▶ | sub _debug { print "[DEBUG] $_[1]\n" if $_[0]->{verbose} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | =head1 GENERATED VALUES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | Values are produced from each column's declared C<data_type>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | integer / bigint / serial random integer (unique: salt + row_num) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | numeric / decimal / float random decimal (2 d.p.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | boolean 0 or 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | datetime / timestamp random datetime 2020-2024 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | date random date 2020-2024 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | time random HH:MM:SS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | uuid random UUID-shaped hex string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | json / jsonb {"generated":true,"row":N} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | text / varchar / char contextual string matched on column name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | unknown / blank dtype colname_N (colname_N_SALT if unique) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | Nullable columns receive NULL roughly 17% of the time (never for unique cols). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | =head1 CONFIGURATION OPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | =head2 rows_per_table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | rows_per_table => { Author => 10, Book => 3 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | Allows you to specify different numbers of rows for specific tables. Any table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | not listed in this hash will use the global C<rows> value. This is useful when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | you need more data for certain tables (e.g., Authors) and less for others. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | =head2 generators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | generators => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | email => sub { "user".int(rand(1000))."\@example.com" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | status => sub { "active" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | Provides custom value generators for specific columns. The generator subroutine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | receives four arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | =item C<$col> - The column name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | =item C<$info> - The column info hashref from the result source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | =item C<$n> - The current row number (1-based) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | =item C<$mock> - The MockData object instance (provides access to C<_salt> etc.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | The generator should return a scalar value appropriate for the column. This | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | overrides the default value generation for that column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | # Static value for all rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | status => sub { 'active' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | # Value based on row number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | code => sub { my ($col, $info, $n) = @_; "CODE_$n" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | # Value using the instance salt for uniqueness | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | token => sub { my ($col, $info, $n, $mock) = @_; "token_${n}_$mock->{_salt}" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | # Conditional logic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | email => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | my ($col, $info, $n) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | return $n == 1 ? 'admin@example.com' : "user$n\@example.com"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | =head1 PERFORMANCE IMPROVEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | Version 0.04 introduces significant performance optimisations: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | =head2 Bulk Insert Mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | Previously, rows were inserted one at a time using C<< $rs->create() >>, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | could be slow for large datasets. The module now uses C<< $rs->populate() >> to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | insert all rows in a single batch operation. This results in: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | =item * Up to 10x faster insertions for large datasets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | =item * Reduced database round-trips | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | =item * Maintained foreign key integrity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | =head2 Smarter Salt Generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | When a C<seed> is provided for reproducible output, the salt value is now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | randomised while still producing consistent results. This ensures: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | =item * Reproducible test data across runs (with same seed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | =item * Unique values across different test runs (different salts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | =item * No accidental collisions when running tests in parallel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | =head2 Unique Constraint Handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | The module now properly respects: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | =item * Primary key uniqueness (except auto-increment columns) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | =item * Named unique constraints from L<DBIx::Class> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | =item * Multi-column unique constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | Values for unique columns are automatically salted to ensure uniqueness | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | without manual intervention. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | =head1 CLI TOOL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | This distribution ships with a command-line tool B<dbic-mockdata> in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | C<script/> directory, installed into your C<PATH> by C<make install>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | dbic-mockdata --schema-dir t/lib \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | --namespace MyApp::Schema \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | --dsn "dbi:SQLite:dbname=test.db" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | --rows 5 \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | --deploy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | Run C<dbic-mockdata --help> for the full list of options, or see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | L<dbic-mockdata> for the complete manual. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | L<DBIx::Class>, L<Carp>, L<File::Spec>, L<Scalar::Util> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | =head1 REPOSITORY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | L<https://github.com/manwar/DBIx-Class-MockData> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/DBIx-Class-MockData/issues>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | I will be notified and then you'll automatically be notified of progress on your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | perldoc DBIx::Class::MockData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | =item * BUG Report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | L<https://github.com/manwar/DBIx-Class-MockData/issues> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | L<http://cpanratings.perl.org/d/DBIx-Class-MockData> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | =item * Search MetaCPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | L<https://metacpan.org/dist/DBIx-Class-MockData/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | Copyright (C) 2026 Mohammad Sajid Anwar. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | This program is free software; you can redistribute it and / or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | the terms of the the Artistic License (2.0). You may obtain a copy of the full | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | license at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | Any use, modification, and distribution of the Standard or Modified Versions is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | governed by this Artistic License.By using, modifying or distributing the Package, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | you accept this license. Do not use, modify, or distribute the Package, if you do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | not accept this license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | If your Modified Version has been derived from a Modified Version made by someone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | other than you,you are nevertheless required to ensure that your Modified Version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | complies with the requirements of this license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | This license does not grant you the right to use any trademark, service mark, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | This license includes the non-exclusive, worldwide, free-of-charge patent license | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | to make, have made, use, offer to sell, sell, import and otherwise transfer the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | Package with respect to any patent claims licensable by the Copyright Holder that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | are necessarily infringed by the Package. If you institute patent litigation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | (including a cross-claim or counterclaim) against any party alleging that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | Package constitutes direct or contributory patent infringement,then this Artistic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | License to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 6 | 1; # End of DBIx::Class::MockData | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||