Wizard/Expr.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 80.0% 8 / 10 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 96.3% 26 / 27 Podpod 0.0% 0 / 8 totaltotal 84.5% 109 / 129 CC 9 SCAR 5.2
CC
9
Cov
92%
to_sql
3.3
_coerce
3.0
over
3.0
CRAP 1.7
« Wizard.pm ↑ Summary Wizard/Expr/Compound.pm »
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 __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 57 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 14 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 sub new {
24 410 ▶ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
25 410 bless \%args, $class;
26 }
27  
28 sub to_sql {
29 177 ▶ my ($self, $renderer) = @_;
Subroutine to_sql: called CC=3 SCAR=12.0
Pod undocumented
30 177 ▶ $renderer ||= $self->{_renderer};
Condition33%1/3
$renderer ||= $self->{"_renderer"}
l!l&&r!l&&!r
01770
MC/DC0%0/2
$renderer ||= $self->{"_renderer"}
$renderer $self->{"_renderer"}
Truth table33%1/3
A ||= B
A= $rendererB= $self->{"_renderer"}
ABresult
1X1
011
000
31 177 ▶ croak "No renderer available" unless $renderer;
Branch: 1 branch
BranchTrueFalseTotal
unless $renderer 0 177 177
32 177 $renderer->render($self);
33 }
34  
35 sub as {
36 28 ▶ my ($self, $alias) = @_;
Subroutine as: called CC=2 SCAR=7.1
Pod undocumented
37 28 ▶ croak "alias must be a word (\\w+), got '$alias'" unless $alias =~ /^\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $alias =~ /^\w+$/ 0 28 28
38 SQL::Wizard::Expr::Alias->new(
39 expr => $self,
40 alias => $alias,
41 _renderer => $self->{_renderer},
42 28 );
43 }
44  
45 sub asc {
46 2 ▶ my ($self) = @_;
Subroutine asc: called CC=1 SCAR=0.0
Pod undocumented
47 SQL::Wizard::Expr::Order->new(
48 expr => $self,
49 direction => 'ASC',
50 _renderer => $self->{_renderer},
51 2 );
52 }
53  
54 sub desc {
55 2 ▶ my ($self) = @_;
Subroutine desc: called CC=1 SCAR=0.0
Pod undocumented
56 SQL::Wizard::Expr::Order->new(
57 expr => $self,
58 direction => 'DESC',
59 _renderer => $self->{_renderer},
60 2 );
61 }
62  
63 sub asc_nulls_first {
64 1 ▶ my ($self) = @_;
Subroutine asc_nulls_first: called CC=1 SCAR=0.0
Pod undocumented
65 SQL::Wizard::Expr::Order->new(
66 expr => $self,
67 direction => 'ASC',
68 nulls => 'FIRST',
69 _renderer => $self->{_renderer},
70 1 );
71 }
72  
73 sub desc_nulls_last {
74 1 ▶ my ($self) = @_;
Subroutine desc_nulls_last: called CC=1 SCAR=0.0
Pod undocumented
75 SQL::Wizard::Expr::Order->new(
76 expr => $self,
77 direction => 'DESC',
78 nulls => 'LAST',
79 _renderer => $self->{_renderer},
80 1 );
81 }
82  
83 sub over {
84 9 ▶ my ($self, @args) = @_;
Subroutine over: called CC=3 SCAR=11.0
Pod undocumented
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
BranchTrueFalseTotal
if (@args == 1 and not ref $args[0]) { } 4 5 9
Condition66%2/3
@args == 1 and not ref $args[0]
!ll&&!rl&&r
504
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]
ABresult
0X0
100
111
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 sub _binop {
101 13 ▶ my ($op, $left, $right, $swap) = @_;
Subroutine _binop: called CC=2 SCAR=6.9
102 # Coerce plain values to Value nodes
103 13 $right = _coerce($right, $left);
104 13 ▶ ($left, $right) = ($right, $left) if $swap;
Branch: 1 branch
BranchTrueFalseTotal
if $swap 1 12 13
105 SQL::Wizard::Expr::BinaryOp->new(
106 op => $op,
107 left => $left,
108 right => $right,
109 _renderer => $left->{_renderer},
110 13 );
111 }
112  
113 sub _coerce {
114 13 ▶ my ($thing, $ref_expr) = @_;
Subroutine _coerce: called CC=3 SCAR=11.0
115 13 ▶ return $thing if blessed($thing) && $thing->isa('SQL::Wizard::Expr');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($thing) and $thing->isa("SQL::Wizard::Expr") 10 3 13
Condition66%2/3
builtin::blessed($thing) and $thing->isa("SQL::Wizard::Expr")
!ll&&!rl&&r
3010
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")
ABresult
0X0
100
111
116 SQL::Wizard::Expr::Value->new(
117 value => $thing,
118 _renderer => $ref_expr->{_renderer},
119 3 );
120 }
121  
122 14 1;
« Wizard.pm ↑ Summary Wizard/Expr/Compound.pm »