blib/lib/DBIx/QuickORM/WhereBuilder/RawSQL.pm

filter: Statementstmt 71.4% 25 / 35 Branchbran 50.0% 8 / 16 Conditioncond 44.4% 8 / 18 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 75.0% 6 / 8 Podpod 100% 4 / 4 totaltotal 60.4% 55 / 91 CC 15 SCAR 20.1
CC
15
Cov
59%
can_build_where
11.3
can_build_where
11.3
build_where
4.1
CRAP 7.5
« blib/lib/DBIx/QuickORM/LookupTable.pm ↑ Summary blib/lib/DBIx/QuickORM/WhereBuilder/Simple.pm »
1 package DBIx::QuickORM::WhereBuilder::RawSQL;
2 261 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 261 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 261 our $VERSION = '0.000033';
6  
7 261 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 261 ▶use Role::Tiny::With qw/with/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 261 with 'DBIx::QuickORM::Role::WhereBuilder';
11  
12 =pod
13  
14 =encoding UTF-8
15  
16 =head1 NAME
17  
18 DBIx::QuickORM::WhereBuilder::RawSQL - A where that is SQL already.
19  
20 =head1 DESCRIPTION
21  
22 Takes a C<where> that is a plain string, used as SQL with no binds, or a
23 single C<sql()> marker (L<DBIx::QuickORM::Value>), used with its binds. It
24 declines everything else.
25  
26 =head1 SYNOPSIS
27  
28 It is in the ORM's default chain, so a handle's C<where> reaches it:
29  
30 use DBIx::QuickORM::Value qw/sql/;
31  
32 # SELECT ... FROM "users" WHERE ( id > ? )
33 my @rows = $orm->handle('users')
34 ->where(sql('id > ?', 10))
35 ->all;
36  
37 # A plain string is SQL with no binds. Pass values through sql() as above,
38 # and never put untrusted input in a string like this one.
39 my @named = $orm->handle('users')
40 ->where("name LIKE 'B%'")
41 ->all;
42  
43 =head1 PUBLIC METHODS
44  
45 =over 4
46  
47 =item $bool = DBIx::QuickORM::WhereBuilder::RawSQL->can_build_where($where)
48  
49 =item ($sql, \@binds) = DBIx::QuickORM::WhereBuilder::RawSQL->build_where($where, $source, $dialect)
50  
51 As L<DBIx::QuickORM::Role::WhereBuilder> describes. The SQL is wrapped in
52 parentheses, and an C<sql> marker's binds are tied to no field.
53  
54 use DBIx::QuickORM::Value qw/sql/;
55  
56 my $raw = 'DBIx::QuickORM::WhereBuilder::RawSQL';
57  
58 my $yes = $raw->can_build_where(sql('id > ?', 10)); # 1
59 my $no = $raw->can_build_where({name => 'Bob'}); # 0
60  
61 my ($sql, $binds) = $raw->build_where(
62 sql('id > ?', 10),
63 $orm->handle('users')->source,
64 $orm->connection->dialect,
65 );
66 # $sql: ( id > ? )
67 # $binds: [[undef, 10]]
68  
69 An empty string is no condition: C<('', [])>.
70  
71 =back
72  
73 =cut
74  
75 259 ▶sub can_build_where {
Subroutine can_build_where: called CC=6 SCAR=24.3
Pod documented
76 0 ▶ my $class = shift;
Subroutine can_build_where: not called CC=6 SCAR=24.3
Pod documented
77 0 my ($where) = @_;
78 0 ▶ return 1 if defined($where) && !ref($where);
Branch: 2 branches
BranchTrueFalseTotal
if defined $where and not ref $where 5 254 259
if defined $where and not ref $where 0 0 0
Condition50%3/6
defined $where and not ref $where
!ll&&!rl&&r
12535
defined $where and not ref $where
!ll&&!rl&&r
000
MC/DC100%2/2
defined $where and not ref $where
defined $where not ref $where
MC/DC0%0/2
defined $where and not ref $where
defined $where not ref $where
Truth table100%3/3
A and not(B)
A= defined $whereB= not ref $where
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $whereB= not ref $where
ABresult
0X0
100
111
79 0 ▶ return blessed($where) && $where->isa('DBIx::QuickORM::Value') && $where->kind eq 'sql' ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($where) && $where->isa('DBIx::QuickORM::Value') && $where->kind eq 'sql' ? : 1 253 254
builtin::blessed($where) && $where->isa('DBIx::QuickORM::Value') && $where->kind eq 'sql' ? : 0 0 0
Condition41%5/12
builtin::blessed($where) and $where->isa("DBIx::QuickORM::Value") and $where->kind eq "sql"
!ll&&!rl&&r
25211
builtin::blessed($where) and $where->isa("DBIx::QuickORM::Value")
!ll&&!rl&&r
25202
builtin::blessed($where) and $where->isa("DBIx::QuickORM::Value") and $where->kind eq "sql"
!ll&&!rl&&r
000
builtin::blessed($where) and $where->isa("DBIx::QuickORM::Value")
!ll&&!rl&&r
000
MC/DC66%2/3
builtin::blessed($where) and $where->isa("DBIx::QuickORM::Value") and $where->kind eq "sql"
builtin::blessed($where) $where->isa("DBIx::QuickORM::Value") $where->kind eq "sql"
MC/DC0%0/3
builtin::blessed($where) and $where->isa("DBIx::QuickORM::Value") and $where->kind eq "sql"
builtin::blessed($where) $where->isa("DBIx::QuickORM::Value") $where->kind eq "sql"
Truth table75%3/4
A and B and C
A= builtin::blessed($where)B= $where->isa("DBIx::QuickORM::Value")C= $where->kind eq "sql"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= builtin::blessed($where)B= $where->isa("DBIx::QuickORM::Value")C= $where->kind eq "sql"
ABCresult
0XX0
10X0
1100
1111
80 }
81  
82 6 ▶sub build_where {
Subroutine build_where: called CC=3 SCAR=14.2
Pod documented
83 0 ▶ my $class = shift;
Subroutine build_where: not called CC=3 SCAR=14.2
Pod documented
84 0 my ($where) = @_;
85 0 ▶ my ($sql, @binds) = ref($where) ? ($where->value, map { [undef, $_] } @{$where->binds}) : ($where);
Branch: 2 branches
BranchTrueFalseTotal
ref $where ? : 1 5 6
ref $where ? : 0 0 0
86 0 ▶ return length($sql) ? ("( $sql )", \@binds) : ('', []);
Branch: 2 branches
BranchTrueFalseTotal
length $sql ? : 5 1 6
length $sql ? : 0 0 0
87 }
88  
89 261 1;
90  
91 __END__
« blib/lib/DBIx/QuickORM/LookupTable.pm ↑ Summary blib/lib/DBIx/QuickORM/WhereBuilder/Simple.pm »