| 1 | package SQL::Wizard::Expr; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use SQL::Wizard::Expr::Alias; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use SQL::Wizard::Expr::Order; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use SQL::Wizard::Expr::Window; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use SQL::Wizard::Expr::BinaryOp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use SQL::Wizard::Expr::Value; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | use overload | ||||||||||||||||||||||||||||
| 14 | 3 | ▶ | '+' => sub { _binop('+', @_) }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | '-' => sub { _binop('-', @_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | '*' => sub { _binop('*', @_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | '/' => sub { _binop('/', @_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | '%' => sub { _binop('%', @_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | '""' => sub { croak "Cannot stringify SQL::Wizard::Expr directly; use ->to_sql" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | 28 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 14 | fallback => 1; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 410 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 410 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 25 | 410 | bless \%args, $class; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 177 | ▶ | sub to_sql { | ||||||||||||||||||||||||||
|
Subroutine
to_sql: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 177 | my ($self, $renderer) = @_; | |||||||||||||||||||||||||||
| 30 | 177 | ▶ | $renderer ||= $self->{_renderer}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$renderer ||= $self->{"_renderer"}
MC/DC0%0/2
$renderer ||= $self->{"_renderer"}
$renderer
$self->{"_renderer"}
Truth table33%1/3
A ||= B
A= $rendererB= $self->{"_renderer"}
| |||||||||||||||||||||||||||||
| 31 | 177 | ▶ | croak "No renderer available" unless $renderer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 177 | $renderer->render($self); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 28 | ▶ | sub as { | ||||||||||||||||||||||||||
|
Subroutine
as: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 28 | my ($self, $alias) = @_; | |||||||||||||||||||||||||||
| 37 | 28 | $self->{_renderer}->_assert_column($alias); | |||||||||||||||||||||||||||
| 38 | SQL::Wizard::Expr::Alias->new( | ||||||||||||||||||||||||||||
| 39 | expr => $self, | ||||||||||||||||||||||||||||
| 40 | alias => $alias, | ||||||||||||||||||||||||||||
| 41 | _renderer => $self->{_renderer}, | ||||||||||||||||||||||||||||
| 42 | 28 | ); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub asc { | ||||||||||||||||||||||||||
|
Subroutine
asc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 47 | SQL::Wizard::Expr::Order->new( | ||||||||||||||||||||||||||||
| 48 | expr => $self, | ||||||||||||||||||||||||||||
| 49 | direction => 'ASC', | ||||||||||||||||||||||||||||
| 50 | _renderer => $self->{_renderer}, | ||||||||||||||||||||||||||||
| 51 | 2 | ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub desc { | ||||||||||||||||||||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 56 | SQL::Wizard::Expr::Order->new( | ||||||||||||||||||||||||||||
| 57 | expr => $self, | ||||||||||||||||||||||||||||
| 58 | direction => 'DESC', | ||||||||||||||||||||||||||||
| 59 | _renderer => $self->{_renderer}, | ||||||||||||||||||||||||||||
| 60 | 2 | ); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub asc_nulls_first { | ||||||||||||||||||||||||||
|
Subroutine
asc_nulls_first: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 65 | SQL::Wizard::Expr::Order->new( | ||||||||||||||||||||||||||||
| 66 | expr => $self, | ||||||||||||||||||||||||||||
| 67 | direction => 'ASC', | ||||||||||||||||||||||||||||
| 68 | nulls => 'FIRST', | ||||||||||||||||||||||||||||
| 69 | _renderer => $self->{_renderer}, | ||||||||||||||||||||||||||||
| 70 | 1 | ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub desc_nulls_last { | ||||||||||||||||||||||||||
|
Subroutine
desc_nulls_last: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 75 | SQL::Wizard::Expr::Order->new( | ||||||||||||||||||||||||||||
| 76 | expr => $self, | ||||||||||||||||||||||||||||
| 77 | direction => 'DESC', | ||||||||||||||||||||||||||||
| 78 | nulls => 'LAST', | ||||||||||||||||||||||||||||
| 79 | _renderer => $self->{_renderer}, | ||||||||||||||||||||||||||||
| 80 | 1 | ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 9 | ▶ | sub over { | ||||||||||||||||||||||||||
|
Subroutine
over: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 9 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 85 | # over('window_name') or over(-partition_by => ..., -order_by => ...) | ||||||||||||||||||||||||||||
| 86 | 9 | my $spec; | |||||||||||||||||||||||||||
| 87 | 9 | ▶ | if (@args == 1 && !ref $args[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args == 1 and not ref $args[0]
MC/DC50%1/2
@args == 1 and not ref $args[0]
@args == 1
not ref $args[0]
Truth table66%2/3
A and not(B)
A= @args == 1B= not ref $args[0]
| |||||||||||||||||||||||||||||
| 88 | 4 | $spec = { name => $args[0] }; | |||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||
| 90 | 5 | my %opts = @args; | |||||||||||||||||||||||||||
| 91 | 5 | $spec = \%opts; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | SQL::Wizard::Expr::Window->new( | ||||||||||||||||||||||||||||
| 94 | expr => $self, | ||||||||||||||||||||||||||||
| 95 | spec => $spec, | ||||||||||||||||||||||||||||
| 96 | _renderer => $self->{_renderer}, | ||||||||||||||||||||||||||||
| 97 | 9 | ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 13 | ▶ | sub _binop { | ||||||||||||||||||||||||||
|
Subroutine
_binop: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 101 | 13 | my ($op, $left, $right, $swap) = @_; | |||||||||||||||||||||||||||
| 102 | # Coerce plain values to Value nodes | ||||||||||||||||||||||||||||
| 103 | 13 | $right = _coerce($right, $left); | |||||||||||||||||||||||||||
| 104 | 13 | ▶ | ($left, $right) = ($right, $left) if $swap; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | SQL::Wizard::Expr::BinaryOp->new( | ||||||||||||||||||||||||||||
| 106 | op => $op, | ||||||||||||||||||||||||||||
| 107 | left => $left, | ||||||||||||||||||||||||||||
| 108 | right => $right, | ||||||||||||||||||||||||||||
| 109 | _renderer => $left->{_renderer}, | ||||||||||||||||||||||||||||
| 110 | 13 | ); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 13 | ▶ | sub _coerce { | ||||||||||||||||||||||||||
|
Subroutine
_coerce: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 114 | 13 | my ($thing, $ref_expr) = @_; | |||||||||||||||||||||||||||
| 115 | 13 | ▶ | return $thing if blessed($thing) && $thing->isa('SQL::Wizard::Expr'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($thing) and $thing->isa("SQL::Wizard::Expr")
MC/DC50%1/2
builtin::blessed($thing) and $thing->isa("SQL::Wizard::Expr")
builtin::blessed($thing)
$thing->isa("SQL::Wizard::Expr")
Truth table66%2/3
A and B
A= builtin::blessed($thing)B= $thing->isa("SQL::Wizard::Expr")
| |||||||||||||||||||||||||||||
| 116 | SQL::Wizard::Expr::Value->new( | ||||||||||||||||||||||||||||
| 117 | value => $thing, | ||||||||||||||||||||||||||||
| 118 | _renderer => $ref_expr->{_renderer}, | ||||||||||||||||||||||||||||
| 119 | 3 | ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 14 | 1; | |||||||||||||||||||||||||||