« blib/lib/DBIx/QuickORM/Dialect/PostgreSQL.pm
↑ Summary
blib/lib/DBIx/QuickORM/SchemaBuilder/Table/Temp.pm »
| 1 | package DBIx::QuickORM::Connection::Offline; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = '0.000033'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use parent 'DBIx::QuickORM::Connection'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Object::HashBase qw{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | <raw_tables | ||||||||||||||||||||||||||||
| 12 | 4 | }; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =pod | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | DBIx::QuickORM::Connection::Offline - The stand-in connection of an offline ORM. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | What C<offline> on an ORM class (see L<DBIx::QuickORM::ORM>) connects through: | ||||||||||||||||||||||||||||
| 25 | a L<DBIx::QuickORM::Connection> with a dialect and a map but no database. It | ||||||||||||||||||||||||||||
| 26 | scans nothing and sets up no session. Its C<dbh> is a stand-in that dies | ||||||||||||||||||||||||||||
| 27 | with a stack trace for any method, so anything that would send a query dies | ||||||||||||||||||||||||||||
| 28 | there, while handles still build their SQL. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | As L<DBIx::QuickORM::Connection>, with C<dialect> and C<db_map> required and | ||||||||||||||||||||||||||||
| 33 | no C<dbh>, and: | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =over 4 | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item \%names = $conn->raw_tables | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | The tables and views the map lacks, by name: C<sql> for those the schema | ||||||||||||||||||||||||||||
| 40 | gives as SQL, C<none> for those with a table class but no schema. A handle | ||||||||||||||||||||||||||||
| 41 | naming one says how to have it offline. Default none. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =back | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 24 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 24 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 24 | ▶ | croak "An offline connection needs the 'dialect'" unless $self->{+DIALECT}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 23 | ▶ | croak "An offline connection needs the 'db_map'" unless $self->{+DB_MAP}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 22 | ▶ | croak "An offline connection takes no 'dbh'" if $self->{+DBH}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 21 | $self->_init_settings; | |||||||||||||||||||||||||||
| 53 | 21 | ▶ | $self->{+RAW_TABLES} //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"raw_tables"} //= {}
MC/DC100%1/1
$self->{"raw_tables"} //= {}
$self->{"raw_tables"}
Truth table100%2/2
A
A= $self->{"raw_tables"}
| |||||||||||||||||||||||||||||
| 54 | 21 | $self->{+DB_MAP} = $self->{+DB_MAP}->shallow_copy; | |||||||||||||||||||||||||||
| 55 | 21 | $self->{+DBH} = bless({}, 'DBIx::QuickORM::Connection::Offline::DBH'); | |||||||||||||||||||||||||||
| 56 | 21 | delete $self->{rescan}; | |||||||||||||||||||||||||||
| 57 | 21 | $self->{+PID} = $$; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 PRIVATE METHODS | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =over 4 | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item $note = $conn->_gone_note($name) | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | As inherited, and for a table the map lacks, a note saying to define it | ||||||||||||||||||||||||||||
| 67 | with a C<schema> block to use it offline. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =back | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 5 | ▶ | sub _gone_note { | ||||||||||||||||||||||||||
|
Subroutine
_gone_note: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 74 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 5 | my ($name) = @_; | |||||||||||||||||||||||||||
| 76 | 5 | ▶ | my $why = defined($name) && $self->{+RAW_TABLES}->{$name}; | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $name && $self->{'raw_tables'}{$name}
MC/DC50%1/2
defined $name && $self->{'raw_tables'}{$name}
defined $name
$self->{'raw_tables'}{$name}
Truth table66%2/3
A && B
A= defined $nameB= $self->{'raw_tables'}{$name}
| |||||||||||||||||||||||||||||
| 77 | 5 | ▶ | return " (the schema gives it as SQL, which an offline ORM cannot map; define it with a 'schema' block to use it offline)" if $why && $why eq 'sql'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$why and $why eq "sql"
MC/DC100%2/2
$why and $why eq "sql"
$why
$why eq "sql"
Truth table100%3/3
A and B
A= $whyB= $why eq "sql"
| |||||||||||||||||||||||||||||
| 78 | 3 | ▶ | return " (its table class has no schema; give it a 'schema' block to use it offline)" if $why; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 1 | return $self->SUPER::_gone_note(@_); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | package DBIx::QuickORM::Connection::Offline::DBH; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 4 | ▶ | use Carp qw/confess/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 3 | ▶ | sub can { undef } | ||||||||||||||||||||||||||
|
Subroutine
can: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | 2 | my ($method) = $AUTOLOAD =~ m/([^:]+)\z/; | |||||||||||||||||||||||||||
| 93 | # A full trace: the query starts in the caller's code, many frames up. | ||||||||||||||||||||||||||||
| 94 | 2 | confess "An offline ORM has no database, so it cannot $method (it builds SQL, but sends none)"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 4 | 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||