| 1 | 6 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Metabase::Index::SQL; | ||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Metabase index backend role for common SQL actions | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | our $VERSION = '1.001'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Class::Load qw/load_class try_load_class/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Data::Stream::Bulk::Array; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Data::Stream::Bulk::Nil; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use DBIx::RunSQL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use DBIx::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use List::AllUtils qw/uniq/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use SQL::Abstract; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use SQL::Translator::Schema; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use SQL::Translator::Schema::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use SQL::Translator::Diff; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | use SQL::Translator::Utils qw/normalize_name/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use SQL::Translator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 6 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | use Metabase::Fact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | with 'Metabase::Backend::SQL'; | |||||||||||||||||||||||||||
| 29 | 6 | with 'Metabase::Index' => { -version => 1.000 }; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | has typemap => ( | |||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 34 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | requires '_build_typemap'; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 40 | # attributes built by the role | ||||||||||||||||||||||||||||
| 41 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | has _core_table => ( | ||||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||
| 45 | isa => 'Str', | ||||||||||||||||||||||||||||
| 46 | 71 | ▶ | default => sub { "core_meta" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 6 | ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | has _requested_content_type => ( | |||||||||||||||||||||||||||
| 50 | is => 'rw', | ||||||||||||||||||||||||||||
| 51 | isa => 'Str', | ||||||||||||||||||||||||||||
| 52 | clearer => '_clear_requested_content_type', | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | has _requested_resource_type => ( | |||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||
| 57 | isa => 'Str', | ||||||||||||||||||||||||||||
| 58 | clearer => '_clear_requested_resource_type', | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 6 | has _query_fields => ( | |||||||||||||||||||||||||||
| 62 | traits => ['Array'], | ||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||
| 64 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 65 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 66 | handles => { | ||||||||||||||||||||||||||||
| 67 | _push_query_fields => 'push', | ||||||||||||||||||||||||||||
| 68 | _grep_query_fields => 'grep', | ||||||||||||||||||||||||||||
| 69 | _all_query_fields => 'elements', | ||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 6 | has _content_tables => ( | |||||||||||||||||||||||||||
| 74 | traits => ['Array'], | ||||||||||||||||||||||||||||
| 75 | is => 'ro', | ||||||||||||||||||||||||||||
| 76 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 77 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 78 | handles => { | ||||||||||||||||||||||||||||
| 79 | _push_content_tables => 'push', | ||||||||||||||||||||||||||||
| 80 | _grep_content_tables => 'grep', | ||||||||||||||||||||||||||||
| 81 | _all_content_tables => 'elements', | ||||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 6 | has _resource_tables => ( | |||||||||||||||||||||||||||
| 86 | traits => ['Array'], | ||||||||||||||||||||||||||||
| 87 | is => 'ro', | ||||||||||||||||||||||||||||
| 88 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 89 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 90 | handles => { | ||||||||||||||||||||||||||||
| 91 | _push_resource_tables => 'push', | ||||||||||||||||||||||||||||
| 92 | _grep_resource_tables => 'grep', | ||||||||||||||||||||||||||||
| 93 | _all_resource_tables => 'elements', | ||||||||||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 69 | ▶ | sub _build__content_tables { return [] } | ||||||||||||||||||||||||||
|
Subroutine
_build__content_tables: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 70 | ▶ | sub _build__resource_tables { return [] } | ||||||||||||||||||||||||||
|
Subroutine
_build__resource_tables: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 483 | ▶ | sub _build__query_fields { return [] } | ||||||||||||||||||||||||||
|
Subroutine
_build__query_fields: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub _all_tables { | ||||||||||||||||||||||||||
|
Subroutine
_all_tables: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | return | ||||||||||||||||||||||||||||
| 106 | 0 | $self->_core_table, | |||||||||||||||||||||||||||
| 107 | $self->_all_content_tables, | ||||||||||||||||||||||||||||
| 108 | $self->_all_resource_tables; | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 112 | # methods | ||||||||||||||||||||||||||||
| 113 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 71 | ▶ | sub initialize { | ||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 71 | my ($self, $classes, $resources) = @_; | |||||||||||||||||||||||||||
| 117 | 71 | @$resources = uniq ( @$resources, "Metabase::Resource::metabase::user" ); | |||||||||||||||||||||||||||
| 118 | 71 | my $schema = $self->schema; | |||||||||||||||||||||||||||
| 119 | # Core table | ||||||||||||||||||||||||||||
| 120 | 71 | my $table = $self->_table_from_meta( $self->_core_table, Metabase::Fact->core_metadata_types ); | |||||||||||||||||||||||||||
| 121 | 71 | my $pk = $table->get_field('guid'); | |||||||||||||||||||||||||||
| 122 | 71 | ▶ | while ( my ($k,$v) = each %{$self->_guid_field_params} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 142 | ▶ | $pk->$k($v) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | if $pk->can($k); | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | $table->add_constraint( | ||||||||||||||||||||||||||||
| 127 | 71 | name => $self->_core_table . "_pk", | |||||||||||||||||||||||||||
| 128 | fields => ['guid'], | ||||||||||||||||||||||||||||
| 129 | type => PRIMARY_KEY, | ||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||
| 131 | 71 | $schema->add_table($table); | |||||||||||||||||||||||||||
| 132 | # Fact tables | ||||||||||||||||||||||||||||
| 133 | my @expanded = | ||||||||||||||||||||||||||||
| 134 | 0 | map { $_->fact_classes } | |||||||||||||||||||||||||||
| 135 | 71 | grep { $_->isa("Metabase::Report") } | |||||||||||||||||||||||||||
| 136 | @$classes; | ||||||||||||||||||||||||||||
| 137 | 71 | for my $c ( @$classes, @expanded ) { | |||||||||||||||||||||||||||
| 138 | 70 | ▶ | next unless try_load_class($c); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 70 | my $name = normalize_name( lc($c->type) ); | |||||||||||||||||||||||||||
| 140 | 70 | my $types = $c->content_metadata_types; | |||||||||||||||||||||||||||
| 141 | 70 | ▶ | next unless $types && keys %$types; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$types and keys %$types
MC/DC50%1/2
$types and keys %$types
$types
keys %$types
Truth table66%2/3
A and B
A= $typesB= keys %$types
| |||||||||||||||||||||||||||||
| 142 | 69 | $self->_push_content_tables($name); | |||||||||||||||||||||||||||
| 143 | 69 | my $table = $self->_table_from_meta( $name, $types ); | |||||||||||||||||||||||||||
| 144 | $table->add_field( | ||||||||||||||||||||||||||||
| 145 | name => '_guid', | ||||||||||||||||||||||||||||
| 146 | is_nullable => 0, | ||||||||||||||||||||||||||||
| 147 | 69 | %{$self->_guid_field_params} | |||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||
| 149 | 69 | $table->add_constraint( | |||||||||||||||||||||||||||
| 150 | name => "${name}_pk", | ||||||||||||||||||||||||||||
| 151 | fields => ['_guid'], | ||||||||||||||||||||||||||||
| 152 | type => PRIMARY_KEY, | ||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||
| 154 | 69 | $schema->add_table($table); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | # Resource tables | ||||||||||||||||||||||||||||
| 157 | 71 | for my $r ( @$resources ) { | |||||||||||||||||||||||||||
| 158 | 139 | ▶ | next unless try_load_class($r); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 139 | my $name = $r; | |||||||||||||||||||||||||||
| 160 | 139 | $name =~ s/^Metabase::Resource:://; | |||||||||||||||||||||||||||
| 161 | 139 | $name =~ s/::/_/g; | |||||||||||||||||||||||||||
| 162 | 139 | $name = normalize_name( lc $name ); | |||||||||||||||||||||||||||
| 163 | 139 | my $types = $r->metadata_types; | |||||||||||||||||||||||||||
| 164 | 139 | ▶ | next unless keys %$types; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 139 | $self->_push_resource_tables($name); | |||||||||||||||||||||||||||
| 166 | 139 | my $table = $self->_table_from_meta( $name, $types ); | |||||||||||||||||||||||||||
| 167 | $table->add_field( | ||||||||||||||||||||||||||||
| 168 | name => '_guid', | ||||||||||||||||||||||||||||
| 169 | is_nullable => 0, | ||||||||||||||||||||||||||||
| 170 | is_primary_key => 1, | ||||||||||||||||||||||||||||
| 171 | 139 | %{$self->_guid_field_params} | |||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||
| 173 | 139 | $table->add_constraint( | |||||||||||||||||||||||||||
| 174 | name => "${name}_pk", | ||||||||||||||||||||||||||||
| 175 | fields => ['_guid'], | ||||||||||||||||||||||||||||
| 176 | type => PRIMARY_KEY, | ||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||
| 178 | 139 | $schema->add_table($table); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 71 | $self->_deploy_schema; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 71 | return; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 279 | ▶ | sub _table_from_meta { | ||||||||||||||||||||||||||
|
Subroutine
_table_from_meta: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 187 | 279 | my ($self, $name, $typehash) = @_; | |||||||||||||||||||||||||||
| 188 | 279 | my $table = SQL::Translator::Schema::Table->new( name => $name ); | |||||||||||||||||||||||||||
| 189 | 279 | for my $k ( sort keys %$typehash ) { | |||||||||||||||||||||||||||
| 190 | # warn "Adding $k to $name\n"; | ||||||||||||||||||||||||||||
| 191 | $table->add_field( | ||||||||||||||||||||||||||||
| 192 | name => normalize_name($k), | ||||||||||||||||||||||||||||
| 193 | 1188 | ▶ | data_type => $self->typemap->{$typehash->{$k} || "//str"}, | ||||||||||||||||||||||||||
|
Condition50%1/2
$typehash->{$k} || '//str'
MC/DC0%0/1
$typehash->{$k} || '//str'
$typehash->{$k}
Truth table50%1/2
A
A= $typehash->{$k}
| |||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | 279 | return $table; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 169 | ▶ | sub _content_table { | ||||||||||||||||||||||||||
|
Subroutine
_content_table: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 200 | 169 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 201 | 169 | return normalize_name( lc $name ); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 50 | ▶ | sub _resource_table { | ||||||||||||||||||||||||||
|
Subroutine
_resource_table: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 205 | 50 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 206 | 50 | $name =~ s/^Metabase-Resource-//; | |||||||||||||||||||||||||||
| 207 | 50 | return normalize_name( lc $name ); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 482 | ▶ | sub _get_search_sql { | ||||||||||||||||||||||||||
|
Subroutine
_get_search_sql: called CC=14 SCAR=27.1
| |||||||||||||||||||||||||||||
| 211 | 482 | my ( $self, $select, $spec ) = @_; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # clear type constraints before analyzing query | ||||||||||||||||||||||||||||
| 214 | 482 | $self->_clear_requested_content_type; | |||||||||||||||||||||||||||
| 215 | 482 | $self->_clear_requested_resource_type; | |||||||||||||||||||||||||||
| 216 | 482 | $self->_clear_query_fields; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 482 | my ($where, $limit) = $self->get_native_query($spec); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 482 | my ($saw_content_field, $saw_resource_field); | |||||||||||||||||||||||||||
| 221 | 482 | for my $f ( $self->_all_query_fields ) { | |||||||||||||||||||||||||||
| 222 | 499 | ▶ | $saw_content_field++ if $f =~ qr{^content\.}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 499 | ▶ | $saw_resource_field++ if $f =~ qr{^resource\.}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 499 | ▶ | return unless $f =~ qr{^(?:core|content|resource)\.}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 465 | ▶ | if ( $saw_content_field && ! $self->_requested_content_type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$saw_content_field and not $self->_requested_content_type
MC/DC0%0/2
$saw_content_field and not $self->_requested_content_type
$saw_content_field
not $self->_requested_content_type
Truth table66%2/3
A and not(B)
A= $saw_content_fieldB= not $self->_requested_content_type
| |||||||||||||||||||||||||||||
| 228 | 0 | Carp::confess("query requested content metadata without content type constraint"); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | 465 | ▶ | if ( $saw_resource_field && ! $self->_requested_resource_type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$saw_resource_field and not $self->_requested_resource_type
MC/DC0%0/2
$saw_resource_field and not $self->_requested_resource_type
$saw_resource_field
not $self->_requested_resource_type
Truth table66%2/3
A and not(B)
A= $saw_resource_fieldB= not $self->_requested_resource_type
| |||||||||||||||||||||||||||||
| 231 | 0 | Carp::confess("query requested resource metadata without resource type constraint"); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # based on requests, conduct joins | ||||||||||||||||||||||||||||
| 235 | 465 | my @from = qq{from "core_meta" core}; | |||||||||||||||||||||||||||
| 236 | 465 | ▶ | return unless $self->_check_query_fields($self->_core_table, 'core'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 465 | ▶ | if ( my $content_type = $self->_requested_content_type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 153 | my $content_table = $self->_content_table($content_type); | |||||||||||||||||||||||||||
| 240 | 153 | ▶ | return unless $self->_check_query_fields($content_table, 'content'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 153 | push @from, qq{join "$content_table" content on core.guid = content._guid}; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 465 | ▶ | if ( my $resource_type = $self->_requested_resource_type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 34 | my $resource_table = $self->_resource_table($resource_type); | |||||||||||||||||||||||||||
| 245 | 34 | ▶ | return unless $self->_check_query_fields($resource_table, 'resource'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 34 | push @from, qq{join "$resource_table" resource on core.guid = resource._guid}; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 465 | my $sql = join(" ", $select, @from, $where); | |||||||||||||||||||||||||||
| 250 | 465 | return ($sql, $limit); | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 652 | ▶ | sub _check_query_fields { | ||||||||||||||||||||||||||
|
Subroutine
_check_query_fields: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 254 | 652 | my ($self, $table, $type) = @_; # type 'core', 'resource' or 'content' | |||||||||||||||||||||||||||
| 255 | 652 | my $table_obj = $self->schema->get_table("$table"); | |||||||||||||||||||||||||||
| 256 | 652 | for my $f ( $self->_all_query_fields ) { | |||||||||||||||||||||||||||
| 257 | 856 | ▶ | next unless $f =~ /^$type\.(.+)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 482 | my $name = $1; | |||||||||||||||||||||||||||
| 259 | 482 | ▶ | return unless $table_obj->get_field($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | 652 | return 1; | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 16 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 265 | 16 | my ( $self, $fact ) = @_; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 16 | ▶ | Carp::confess("can't index a Fact without a GUID") unless $fact->guid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 16 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 270 | 16 | $self->dbis->begin_work(); | |||||||||||||||||||||||||||
| 271 | 16 | my $core_meta = $fact->core_metadata; | |||||||||||||||||||||||||||
| 272 | 16 | $core_meta->{resource} = "$core_meta->{resource}"; #stringify obj | |||||||||||||||||||||||||||
| 273 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 274 | # warn "Adding " . Dumper $core_meta; | ||||||||||||||||||||||||||||
| 275 | 16 | $core_meta->{guid} = $self->_munge_guid($core_meta->{guid}); | |||||||||||||||||||||||||||
| 276 | 16 | $self->dbis->insert( 'core_meta', $core_meta ); | |||||||||||||||||||||||||||
| 277 | 16 | my $content_meta = $fact->content_metadata; | |||||||||||||||||||||||||||
| 278 | # not all facts have content metadata | ||||||||||||||||||||||||||||
| 279 | 16 | ▶ | if ( keys %$content_meta ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 16 | $content_meta->{_guid} = $self->_munge_guid($fact->guid); | |||||||||||||||||||||||||||
| 281 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 282 | # warn "Adding " . Dumper $content_meta; | ||||||||||||||||||||||||||||
| 283 | 16 | my $content_table = $self->_content_table( $fact->type ); | |||||||||||||||||||||||||||
| 284 | 16 | $self->dbis->insert( $content_table, $content_meta ); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | # XXX eventually, add resource metadata -- dagolden, 2011-08-24 | ||||||||||||||||||||||||||||
| 287 | 16 | my $resource_meta = $fact->resource_metadata; | |||||||||||||||||||||||||||
| 288 | # not all facts have resource metadata | ||||||||||||||||||||||||||||
| 289 | 16 | ▶ | if ( keys %$resource_meta ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 16 | $resource_meta->{_guid} = $self->_munge_guid($fact->guid); | |||||||||||||||||||||||||||
| 291 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 292 | # warn "Adding " . Dumper $resource_meta; | ||||||||||||||||||||||||||||
| 293 | 16 | my $resource_table = $self->_resource_table( $resource_meta->{type} ); | |||||||||||||||||||||||||||
| 294 | 16 | $self->dbis->insert( $resource_table, $resource_meta ); | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | 16 | $self->dbis->commit; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 299 | 0 | $self->dbis->rollback; | |||||||||||||||||||||||||||
| 300 | 0 | Carp::confess("Error inserting record: $_"); | |||||||||||||||||||||||||||
| 301 | 16 | }; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 255 | ▶ | sub count { | ||||||||||||||||||||||||||
|
Subroutine
count: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 306 | 255 | my ( $self, %spec) = @_; | |||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 255 | my ($sql, $limit) = $self->_get_search_sql("select count(*)", \%spec); | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 255 | ▶ | return 0 unless $sql; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | # warn "COUNT: $sql\n"; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 255 | my ($count) = $self->dbis->query($sql)->list; | |||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 255 | return $count; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 19 | ▶ | sub query { | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 319 | 19 | my ( $self, %spec) = @_; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 19 | my ($sql, $limit) = $self->_get_search_sql("select core.guid", \%spec); | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 19 | ▶ | return Data::Stream::Bulk::Nil->new | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | unless $sql; | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | # warn "QUERY: $sql\n"; | ||||||||||||||||||||||||||||
| 327 | 18 | my $result = $self->dbis->query($sql); | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | return Data::Stream::Bulk::Array->new( | ||||||||||||||||||||||||||||
| 330 | 18 | array => [ map { $self->_unmunge_guid( $_->[0] ) } $result->arrays ] | |||||||||||||||||||||||||||
| 331 | ); | ||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | # XXX evil hackery to allow shards to give us ordering info | ||||||||||||||||||||||||||||
| 335 | 208 | ▶ | sub _shard_query { | ||||||||||||||||||||||||||
|
Subroutine
_shard_query: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 336 | 208 | my ( $self, %spec) = @_; | |||||||||||||||||||||||||||
| 337 | 208 | my $spec = \%spec; | |||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 208 | my $select; | |||||||||||||||||||||||||||
| 340 | 208 | ▶ | if ( defined $spec->{-order} and ref $spec->{-order} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $spec->{"-order"} and ref $spec->{"-order"} eq "ARRAY"
MC/DC50%1/2
defined $spec->{"-order"} and ref $spec->{"-order"} eq "ARRAY"
defined $spec->{"-order"}
ref $spec->{"-order"} eq "ARRAY"
Truth table66%2/3
A and B
A= defined $spec->{"-order"}B= ref $spec->{"-order"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 341 | 48 | my @clauses; | |||||||||||||||||||||||||||
| 342 | 48 | my @order = @{$spec->{-order}}; | |||||||||||||||||||||||||||
| 343 | 48 | ▶ | while ( @order ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 48 | my ($dir, $field) = splice( @order, 0, 2); | |||||||||||||||||||||||||||
| 345 | 48 | $field = $self->_quote_field( $field ); | |||||||||||||||||||||||||||
| 346 | 48 | $dir =~ s/^-//; | |||||||||||||||||||||||||||
| 347 | 48 | $dir = uc $dir; | |||||||||||||||||||||||||||
| 348 | 48 | push @clauses, $field; | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | 48 | $select = "select " . join(", ", "core.guid", @clauses); | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | else { | ||||||||||||||||||||||||||||
| 353 | 160 | $select = "select core.guid"; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 208 | my ($sql, $limit) = $self->_get_search_sql($select, \%spec); | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 208 | ▶ | return Data::Stream::Bulk::Nil->new | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | unless $sql; | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | # warn "QUERY: $sql\n"; | ||||||||||||||||||||||||||||
| 362 | 192 | my $result = $self->dbis->query($sql); | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 192 | return Data::Stream::Bulk::Array->new( | |||||||||||||||||||||||||||
| 365 | array => [ $result->arrays ] | ||||||||||||||||||||||||||||
| 366 | ); | ||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 4 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 370 | 4 | my ( $self, $guid ) = @_; | |||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 4 | ▶ | Carp::confess("can't delete without a GUID") unless $guid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 4 | $guid = $self->_munge_guid($guid); | |||||||||||||||||||||||||||
| 375 | 4 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 376 | 4 | $self->dbis->begin_work(); | |||||||||||||||||||||||||||
| 377 | 4 | $self->dbis->delete( 'core_meta', { 'guid' => $guid } ); | |||||||||||||||||||||||||||
| 378 | # XXX need to track _content_tables | ||||||||||||||||||||||||||||
| 379 | 4 | for my $table ( uniq $self->_all_content_tables ) { | |||||||||||||||||||||||||||
| 380 | 4 | $self->dbis->delete( $table, { '_guid' => $guid } ); | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | 4 | for my $table ( uniq $self->_all_resource_tables ) { | |||||||||||||||||||||||||||
| 383 | 8 | $self->dbis->delete( $table, { '_guid' => $guid } ); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | # XXX eventually, add resource metadata -- dagolden, 2011-08-24 | ||||||||||||||||||||||||||||
| 386 | 4 | $self->dbis->commit; | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 389 | 0 | $self->dbis->rollback; | |||||||||||||||||||||||||||
| 390 | 0 | Carp::confess("Error deleting record: $_"); | |||||||||||||||||||||||||||
| 391 | 4 | }; | |||||||||||||||||||||||||||
| 392 | # delete | ||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 396 | # required by Metabase::Query | ||||||||||||||||||||||||||||
| 397 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 6 | requires '_quote_field'; | |||||||||||||||||||||||||||
| 400 | 6 | requires '_quote_val'; | |||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | # We need to track fields used in a query | ||||||||||||||||||||||||||||
| 403 | 566 | ▶ | before _quote_field => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 404 | 566 | my ($self, $field) = @_; | |||||||||||||||||||||||||||
| 405 | 566 | $self->_push_query_fields($field); | |||||||||||||||||||||||||||
| 406 | 6 | }; | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | # We need to track type constraints to determine which tables to join | ||||||||||||||||||||||||||||
| 409 | 385 | ▶ | before op_eq => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 410 | 385 | my ($self, $field, $value) = @_; | |||||||||||||||||||||||||||
| 411 | 385 | ▶ | if ($field eq 'core.type') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 412 | 153 | $self->_requested_content_type( $value ); | |||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | 385 | ▶ | if ($field eq 'resource.type') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 34 | $self->_requested_resource_type( $value ); | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | 6 | }; | |||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 496 | ▶ | sub translate_query { | ||||||||||||||||||||||||||
|
Subroutine
translate_query: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 420 | 496 | my ( $self, $spec ) = @_; | |||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 496 | my (@parts, $limit); | |||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | # where | ||||||||||||||||||||||||||||
| 425 | 496 | ▶ | if ( defined $spec->{-where} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 309 | push @parts, "where " . $self->dispatch_query_op( $spec->{-where} ); | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | # order | ||||||||||||||||||||||||||||
| 430 | 496 | ▶ | if ( defined $spec->{-order} and ref $spec->{-order} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $spec->{"-order"} and ref $spec->{"-order"} eq "ARRAY"
MC/DC50%1/2
defined $spec->{"-order"} and ref $spec->{"-order"} eq "ARRAY"
defined $spec->{"-order"}
ref $spec->{"-order"} eq "ARRAY"
Truth table66%2/3
A and B
A= defined $spec->{"-order"}B= ref $spec->{"-order"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 431 | 53 | my @clauses; | |||||||||||||||||||||||||||
| 432 | 53 | my @order = @{$spec->{-order}}; | |||||||||||||||||||||||||||
| 433 | 53 | ▶ | while ( @order ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | 53 | my ($dir, $field) = splice( @order, 0, 2); | |||||||||||||||||||||||||||
| 435 | 53 | $field = $self->_quote_field( $field ); | |||||||||||||||||||||||||||
| 436 | 53 | $dir =~ s/^-//; | |||||||||||||||||||||||||||
| 437 | 53 | $dir = uc $dir; | |||||||||||||||||||||||||||
| 438 | 53 | push @clauses, "$field $dir"; | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | 53 | push @parts, qq{order by } . join(", ", @clauses); | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | # limit | ||||||||||||||||||||||||||||
| 444 | 496 | ▶ | if ( $limit = $spec->{-limit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 18 | push @parts, qq{limit $limit}; | |||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 496 | return join( q{ }, @parts ), $limit; | |||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 464 | ▶ | around [qw/op_eq op_ne op_gt op_lt op_ge op_le op_like/ ] => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 452 | 464 | my $orig = shift; | |||||||||||||||||||||||||||
| 453 | 464 | my $self = shift; | |||||||||||||||||||||||||||
| 454 | 464 | my ($field, $val) = @_; | |||||||||||||||||||||||||||
| 455 | 464 | ▶ | if ( $field eq "core.guid" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | # warn "*** Fixing $field ($val)"; | ||||||||||||||||||||||||||||
| 457 | 142 | $val = $self->_munge_guid($val); | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | 464 | return $self->$orig($field, $val); | |||||||||||||||||||||||||||
| 460 | 6 | }; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 1 | ▶ | around [qw/op_between/ ] => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 463 | 1 | my $orig = shift; | |||||||||||||||||||||||||||
| 464 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 465 | 1 | my ($field, $low, $high) = @_; | |||||||||||||||||||||||||||
| 466 | 1 | ▶ | if ( $field eq "core.guid" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | $low = $self->_munge_guid($low); | |||||||||||||||||||||||||||
| 468 | 0 | $high = $self->_munge_guid($high); | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | 1 | return $self->$orig($field, $low, $high); | |||||||||||||||||||||||||||
| 471 | 6 | }; | |||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 385 | ▶ | sub op_eq { | ||||||||||||||||||||||||||
|
Subroutine
op_eq: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 474 | 385 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 475 | 385 | return $self->_quote_field($field) . " = " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 52 | ▶ | sub op_ne { | ||||||||||||||||||||||||||
|
Subroutine
op_ne: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 479 | 52 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 480 | 52 | return $self->_quote_field($field) . " != " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 21 | ▶ | sub op_gt { | ||||||||||||||||||||||||||
|
Subroutine
op_gt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 484 | 21 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 485 | 21 | return $self->_quote_field($field) . " > " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 3 | ▶ | sub op_lt { | ||||||||||||||||||||||||||
|
Subroutine
op_lt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 489 | 3 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 490 | 3 | return $self->_quote_field($field) . " < " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 1 | ▶ | sub op_ge { | ||||||||||||||||||||||||||
|
Subroutine
op_ge: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 494 | 1 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 495 | 1 | return $self->_quote_field($field) . " >= " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 1 | ▶ | sub op_le { | ||||||||||||||||||||||||||
|
Subroutine
op_le: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 499 | 1 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 500 | 1 | return $self->_quote_field($field) . " <= " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 1 | ▶ | sub op_between { | ||||||||||||||||||||||||||
|
Subroutine
op_between: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 504 | 1 | my ($self, $field, $low, $high) = @_; | |||||||||||||||||||||||||||
| 505 | 1 | return $self->_quote_field($field) . " between " | |||||||||||||||||||||||||||
| 506 | . $self->_quote_val($low) . " and " . $self->_quote_val($high); | ||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 1 | ▶ | sub op_like { | ||||||||||||||||||||||||||
|
Subroutine
op_like: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 510 | 1 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||
| 511 | # XXX really should quote/check $val | ||||||||||||||||||||||||||||
| 512 | 1 | return $self->_quote_field($field) . " like " . $self->_quote_val($val); | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 1 | ▶ | sub op_not { | ||||||||||||||||||||||||||
|
Subroutine
op_not: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 516 | 1 | my ($self, $pred) = @_; | |||||||||||||||||||||||||||
| 517 | 1 | my $clause = $self->dispatch_query_op($pred); | |||||||||||||||||||||||||||
| 518 | 1 | return "NOT ($clause)"; | |||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 1 | ▶ | sub op_or { | ||||||||||||||||||||||||||
|
Subroutine
op_or: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 522 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 523 | 1 | my @predicates = map { $self->dispatch_query_op($_) } @args; | |||||||||||||||||||||||||||
| 524 | 1 | return join(" or ", map { "($_)" } @predicates); | |||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | 155 | ▶ | sub op_and { | ||||||||||||||||||||||||||
|
Subroutine
op_and: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 528 | 155 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 529 | 155 | my @predicates = map { $self->dispatch_query_op($_) } @args; | |||||||||||||||||||||||||||
| 530 | 155 | return join(" and ", map { "($_)" } @predicates); | |||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | 6 | 1; | |||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | __END__ | ||||||||||||||||||||||||||||