| 1 | package DBIx::Class::Schema::KiokuDB; | ||||||||||||||||||||
| 2 | 8 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 8 | $DBIx::Class::Schema::KiokuDB::AUTHORITY = 'cpan:NUFFIN'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | # ABSTRACT: Hybrid KiokuDB/DBIx::Class::Schema schema support. | ||||||||||||||||||||
| 6 | 8 | $DBIx::Class::Schema::KiokuDB::VERSION = '1.23'; | |||||||||||||||||||
| 7 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 8 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 8 | ▶ | use DBI 1.607 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 8 | ▶ | use DBIx::Class 0.08127 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 8 | ▶ | use DBIx::Class::KiokuDB::EntryProxy; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 8 | ▶ | use DBIx::Class::ResultSource::Table; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 8 | ▶ | use Scalar::Util qw(weaken refaddr); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 8 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 8 | ▶ | use base qw(Class::Accessor::Grouped); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 8 | __PACKAGE__->mk_group_accessors( inherited => "kiokudb_entries_source_name" ); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 22 | ▶ | sub kiokudb_handle { | ||||||||||||||||||
|
Subroutine
kiokudb_handle: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 26 | 22 | my $self = shift; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 22 | ▶ | croak "Can't call kiokudb_handle on unconnected schema" unless ref $self; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 22 | ▶ | unless ( $self->{kiokudb_handle} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 1 | require KiokuDB; | |||||||||||||||||||
| 32 | 1 | require KiokuDB::Backend::DBI; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | ▶ | croak "Can't vivify KiokuDB handle without KiokuDB schema bits. " . | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | "Add __PACKAGE__->define_kiokudb_schema() to your schema class" | ||||||||||||||||||||
| 36 | unless $self->kiokudb_entries_source_name; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | my $dir = KiokuDB->new( | |||||||||||||||||||
| 39 | backend => my $backend = KiokuDB::Backend::DBI->new( | ||||||||||||||||||||
| 40 | connected_schema => $self, | ||||||||||||||||||||
| 41 | ), | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | $backend->meta->get_attribute('schema')->_weaken_value($backend); # FIXME proper MOP api? | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # not weak | ||||||||||||||||||||
| 47 | 1 | $self->{kiokudb_handle} = $dir; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 22 | $self->{kiokudb_handle}; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 62 | ▶ | sub _kiokudb_handle { | ||||||||||||||||||
|
Subroutine
_kiokudb_handle: called CC=5 SCAR=19.1
| |||||||||||||||||||||
| 54 | 62 | my ( $self, $handle ) = @_; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 62 | ▶ | croak "Can't call _kiokudb_handle on unconnected schema" unless ref $self; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 62 | ▶ | croak "Can't vivify KiokuDB handle without KiokuDB schema bits. " . | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | "Add __PACKAGE__->define_kiokudb_schema() to your schema class" | ||||||||||||||||||||
| 60 | unless $self->kiokudb_entries_source_name; | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 62 | ▶ | if ( $self->{kiokudb_handle} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | ▶ | if ( refaddr($self->{kiokudb_handle}) != refaddr($handle) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | croak "KiokuDB directory already registered"; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||
| 67 | 62 | $self->{kiokudb_handle} = $handle; | |||||||||||||||||||
| 68 | 62 | weaken($self->{kiokudb_handle}); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 62 | return $handle; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 63 | ▶ | sub define_kiokudb_schema { | ||||||||||||||||||
|
Subroutine
define_kiokudb_schema: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||
| 75 | 63 | my ( $self, @args ) = @_; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 63 | my %args = ( | |||||||||||||||||||
| 78 | schema => $self, | ||||||||||||||||||||
| 79 | entries_table => "entries", | ||||||||||||||||||||
| 80 | gin_index_table => "gin_index", | ||||||||||||||||||||
| 81 | result_class => "DBIx::Class::KiokuDB::EntryProxy", | ||||||||||||||||||||
| 82 | gin_index => 1, | ||||||||||||||||||||
| 83 | @args, | ||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 63 | ▶ | my $entries_source_name = $args{entries_source} ||= $args{entries_table}; | ||||||||||||||||||
|
Condition33%1/3
$args{"entries_source"} ||= $args{"entries_table"}
MC/DC0%0/2
$args{"entries_source"} ||= $args{"entries_table"}
$args{"entries_source"}
$args{"entries_table"}
Truth table33%1/3
A ||= B
A= $args{"entries_source"}B= $args{"entries_table"}
| |||||||||||||||||||||
| 87 | 63 | ▶ | my $gin_index_source_name = $args{gin_index_source} ||= $args{gin_index_table}; | ||||||||||||||||||
|
Condition33%1/3
$args{"gin_index_source"} ||= $args{"gin_index_table"}
MC/DC0%0/2
$args{"gin_index_source"} ||= $args{"gin_index_table"}
$args{"gin_index_source"}
$args{"gin_index_table"}
Truth table33%1/3
A ||= B
A= $args{"gin_index_source"}B= $args{"gin_index_table"}
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 63 | my $entries = $self->define_kiokudb_entries_resultsource(%args); | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 63 | my $schema = $args{schema}; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 63 | $schema->register_source( $entries_source_name => $entries ); | |||||||||||||||||||
| 94 | 63 | ▶ | if ($args{gin_index}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 63 | my $gin_index = $self->define_kiokudb_gin_index_resultsource(%args); | |||||||||||||||||||
| 96 | 63 | $schema->register_source( $gin_index_source_name => $gin_index ); | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 63 | ▶ | $schema->kiokudb_entries_source_name($entries_source_name) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | unless $schema->kiokudb_entries_source_name; | ||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 63 | ▶ | sub define_kiokudb_entries_resultsource { | ||||||||||||||||||
|
Subroutine
define_kiokudb_entries_resultsource: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 105 | 63 | my ( $self, %args ) = @_; | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 63 | my $entries = DBIx::Class::ResultSource::Table->new({ name => $args{entries_table} }); | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | $entries->add_columns( | ||||||||||||||||||||
| 110 | id => { data_type => "varchar" }, | ||||||||||||||||||||
| 111 | data => { data_type => "blob", is_nullable => 0 }, # FIXME longblob for mysql | ||||||||||||||||||||
| 112 | class => { data_type => "varchar", is_nullable => 1 }, | ||||||||||||||||||||
| 113 | root => { data_type => "boolean", is_nullable => 0 }, | ||||||||||||||||||||
| 114 | tied => { data_type => "char", size => 1, is_nullable => 1 }, | ||||||||||||||||||||
| 115 | 63 | ▶ | @{ $args{extra_entries_columns} || [] }, | ||||||||||||||||||
|
Condition100%2/2
$args{'extra_entries_columns'} || []
MC/DC100%1/1
$args{'extra_entries_columns'} || []
$args{'extra_entries_columns'}
Truth table100%2/2
A
A= $args{'extra_entries_columns'}
| |||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 63 | $entries->set_primary_key("id"); | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 6 | ▶ | $entries->sqlt_deploy_callback(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 121 | 6 | my ($source, $sqlt_table) = @_; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 6 | $sqlt_table->extra->{mysql_table_type} = "InnoDB"; | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 6 | ▶ | if ( $source->schema->storage->sqlt_type eq 'MySQL' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | 0 | $sqlt_table->get_field('data')->data_type('longblob'); | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | 63 | }); | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 63 | $entries->result_class($args{result_class}); | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 63 | return $entries; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 63 | ▶ | sub define_kiokudb_gin_index_resultsource { | ||||||||||||||||||
|
Subroutine
define_kiokudb_gin_index_resultsource: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 136 | 63 | my ( $self, %args ) = @_; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 63 | my $gin_index = DBIx::Class::ResultSource::Table->new({ name => $args{gin_index_table} }); | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 63 | $gin_index->add_columns( | |||||||||||||||||||
| 141 | id => { data_type => "varchar", is_foreign_key => 1 }, | ||||||||||||||||||||
| 142 | value => { data_type => "varchar" }, | ||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 63 | $gin_index->add_relationship('entry_ids', $args{entries_source}, { 'foreign.id' => 'self.id' }); | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 6 | ▶ | $gin_index->sqlt_deploy_callback(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||
| 148 | 6 | my ($source, $sqlt_table) = @_; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 6 | $sqlt_table->extra->{mysql_table_type} = "InnoDB"; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 6 | ▶ | $sqlt_table->add_index( name => 'gin_index_ids', fields => ['id'] ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | or die $sqlt_table->error; | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 6 | ▶ | $sqlt_table->add_index( name => 'gin_index_values', fields => ['value'] ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | or die $sqlt_table->error; | ||||||||||||||||||||
| 158 | 63 | }); | |||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 63 | return $gin_index; | |||||||||||||||||||
| 161 | } | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | # ex: set sw=4 et: | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 8 | __PACKAGE__ | |||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||