| 1 | package Mock::Data::Plugin::SQLTypes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mock::Data::Plugin -exporter_setup => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mock::Data::Plugin::Net qw( cidr macaddr ), 'ipv4', { -as => 'inet' }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mock::Data::Plugin::Number qw( integer decimal float sequence uuid byte ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mock::Data::Plugin::Text 'join' => { -as => 'text_join' }, 'words'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | our %type_generators= map +($_ => 1), qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | integer tinyint smallint bigint | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | sequence serial smallserial bigserial | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | numeric decimal | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | float float4 real float8 double double_precision | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | bit bool boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | varchar char nvarchar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | text tinytext mediumtext longtext ntext | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | blob tinyblob mediumblob longblob bytea | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | varbinary binary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | date datetime datetime2 datetimeoffset timestamp | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | datetime_with_time_zone datetime_without_time_zone | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | json jsonb | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | uuid inet cidr macaddr | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | export(keys %type_generators); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # ABSTRACT: Collection of generators that produce data matching a SQL column type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | our $VERSION = '0.04'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub apply_mockdata_plugin { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_mockdata_plugin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my ($class, $mock)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | $mock->load_plugin('Text')->add_generators( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | map +("SQL::$_" => $class->can($_)), keys %type_generators | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub generator_for_type { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generator_for_type: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($mock, $type)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $type =~ s/\s+/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | my $gen= $mock->generators->{$type} // $mock->generators->{"SQL::$type"} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | // $type_generators{$type} && Mock::Data::GeneratorSub->new(__PACKAGE__->can($type)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
($mock->generators->{$type} // $mock->generators->{"SQL::$type"}) // $Mock::Data::Plugin::SQLTypes::type_generators{$type} && "Mock::Data::GeneratorSub"->new(__PACKAGE__->can($type))
$mock->generators->{$type} // $mock->generators->{"SQL::$type"}
$Mock::Data::Plugin::SQLTypes::type_generators{$type} and "Mock::Data::GeneratorSub"->new(__PACKAGE__->can($type))
MC/DC0%0/4
($mock->generators->{$type} // $mock->generators->{"SQL::$type"}) // $Mock::Data::Plugin::SQLTypes::type_generators{$type} && "Mock::Data::GeneratorSub"->new(__PACKAGE__->can($type))
$mock->generators->{$type}
$mock->generators->{"SQL::$type"}
$Mock::Data::Plugin::SQLTypes::type_generators{$type}
"Mock::Data::GeneratorSub"->new(__PACKAGE__->can($type))
Truth table0%0/5
A // B // C and D
A= $mock->generators->{$type}B= $mock->generators->{"SQL::$type"}C= $Mock::Data::Plugin::SQLTypes::type_generators{$type}D= "Mock::Data::GeneratorSub"->new(__PACKAGE__->can($type))
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # TODO: check for complex things like postgres arrays | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | return $gen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | ▶ | sub tinyint { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tinyint: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | ▶ | integer($mock, { $params? %$params : (), bits => 8 }, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 10 | ▶ | sub smallint { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smallint: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 10 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 10 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | ▶ | integer($mock, { $params? %$params : (), bits => 16 }, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | ▶ | sub bigint { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bigint: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | ▶ | integer($mock, { $params? %$params : (), bits => 64 }, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | BEGIN { *bigserial= *smallserial= *serial= *sequence; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | BEGIN { *numeric= *decimal; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | BEGIN { *real= *float4= *float; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 15 | ▶ | sub double { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
double: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 15 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 15 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | ▶ | float($mock, { bits => 53, $params? %$params : () }, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | BEGIN { *float8= *double_precision= *double; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | ▶ | sub bit { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | int rand 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | BEGIN { *bool= *boolean= *bit; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 30 | ▶ | sub varchar { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
varchar: called CC=12 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 30 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 30 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 30 | ▶ | my $size= shift // ($params? $params->{size} : undef) // 16; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
(shift() // ($params ? $params->{"size"} : undef)) // 16
shift() // ($params ? $params->{"size"} : undef)
MC/DC100%2/2
(shift() // ($params ? $params->{"size"} : undef)) // 16
shift()
($params ? $params->{"size"} : undef)
Truth table100%3/3
A // B
A= shift()B= ($params ? $params->{"size"} : undef)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 30 | ▶ | my $size_weight= ($params? $params->{size_weight} : undef) // \&_default_size_weight; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
($params ? $params->{"size_weight"} : undef) // \&Mock::Data::Plugin::SQLTypes::_default_size_weight
MC/DC0%0/1
($params ? $params->{"size_weight"} : undef) // \&Mock::Data::Plugin::SQLTypes::_default_size_weight
($params ? $params->{"size_weight"} : undef)
Truth table50%1/2
A
A= ($params ? $params->{"size_weight"} : undef)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 30 | ▶ | my $source= ($params? $params->{source} : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 30 | ▶ | if (defined $source && !ref $source) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $source and not ref $source
MC/DC0%0/2
defined $source and not ref $source
defined $source
not ref $source
Truth table33%1/3
A and not(B)
A= defined $sourceB= not ref $source
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | Carp::croak("No generator '$source' available") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | unless $mock->generators->{$source}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 30 | ▶ | $source= $mock->generators->{word}? 'word' : \&word; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 30 | return text_join($mock, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | source => $source, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | max_len => $size, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | len => $size_weight->($size), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 30 | ▶ | sub _default_size_weight { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_size_weight: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 30 | my $size= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 30 | ▶ | $size <= 32? int rand($size+1) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | : int rand(100)? int rand(33) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | : 33+int rand($size-31) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | BEGIN { *nvarchar= *varchar; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | ▶ | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | ▶ | varchar($mock, { size => 256, ($params? %$params : ()) }, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | BEGIN { *ntext= *tinytext= *mediumtext= *longtext= *text; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | sub char { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
char: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 10 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 10 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 10 | ▶ | my $size= @_? shift : ($params? $params->{size} : undef) // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
($params ? $params->{"size"} : undef) // 1
MC/DC0%0/1
($params ? $params->{"size"} : undef) // 1
($params ? $params->{"size"} : undef)
Truth table50%1/2
A
A= ($params ? $params->{"size"} : undef)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 10 | ▶ | my $str= varchar($mock, ($params? $params : ()), $size); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | $str .= ' 'x($size - length $str) if length $str < $size; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 10 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 20 | ▶ | sub _epoch_to_iso8601 { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_epoch_to_iso8601: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 20 | my @t= localtime(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 20 | return sprintf "%04d-%02d-%02d %02d:%02d:%02d", $t[5]+1900, $t[4]+1, @t[3,2,1,0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 20 | ▶ | sub _iso8601_to_epoch { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_iso8601_to_epoch: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 20 | my $str= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 20 | ▶ | $str =~ /^ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | (\d{4}) - (\d{2}) - (\d{2}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | (?: [T ] (\d{2}) : (\d{2}) # maybe time | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | (?: :(\d{2}) # maybe seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | (?: \. \d+ )? # ignore milliseconds | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | (?: Z | [-+ ][:\d]+ )? # ignore timezone or Z | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | /x or Carp::croak("Invalid date '$str'. Expecting format YYYY-MM-DD[ HH:MM:SS[.SSS][TZ]]"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 20 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 20 | ▶ | return POSIX::mktime($6||0, $5||0, $4||0, $3, $2-1, $1-1900); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$6 || 0
$5 || 0
$4 || 0
MC/DC0%0/1
$6 || 0
$6
MC/DC0%0/1
$5 || 0
$5
MC/DC0%0/1
$4 || 0
$4
Truth table50%1/2
A
A= $6
Truth table50%1/2
A
A= $5
Truth table50%1/2
A
A= $4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 20 | ▶ | sub datetime { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 20 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 20 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 20 | ▶ | my $before= $params && $params->{before}? _iso8601_to_epoch($params->{before}) : (time - 86400); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params and $params->{"before"}
MC/DC50%1/2
$params and $params->{"before"}
$params
$params->{"before"}
Truth table66%2/3
A and B
A= $paramsB= $params->{"before"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 20 | ▶ | my $after= $params && $params->{after}? _iso8601_to_epoch($params->{after}) : (time - int(10*365.25*86400)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params and $params->{"after"}
MC/DC50%1/2
$params and $params->{"after"}
$params
$params->{"after"}
Truth table66%2/3
A and B
A= $paramsB= $params->{"after"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 20 | _epoch_to_iso8601($after + int rand($before-$after)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 10 | ▶ | sub date { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | substr(datetime(@_), 0, 10) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | *timestamp= *datetime2= *datetime_without_time_zone= *datetime; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | *datetimeoffset= *datetime_with_time_zone= *datetime; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 10 | ▶ | sub blob { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blob: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 10 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 10 | ▶ | my $size= shift // ($params? $params->{size} : undef) // 256; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
(shift() // ($params ? $params->{"size"} : undef)) // 256
shift() // ($params ? $params->{"size"} : undef)
MC/DC50%1/2
(shift() // ($params ? $params->{"size"} : undef)) // 256
shift()
($params ? $params->{"size"} : undef)
Truth table66%2/3
A // B
A= shift()B= ($params ? $params->{"size"} : undef)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 10 | byte($mock, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | BEGIN { *tinyblob= *mediumblob= *longblob= *bytea= *binary= *varbinary= *blob; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | our $json; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub _json_encoder { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json_encoder: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $json //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Mock::Data::Plugin::SQLTypes::json //= do {
local $@;
my $mod = eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
} || eval {
do {
require JSON;
"JSON"
}
} || eval {
do {
require JSON::PP;
"JSON::PP"
}
} or Carp::croak("No JSON module found. This must be installed for the SQL::json generator.");
$mod->new->canonical->ascii
}
MC/DC0%0/2
$Mock::Data::Plugin::SQLTypes::json //= do {
local $@;
my $mod = eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
} || eval {
do {
require JSON;
"JSON"
}
} || eval {
do {
require JSON::PP;
"JSON::PP"
}
} or Carp::croak("No JSON module found. This must be installed for the SQL::json generator.");
$mod->new->canonical->ascii
}
$Mock::Data::Plugin::SQLTypes::json
do {
local $@;
my $mod = eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
} || eval {
do {
require JSON;
"JSON"
}
} || eval {
do {
require JSON::PP;
"JSON::PP"
}
} or Carp::croak("No JSON module found. This must be installed for the SQL::json generator.");
$mod->new->canonical->ascii
}
Truth table0%0/3
A //= B
A= $Mock::Data::Plugin::SQLTypes::jsonB= do {
local $@;
my $mod = eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
} || eval {
do {
require JSON;
"JSON"
}
} || eval {
do {
require JSON::PP;
"JSON::PP"
}
} or Carp::croak("No JSON module found. This must be installed for the SQL::json generator.");
$mod->new->canonical->ascii
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $mod= eval { require JSON::MaybeXS; 'JSON::MaybeXS' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | || eval { require JSON; 'JSON' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | || eval { require JSON::PP; 'JSON::PP' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
eval {
do {
require JSON::MaybeXS;
'JSON::MaybeXS'
}
} || eval {
do {
require JSON;
'JSON'
}
} || eval {
do {
require JSON::PP;
'JSON::PP'
}
}
eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
} or eval {
do {
require JSON;
"JSON"
}
}
MC/DC0%0/3
eval {
do {
require JSON::MaybeXS;
'JSON::MaybeXS'
}
} || eval {
do {
require JSON;
'JSON'
}
} || eval {
do {
require JSON::PP;
'JSON::PP'
}
}
eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
}
eval {
do {
require JSON;
"JSON"
}
}
eval {
do {
require JSON::PP;
'JSON::PP'
}
}
Truth table0%0/4
A or B || C
A= eval {
do {
require JSON::MaybeXS;
"JSON::MaybeXS"
}
}B= eval {
do {
require JSON;
"JSON"
}
}C= eval {
do {
require JSON::PP;
'JSON::PP'
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | or Carp::croak("No JSON module found. This must be installed for the SQL::json generator."); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $mod->new->canonical->ascii | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | ▶ | sub json { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json: called CC=5 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 10 | my $mock= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 10 | ▶ | my $params= ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | ▶ | my $data= shift // ($params? $params->{data} : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
shift() // ($params ? $params->{"data"} : undef)
MC/DC0%0/2
shift() // ($params ? $params->{"data"} : undef)
shift()
($params ? $params->{"data"} : undef)
Truth table33%1/3
A // B
A= shift()B= ($params ? $params->{"data"} : undef)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | return defined $data? _json_encoder->encode($data) : '{}'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | ▶ | BEGIN { *jsonb= *json; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||