| 1 | package DBIO::PostgreSQL::JSONB::Op; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: JSONB path-extraction operator object built by jsonb() | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 21 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 21 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | DBIO::Exception->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 'jsonb: the column is a plain identifier (letters, digits, underscores and dots)' | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 21 | ▶ | ) unless defined $args{col} && !ref $args{col} && $args{col} =~ /\A[\w.]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $args{"col"} and not ref $args{"col"} and $args{"col"} =~ /\A[\w.]+\z/
defined $args{"col"} and not ref $args{"col"}
MC/DC66%2/3
defined $args{"col"} and not ref $args{"col"} and $args{"col"} =~ /\A[\w.]+\z/
defined $args{"col"}
not ref $args{"col"}
$args{"col"} =~ /\A[\w.]+\z/
Truth table75%3/4
A and not(B) and C
A= defined $args{"col"}B= not ref $args{"col"}C= $args{"col"} =~ /\A[\w.]+\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # Returns the SQL text-extraction expression -- (col->>?) or (col#>>?::text[]) | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # -- and the one bind it carries: the path element, or the path as the text | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # of a text[] literal. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 16 | ▶ | sub _text_sql { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text_sql: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | my $col = $self->{col}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 16 | my @path = @{ $self->{path} }; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 16 | ▶ | Carp::croak('jsonb() requires at least one path element') unless @path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 16 | ▶ | return ( sprintf( '(%s->>?)', $col ), $path[0] ) if @path == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | my $array = '{' . join( ',', map { ( my $k = $_ ) =~ s/([\\"])/\\$1/g; "\"$k\"" } @path ) . '}'; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | return ( sprintf( '(%s#>>?::text[])', $col ), $array ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 11 | ▶ | sub _op { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_op: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | my ( $self, $op, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | my ( $sql, @bind ) = $self->_text_sql; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | return \[ sprintf( '%s %s ?', $sql, $op ), @bind, $val ]; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | sub eq { $_[0]->_op( '=', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eq: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub ne { $_[0]->_op( '!=', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ne: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub lt { $_[0]->_op( '<', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub le { $_[0]->_op( '<=', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
le: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub gt { $_[0]->_op( '>', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub ge { $_[0]->_op( '>=', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ge: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub like { $_[0]->_op( 'LIKE', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
like: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub ilike { $_[0]->_op( 'ILIKE', $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ilike: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub is_null { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_null: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my ( $sql, @bind ) = $self->_text_sql; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | return \[ "$sql IS NULL", @bind ]; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub is_not_null { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_not_null: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my ( $sql, @bind ) = $self->_text_sql; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | return \[ "$sql IS NOT NULL", @bind ]; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub as_order { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | my ( $sql, @bind ) = $self->_text_sql; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | return \[ $sql, @bind ]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||||||||||||||||