| 1 | package Yancy::Backend::Memory; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 23 | our $VERSION = '1.087'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A backend entirely in memory | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 6 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 7 | #pod An in-memory "database" backend for Yancy. Uses L<Yancy::Util/match> to implement | ||||||||||||||||||||||||||||||||||||||||||
| 8 | #pod basic searching for (</list>). | ||||||||||||||||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 10 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # XXX: TODO Remove references to Local::Test | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use Mojo::Base '-base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 23 | ▶ | use List::Util qw( max ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use Mojo::JSON qw( true false from_json to_json encode_json ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use Mojo::File qw( path ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 23 | ▶ | use Storable qw( dclone ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | ▶ | use Role::Tiny qw( with ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | with 'Yancy::Backend::Role::Sync'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | ▶ | use Yancy::Util qw( match is_type order_by is_format ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 23 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 23 | our %DATA; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 84 | ▶ | my ( $class, $url, $schema ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 84 | ▶ | if ( $url ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 83 | my ( $path ) = $url =~ m{^[^:]+://[^/]+(?:/(.+))?$}; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 83 | ▶ | if ( $path ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | %DATA = %{ from_json( path( ( $ENV{MOJO_HOME} || () ), $path )->slurp ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'MOJO_HOME'} || ()
MC/DC0%0/2
$ENV{'MOJO_HOME'} || ()
$ENV{'MOJO_HOME'}
()
Truth table0%0/3
A || B
A= $ENV{'MOJO_HOME'}B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 84 | ▶ | $schema //= \%Local::Test::SCHEMA; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema //= \%Local::Test::SCHEMA
MC/DC100%1/1
$schema //= \%Local::Test::SCHEMA
$schema
Truth table100%2/2
A
A= $schema
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 84 | return bless { init_arg => $url, schema => $schema }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | sub schema { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 3177 | ▶ | my ( $self, $schema ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3177 | ▶ | if ( $schema ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 51 | $self->{schema} = $schema; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 51 | return; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 3126 | $self->{schema}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | sub collections; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 23 | *collections = *schema; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | sub create { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 113 | ▶ | my ( $self, $schema_name, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=17 SCAR=28.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 113 | $params = { %$params }; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 113 | my $props = $self->schema->{ $schema_name }{properties}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | $params->{ $_ } = $props->{ $_ }{default} // undef | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 113 | ▶ | for grep !exists $params->{ $_ }, | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$props->{$_}{"default"} // undef
MC/DC100%1/1
$props->{$_}{"default"} // undef
$props->{$_}{"default"}
Truth table100%2/2
A
A= $props->{$_}{"default"}
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | keys %$props; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 113 | $params = $self->_normalize( $schema_name, $params ); # makes a copy | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 113 | ▶ | my $id_field = $self->schema->{ $schema_name }{ 'x-id-field' } || 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->schema->{$schema_name}{'x-id-field'} || 'id'
MC/DC100%1/1
$self->schema->{$schema_name}{'x-id-field'} || 'id'
$self->schema->{$schema_name}{'x-id-field'}
Truth table100%2/2
A
A= $self->schema->{$schema_name}{'x-id-field'}
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 113 | ▶ | my @id_fields = ref $id_field eq 'ARRAY' ? @$id_field : ( $id_field ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Fill in any auto-increment data... | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 113 | for my $id_field ( @id_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 63 | # We haven't provided a value for an integer ID, assume it's autoinc | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 118 | ▶ | if ( !$params->{ $id_field } and $self->schema->{ $schema_name }{properties}{ $id_field }{type} eq 'integer' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
not $params->{$id_field} and $self->schema->{$schema_name}{"properties"}{$id_field}{"type"} eq "integer"
MC/DC50%1/2
not $params->{$id_field} and $self->schema->{$schema_name}{"properties"}{$id_field}{"type"} eq "integer"
not $params->{$id_field}
$self->schema->{$schema_name}{"properties"}{$id_field}{"type"} eq "integer"
Truth table66%2/3
not(A) and B
A= not $params->{$id_field}B= $self->schema->{$schema_name}{"properties"}{$id_field}{"type"} eq "integer"
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 55 | my @existing_ids = keys %{ $DATA{ $schema_name } }; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 55 | ▶ | $params->{ $id_field} = ( max( @existing_ids ) // 0 ) + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
&max(@existing_ids) // 0
MC/DC100%1/1
&max(@existing_ids) // 0
&max(@existing_ids)
Truth table100%2/2
A
A= &max(@existing_ids)
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # We have provided another ID, make 'id' another autoinc | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ▶ | elsif ( $params->{ $id_field } | |||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$params->{$id_field} and $id_field ne "id" and exists $self->schema->{$schema_name}{"properties"}{"id"}
$params->{$id_field} and $id_field ne "id"
MC/DC66%2/3
$params->{$id_field} and $id_field ne "id" and exists $self->schema->{$schema_name}{"properties"}{"id"}
$params->{$id_field}
$id_field ne "id"
exists $self->schema->{$schema_name}{"properties"}{"id"}
Truth table75%3/4
A and B and C
A= $params->{$id_field}B= $id_field ne "id"C= exists $self->schema->{$schema_name}{"properties"}{"id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | && $id_field ne 'id' | ||||||||||||||||||||||||||||||||||||||||||
| 71 | && exists $self->schema->{ $schema_name }{properties}{id} | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 46 | my @existing_ids = map { $_->{ id } } values %{ $DATA{ $schema_name } }; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 46 | ▶ | $params->{id} = ( max( @existing_ids ) // 0 ) + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
&max(@existing_ids) // 0
MC/DC100%1/1
&max(@existing_ids) // 0
&max(@existing_ids)
Truth table100%2/2
A
A= &max(@existing_ids)
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 113 | ▶ | my $store = $DATA{ $schema_name } //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Yancy::Backend::Memory::DATA{$schema_name} //= {}
MC/DC100%1/1
$Yancy::Backend::Memory::DATA{$schema_name} //= {}
$Yancy::Backend::Memory::DATA{$schema_name}
Truth table100%2/2
A
A= $Yancy::Backend::Memory::DATA{$schema_name}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 113 | for my $i ( 0 .. $#id_fields-1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | $store = $store->{ $params->{ $id_fields[$i] } } //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$store{$$params{$id_fields[$i]}} //= {}
MC/DC100%1/1
$$store{$$params{$id_fields[$i]}} //= {}
$$store{$$params{$id_fields[$i]}}
Truth table100%2/2
A
A= $$store{$$params{$id_fields[$i]}}
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 113 | $store->{ $params->{ $id_fields[-1] } } = $params; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 113 | ▶ | return @id_fields > 1 ? { map {; $_ => $params->{ $_ } } @id_fields } : $params->{ $id_field }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | sub get { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 325 | ▶ | my ( $self, $schema_name, $id, %opt ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 325 | my $schema = $self->schema->{ $schema_name }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 325 | ▶ | my $real_coll = ( $schema->{'x-view'} || {} )->{schema} // $schema_name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'} || {}
MC/DC0%0/2
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'}
$schema_name
Truth table66%2/3
A // B
A= $schema->{'x-view'}B= $schema_name
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 325 | ▶ | my $id_field = $self->schema->{ $schema_name }{ 'x-id-field' } || 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->schema->{$schema_name}{'x-id-field'} || 'id'
MC/DC100%1/1
$self->schema->{$schema_name}{'x-id-field'} || 'id'
$self->schema->{$schema_name}{'x-id-field'}
Truth table100%2/2
A
A= $self->schema->{$schema_name}{'x-id-field'}
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 325 | ▶ | my @ids = ref $id_field eq 'ARRAY' ? map { $id->{ $_ } } @$id_field : ( $id ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 324 | ▶ | die "Missing composite ID parts" if @ids > 1 && ( !ref $id || keys %$id < @ids ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@ids > 1 and !ref($id) || keys %$id < @ids
not ref $id or keys %$id < @ids
MC/DC66%2/3
@ids > 1 and !ref($id) || keys %$id < @ids
@ids > 1
not ref $id
keys %$id < @ids
Truth table75%3/4
A and not(B) or C
A= @ids > 1B= not ref $idC= keys %$id < @ids
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 323 | my $item = $DATA{ $real_coll }; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 323 | for my $id ( @ids ) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | 334 | ▶ | return undef if !defined $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 331 | ▶ | $item = $item->{ $id } // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$item->{$id} // (return undef)
MC/DC100%1/1
$item->{$id} // (return undef)
$item->{$id}
Truth table100%2/2
A
A= $item->{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 279 | $item = $self->_viewise( $schema_name, $item ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 279 | ▶ | if ( my $join = $opt{join} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | $item = $self->_join( $schema_name, $item, $join ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 279 | return $item; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | sub _join { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 19 | ▶ | my ( $self, $schema_name, $item, $join, $where ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_join: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 19 | $item = { %$item }; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 19 | my $schema = $self->schema->{ $schema_name }; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 19 | ▶ | my $id_field = $self->schema->{ $schema_name }{ 'x-id-field' } || 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->schema->{$schema_name}{'x-id-field'} || 'id'
MC/DC0%0/1
$self->schema->{$schema_name}{'x-id-field'} || 'id'
$self->schema->{$schema_name}{'x-id-field'}
Truth table50%1/2
A
A= $self->schema->{$schema_name}{'x-id-field'}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 19 | ▶ | my @joins = ref $join eq 'ARRAY' ? @$join : ( $join ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 19 | for my $join ( @joins ) { | |||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | ▶ | if ( my $join_prop = $schema->{ properties }{ $join } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 21 | ▶ | my $join_id = $item->{ $join } || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$item->{$join} || (next)
MC/DC100%1/1
$item->{$join} || (next)
$item->{$join}
Truth table100%2/2
A
A= $item->{$join}
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 17 | my $join_schema_name = $join_prop->{'x-foreign-key'}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 17 | $item->{ $join } = $self->get( $join_schema_name, $join_id ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 17 | for my $key ( grep /^${join}\./, keys %$where ) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | my ( $k ) = $key =~ /^${join}\.(.+)$/; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | ▶ | if ( !match( { $k => $where->{ $key } }, $item->{ $join } ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | # Inner match fails, so this row is not in the | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # results | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | elsif ( my $join_schema = $self->schema->{ $join } ) { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | my $join_schema_name = $join; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | ▶ | my ( $join_id_field ) = grep { ( $join_schema->{properties}{$_}{'x-foreign-key'}//'' ) eq $schema_name } keys %{ $join_schema->{properties} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$join_schema->{"properties"}{$_}{"x-foreign-key"} // ""
MC/DC100%1/1
$join_schema->{"properties"}{$_}{"x-foreign-key"} // ""
$join_schema->{"properties"}{$_}{"x-foreign-key"}
Truth table100%2/2
A
A= $join_schema->{"properties"}{$_}{"x-foreign-key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | ▶ | my $join_where = ref $id_field eq 'ARRAY' ? { map { $_ => $item->{ $_ } } @$join_id_field } : { $join_id_field => $item->{$join_id_field} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | my $min_items = 0; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | for my $key ( grep /^${join}\./, keys %$where ) { | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | my ( $k ) = $key =~ /^${join}\.(.+)$/; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | $join_where->{ $k } = $where->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | $min_items = 1; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | my $res = $self->list( $join_schema_name, $join_where ); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | return if $res->{total} < $min_items; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | $item->{ $join } = $res->{items}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 16 | return $item; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | sub _viewise { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 625 | ▶ | my ( $self, $schema_name, $item, $join ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_viewise: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 625 | $item = dclone $item; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 625 | my $schema = $self->schema->{ $schema_name }; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 625 | ▶ | my $real_coll = ( $schema->{'x-view'} || {} )->{schema} // $schema_name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'} || {}
MC/DC0%0/2
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'}
$schema_name
Truth table66%2/3
A // B
A= $schema->{'x-view'}B= $schema_name
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | my %props = %{ | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 625 | $schema->{properties} || $self->schema->{ $real_coll }{properties} | |||||||||||||||||||||||||||||||||||||||||
| 155 | 625 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 625 | ▶ | if ( $join ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 12 | ▶ | $props{ $_ } = 1 for @{ ref $join eq 'ARRAY' ? $join : [ $join ] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 625 | delete $item->{$_} for grep !$props{ $_ }, keys %$item; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 625 | $item; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | sub list { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 327 | ▶ | my ( $self, $schema_name, $params, @opt ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=18 SCAR=29.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 327 | ▶ | my $opt = @opt % 2 == 0 ? {@opt} : $opt[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 327 | my $schema = $self->schema->{ $schema_name }; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 327 | ▶ | die "list attempted on non-existent schema '$schema_name'" unless $schema; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 327 | ▶ | $params ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params ||= {}
MC/DC100%1/1
$params ||= {}
$params
Truth table100%2/2
A
A= $params
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 327 | ▶ | my $id_field = $self->schema->{ $schema_name }{ 'x-id-field' } || 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->schema->{$schema_name}{'x-id-field'} || 'id'
MC/DC100%1/1
$self->schema->{$schema_name}{'x-id-field'} || 'id'
$self->schema->{$schema_name}{'x-id-field'}
Truth table100%2/2
A
A= $self->schema->{$schema_name}{'x-id-field'}
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 327 | ▶ | my @id_fields = ref $id_field eq 'ARRAY' ? @$id_field : ( $id_field ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 327 | ▶ | my $real_coll = ( $schema->{'x-view'} || {} )->{schema} // $schema_name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'} || {}
MC/DC0%0/2
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'}
$schema_name
Truth table66%2/3
A // B
A= $schema->{'x-view'}B= $schema_name
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | my $props = $schema->{properties} | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 327 | ▶ | || $self->schema->{ $real_coll }{properties}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$schema->{'properties'} || $self->schema->{$real_coll}{'properties'}
MC/DC0%0/2
$schema->{'properties'} || $self->schema->{$real_coll}{'properties'}
$schema->{'properties'}
$self->schema->{$real_coll}{'properties'}
Truth table33%1/3
A || B
A= $schema->{'properties'}B= $self->schema->{$real_coll}{'properties'}
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 327 | my @rows = values %{ $DATA{ $real_coll } }; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 327 | for my $id_field ( 1..$#id_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 178 | 8 | @rows = map values %$_, @rows; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 327 | ▶ | if ( $opt->{join} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | @rows = map $self->_join( $schema_name, $_, $opt->{join}, $params ), @rows; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # Join queries have been resolved | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 327 | ▶ | for my $p ( ref $params eq 'ARRAY' ? @$params : ( $params ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 328 | for my $key ( grep /\./, keys %$p ) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | delete $p->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | my ( $j ) = split /\./, $key; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 4 | $p->{ $j } = { '!=' => undef }; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | my $matched_rows = order_by( | ||||||||||||||||||||||||||||||||||||||||||
| 192 | $opt->{order_by} // \@id_fields, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 327 | ▶ | [ grep { match( $params, $_ ) } @rows ], | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt->{"order_by"} // \@id_fields
MC/DC100%1/1
$opt->{"order_by"} // \@id_fields
$opt->{"order_by"}
Truth table100%2/2
A
A= $opt->{"order_by"}
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 327 | ▶ | my $first = $opt->{offset} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt->{"offset"} // 0
MC/DC100%1/1
$opt->{"offset"} // 0
$opt->{"offset"}
Truth table100%2/2
A
A= $opt->{"offset"}
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 327 | ▶ | my $last = $opt->{limit} ? $opt->{limit} + $first - 1 : $#$matched_rows; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 327 | ▶ | if ( $last > $#$matched_rows ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 57 | $last = $#$matched_rows; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 327 | my @items = map $self->_viewise( $schema_name, $_, $opt->{join} ), @$matched_rows[ $first .. $last ]; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 327 | my $retval = { | |||||||||||||||||||||||||||||||||||||||||
| 202 | items => \@items, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | total => scalar @$matched_rows, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | #; use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | #; say Dumper $retval; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 327 | return $retval; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | sub set { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 58 | ▶ | my ( $self, $schema_name, $id, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 58 | ▶ | my $id_field = $self->schema->{ $schema_name }{ 'x-id-field' } || 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->schema->{$schema_name}{'x-id-field'} || 'id'
MC/DC100%1/1
$self->schema->{$schema_name}{'x-id-field'} || 'id'
$self->schema->{$schema_name}{'x-id-field'}
Truth table100%2/2
A
A= $self->schema->{$schema_name}{'x-id-field'}
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 58 | ▶ | my @id_fields = ref $id_field eq 'ARRAY' ? @$id_field : ( $id_field ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 58 | ▶ | die "Missing composite ID parts" if @id_fields > 1 && ( !ref $id || keys %$id < @id_fields ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@id_fields > 1 and !ref($id) || keys %$id < @id_fields
not ref $id or keys %$id < @id_fields
MC/DC66%2/3
@id_fields > 1 and !ref($id) || keys %$id < @id_fields
@id_fields > 1
not ref $id
keys %$id < @id_fields
Truth table75%3/4
A and not(B) or C
A= @id_fields > 1B= not ref $idC= keys %$id < @id_fields
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # Fill in any missing params from the ID | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 56 | for my $id_field ( @id_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 218 | 58 | ▶ | my $id_part = ref $id eq 'HASH' ? $id->{ $id_field } : $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 58 | ▶ | if ( !$params->{ $id_field } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 34 | $params->{ $id_field } = $id_part; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 56 | $params = $self->_normalize( $schema_name, $params ); | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 56 | my $store = $DATA{ $schema_name }; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 56 | for my $i ( 0..$#id_fields-1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | my $id_field = $id_fields[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | my $id_part = ref $id eq 'HASH' ? $id->{ $id_field } : $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | ▶ | return 0 if !$store->{ $id_part }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | # Update the item's ID if it changes | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $item = delete $store->{ $id_part }; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | $store->{ $params->{ $id_field } } = $item; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | $store = $item; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 56 | ▶ | my $id_part = ref $id eq 'HASH' ? $id->{ $id_fields[-1] } : $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 56 | ▶ | return 0 if !$store->{ $id_part }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | $store->{ $params->{ $id_fields[-1] } } = { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 46 | %{ delete $store->{ $id_part } }, | |||||||||||||||||||||||||||||||||||||||||
| 240 | %$params, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 46 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | sub delete { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 94 | ▶ | my ( $self, $schema_name, $id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 94 | ▶ | return 0 if !$id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 94 | ▶ | my $id_field = $self->schema->{ $schema_name }{ 'x-id-field' } || 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->schema->{$schema_name}{'x-id-field'} || 'id'
MC/DC100%1/1
$self->schema->{$schema_name}{'x-id-field'} || 'id'
$self->schema->{$schema_name}{'x-id-field'}
Truth table100%2/2
A
A= $self->schema->{$schema_name}{'x-id-field'}
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 94 | ▶ | my @id_fields = ref $id_field eq 'ARRAY' ? @$id_field : ( $id_field ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 94 | ▶ | die "Missing composite ID parts" if @id_fields > 1 && ( !ref $id || keys %$id < @id_fields ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@id_fields > 1 and !ref($id) || keys %$id < @id_fields
not ref $id or keys %$id < @id_fields
MC/DC66%2/3
@id_fields > 1 and !ref($id) || keys %$id < @id_fields
@id_fields > 1
not ref $id
keys %$id < @id_fields
Truth table75%3/4
A and not(B) or C
A= @id_fields > 1B= not ref $idC= keys %$id < @id_fields
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 92 | my $store = $DATA{ $schema_name }; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 92 | for my $i ( 0..$#id_fields-1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | my $id_field = $id_fields[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | ▶ | my $id_part = ref $id eq 'HASH' ? $id->{ $id_field } : $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | $store = $store->{ $id_part } // return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$store->{$id_part} // (return 0)
MC/DC0%0/1
$store->{$id_part} // (return 0)
$store->{$id_part}
Truth table50%1/2
A
A= $store->{$id_part}
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 92 | ▶ | my $id_part = ref $id eq 'HASH' ? $id->{ $id_fields[-1] } : $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 92 | ▶ | return 0 if !$store->{ $id_part }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 70 | return !!delete $store->{ $id_part }; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | sub _normalize { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 169 | ▶ | my ( $self, $schema_name, $data ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 169 | ▶ | return undef if !$data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 169 | my $schema = $self->schema->{ $schema_name }{ properties }; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 169 | my %replace; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 169 | for my $key ( keys %$data ) { | |||||||||||||||||||||||||||||||||||||||||
| 269 | 1035 | ▶ | next if !defined $data->{ $key }; # leave nulls alone | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 819 | my ( $type, $format ) = @{ $schema->{ $key } }{qw( type format )}; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 819 | ▶ | if ( is_type( $type, 'boolean' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | # Boolean: true (1, "true"), false (0, "false") | ||||||||||||||||||||||||||||||||||||||||||
| 273 | $replace{ $key } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 56 | ▶ | = $data->{ $key } && $data->{ $key } !~ /^false$/i | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data->{$key} and not $data->{$key} =~ /^false$/iu
MC/DC100%2/2
$data->{$key} and not $data->{$key} =~ /^false$/iu
$data->{$key}
not $data->{$key} =~ /^false$/iu
Truth table100%3/3
A and not(B)
A= $data->{$key}B= not $data->{$key} =~ /^false$/iu
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | ▶ | elsif ( is_type( $type, 'string' ) && is_format( $format, 'date-time' ) ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
is_type($type, "string") and is_format($format, "date-time")
MC/DC100%2/2
is_type($type, "string") and is_format($format, "date-time")
is_type($type, "string")
is_format($format, "date-time")
Truth table100%3/3
A and B
A= is_type($type, "string")B= is_format($format, "date-time")
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 70 | ▶ | if ( $data->{ $key } eq 'now' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 57 | $replace{ $key } = Time::Piece->new->datetime; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 169 | +{ %$data, %replace }; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | # Some databases can know other formats | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 23 | my %db_formats = map { $_ => 1 } qw( date time date-time binary ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | sub read_schema { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 104 | ▶ | my ( $self, @table_names ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_schema: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 104 | ▶ | my $schema = %Local::Test::SCHEMA ? \%Local::Test::SCHEMA : $self->schema; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 104 | my $cloned = dclone $schema; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 104 | delete @$cloned{@Local::Test::SCHEMA_ADDED_COLLS}; # ones not in the "database" at all | |||||||||||||||||||||||||||||||||||||||||
| 294 | # zap all things that DB can't know about | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 104 | for my $c ( values %$cloned ) { | |||||||||||||||||||||||||||||||||||||||||
| 296 | 463 | delete $c->{'x-list-columns'}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 463 | for my $p ( values %{ $c->{properties} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 298 | 2890 | delete @$p{ qw(description pattern title) }; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 2890 | ▶ | if ( $p->{format} && !$db_formats{ $p->{format} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p->{"format"} and not $db_formats{$p->{"format"}}
MC/DC100%2/2
$p->{"format"} and not $db_formats{$p->{"format"}}
$p->{"format"}
not $db_formats{$p->{"format"}}
Truth table100%3/3
A and not(B)
A= $p->{"format"}B= not $db_formats{$p->{"format"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 399 | delete $p->{format}; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 104 | ▶ | return @table_names ? @$cloned{ @table_names } : $cloned; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | sub supports { grep { $_[1] eq $_ } 'complex-type' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supports: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | __END__ | ||||||||||||||||||||||||||||||||||||||||||