| 1 | package DBIx::QuickORM::LookupTable; | ||||||||||||||||||||||||||||||||||||||
| 2 | 264 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 264 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 264 | our $VERSION = '0.000033'; | |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 264 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 264 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 264 | ▶ | use DBIx::QuickORM::RowState(); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 264 | ▶ | use Object::HashBase qw{ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | <connection | ||||||||||||||||||||||||||||||||||||||
| 14 | <db_map | ||||||||||||||||||||||||||||||||||||||
| 15 | <retain | ||||||||||||||||||||||||||||||||||||||
| 16 | <debug | ||||||||||||||||||||||||||||||||||||||
| 17 | <row_states | ||||||||||||||||||||||||||||||||||||||
| 18 | 264 | }; | |||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | =pod | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | DBIx::QuickORM::LookupTable - Base class for the lookup tables. | ||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | A lookup table decides which row hashes are canonical, and may cache rows by | ||||||||||||||||||||||||||||||||||||||
| 31 | primary key. Each Connection builds one, of the class the ORM's C<lookup> | ||||||||||||||||||||||||||||||||||||||
| 32 | argument names (C<< lookup => 'Identity' >> unless given). A bare name gets | ||||||||||||||||||||||||||||||||||||||
| 33 | the C<DBIx::QuickORM::LookupTable::> prefix, and a leading C<+> marks a fully | ||||||||||||||||||||||||||||||||||||||
| 34 | qualified class. The class is loaded when needed, and must compose | ||||||||||||||||||||||||||||||||||||||
| 35 | L<DBIx::QuickORM::Role::LookupTable>, which says what the Connection calls. | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | =item L<DBIx::QuickORM::LookupTable::Identity> | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | The default. One canonical hash per table and primary key, cached, with | ||||||||||||||||||||||||||||||||||||||
| 42 | writes and re-reads replacing it, inside and outside transactions. | ||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | =item L<DBIx::QuickORM::LookupTable::Scoped> | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | No cache, and every copy of a row canonical, except across a transaction | ||||||||||||||||||||||||||||||||||||||
| 47 | boundary: row data from outside a transaction cannot write in it, and row data | ||||||||||||||||||||||||||||||||||||||
| 48 | from one that rolled back cannot write anywhere. | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | =item L<DBIx::QuickORM::LookupTable::Unchecked> | ||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||
| 52 | No cache, and all row data canonical: no checks at all. | ||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | This class holds what every implementation needs from its Connection. An | ||||||||||||||||||||||||||||||||||||||
| 57 | implementation need not inherit it, but then must hold the connection weakly | ||||||||||||||||||||||||||||||||||||||
| 58 | itself. | ||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | # one that ships, by its short name | ||||||||||||||||||||||||||||||||||||||
| 63 | my $orm = DBIx::QuickORM->new(credentials => \%credentials, lookup => 'Scoped'); | ||||||||||||||||||||||||||||||||||||||
| 64 | my $lookup = $orm->connection->lookup; # a DBIx::QuickORM::LookupTable::Scoped | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | # one of your own, by its full name | ||||||||||||||||||||||||||||||||||||||
| 67 | my $mine = DBIx::QuickORM->new(credentials => \%credentials, lookup => '+My::LookupTable'); | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | L<DBIx::QuickORM::Role::LookupTable> shows how to write one. | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | Each but C<connection> comes from the connection unless given. | ||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | =item $conn = $lookup->connection | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | Required: the L<DBIx::QuickORM::Connection>, held weakly, since it holds the | ||||||||||||||||||||||||||||||||||||||
| 80 | lookup table. Once the connection is freed the lookup table cannot be used, | ||||||||||||||||||||||||||||||||||||||
| 81 | so nothing should keep one past its connection. | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | =item $map = $lookup->db_map | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | The connection's L<DBIx::QuickORM::Map>, which gives each table's primary key. | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | =item $bool = $lookup->retain | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | The connection's C<retain_cache>. | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | =item $debug = $lookup->debug | ||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | The connection's L<DBIx::QuickORM::Debug>, or undef. | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | =item $rs = $lookup->row_states | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | The connection's L<DBIx::QuickORM::RowState>, through which an implementation | ||||||||||||||||||||||||||||||||||||||
| 98 | marks the hashes it holds. | ||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 200 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=6 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $conn = $self->{+CONNECTION} or croak "'connection' is required"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $self->{+DB_MAP} = $conn->db_map unless exists $self->{+DB_MAP}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $self->{+RETAIN} = $conn->retain_cache unless exists $self->{+RETAIN}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $self->{+DEBUG} = $conn->debug unless exists $self->{+DEBUG}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->{+ROW_STATES} = $conn->row_states unless exists $self->{+ROW_STATES}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 111 | 0 | weaken($self->{+CONNECTION}); | |||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | =head1 PRIVATE METHODS | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | =item $status = $lookup->_stored_status(\%row_data) | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | The C<canon_status> of row data that is not in the database, from its | ||||||||||||||||||||||||||||||||||||||
| 121 | L<DBIx::QuickORM::RowState>: C<deleted> (with the marking call under | ||||||||||||||||||||||||||||||||||||||
| 122 | C<debug>) or C<not_in_db>. Undef for row data with neither mark. | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | =back | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | 320 | ▶ | sub _stored_status { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_stored_status: called CC=5 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_stored_status: not called CC=5 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my $state = DBIx::QuickORM::RowState->state($data) or return undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return {cause => 'not_in_db'} if $state eq 'vivified'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $by = $self->{+DEBUG} && $self->{+DEBUG}->deleted_by(DBIx::QuickORM::RowState->deleted_origin($data)); | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->{'debug'} && $self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
$self->{'debug'} && $self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
MC/DC50%1/2
$self->{'debug'} && $self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
$self->{'debug'}
$self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
MC/DC0%0/2
$self->{'debug'} && $self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
$self->{'debug'}
$self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
Truth table66%2/3
A && B
A= $self->{'debug'}B= $self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
Truth table0%0/3
A && B
A= $self->{'debug'}B= $self->{'debug'}->deleted_by('DBIx::QuickORM::RowState'->deleted_origin($data))
| |||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return {cause => 'deleted', $by ? (by => $by) : ()}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | 264 | 1; | |||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||||||||||||