| 1 | package EntityModel::Query::Field; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 39 | $EntityModel::Query::Field::VERSION = '0.102'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | 39 | ▶ | use EntityModel::Class { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 39 | '_isa' => [qw(EntityModel::Query::Base)], | |||||||||||||||||||||||||||
| 7 | 'field' => 'EntityModel::Field', | ||||||||||||||||||||||||||||
| 8 | 'name' => 'string', | ||||||||||||||||||||||||||||
| 9 | 'sql' => 'string', | ||||||||||||||||||||||||||||
| 10 | 'alias' => 'string', | ||||||||||||||||||||||||||||
| 11 | 39 | }; | |||||||||||||||||||||||||||
| 12 | 39 | ▶ | no if $] >= 5.017011, warnings => "experimental::smartmatch"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | EntityModel::Query::Field - field wrapper | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 VERSION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | version 0.102 | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | See L<Entitymodel::Query>. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | See L<Entitymodel::Query>. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 METHODS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head2 new | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 17 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 17 | my $class = shift; | |||||||||||||||||||||||||||
| 42 | 17 | my $self = bless { }, $class; | |||||||||||||||||||||||||||
| 43 | 17 | ▶ | if(ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 44 | 4 | my $spec = shift; | |||||||||||||||||||||||||||
| 45 | 4 | my ($k, $v) = %$spec; | |||||||||||||||||||||||||||
| 46 | 4 | $self->alias($k); | |||||||||||||||||||||||||||
| 47 | 4 | ▶ | if(ref $v) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 4 | $self->sql($$v); | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 0 | $self->name($v); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # foreach (qw{name field value alias}) { | ||||||||||||||||||||||||||||
| 54 | # $self->$_($spec->{$_}) if exists $spec->{$_}; | ||||||||||||||||||||||||||||
| 55 | # } | ||||||||||||||||||||||||||||
| 56 | ▶ | } elsif(ref($_[0]) && $_[0]->isa('EntityModel::Field')) { | |||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] and $_[0]->isa("EntityModel::Field")
MC/DC0%0/2
ref $_[0] and $_[0]->isa("EntityModel::Field")
ref $_[0]
$_[0]->isa("EntityModel::Field")
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->isa("EntityModel::Field")
| |||||||||||||||||||||||||||||
| 57 | 0 | my $spec = shift; | |||||||||||||||||||||||||||
| 58 | 0 | $self->field($spec); | |||||||||||||||||||||||||||
| 59 | # Handle plain value | ||||||||||||||||||||||||||||
| 60 | ▶ | } elsif(@_ == 1 && !ref $_[0]) { | |||||||||||||||||||||||||||
|
Condition33%1/3
@_ == 1 and not ref $_[0]
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1
not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||
| 61 | 13 | my $v = shift; | |||||||||||||||||||||||||||
| 62 | 13 | $self->name($v); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 17 | return $self; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head2 quotedValue | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub quotedValue { | ||||||||||||||||||||||||||
|
Subroutine
quotedValue: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | 0 | my $v = $self->value; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 'null' unless defined $v && $v ne 'undef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $v and $v ne "undef"
MC/DC0%0/2
defined $v and $v ne "undef"
defined $v
$v ne "undef"
Truth table0%0/3
A and B
A= defined $vB= $v ne "undef"
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return $v if $self->field && $self->field->type ~~ [qw/int bigint serial bigserial numeric/]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->field and $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
MC/DC0%0/2
$self->field and $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
$self->field
$self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
Truth table0%0/3
A and B
A= $self->fieldB= $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
| |||||||||||||||||||||||||||||
| 77 | 0 | $v =~ s/'/''/g; | |||||||||||||||||||||||||||
| 78 | 0 | $v =~ s!\\!\\\\!g; | |||||||||||||||||||||||||||
| 79 | 0 | return "E'$v'"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head2 asString | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 34 | ▶ | sub asString { | ||||||||||||||||||||||||||
|
Subroutine
asString: called CC=5 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 34 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 34 | my $alias; | |||||||||||||||||||||||||||
| 89 | 34 | ▶ | return $self->sql if exists $self->{sql}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 26 | ▶ | return $self->name if exists $self->{name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | return $self->field->name; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | $alias = $self->table->name if $self->table; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return ($alias ? ($alias . '.') : '') . $self->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 39 | 1; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||