blib/lib/SQL/Abstract/Plugin/ExtraClausesFixed.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 66.6% 12 / 18 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 79.2% 61 / 77 CC 13 SCAR 16.0
CC
13
Cov
82%
_expand_join
7.9
_render_setop
5.2
_expand_select
3.0
CRAP 5.0
↑ Summary blib/lib/SQL/Abstract/Plugin/WindowFunctions.pm »
1 package SQL::Abstract::Plugin::ExtraClausesFixed;
2 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use experimental qw/signatures postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 # TODO - get this upstreamed - `using` is borken RN b/c
5  
6 5 our $VERSION = '0.01_3';
7 5 extends 'SQL::Abstract::Plugin::ExtraClauses';
8  
9 ▶has no_setop_parens => (
Subroutine _build_no_setop_parens: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
10 is => 'lazy',
11 builder => sub ($self) {
12 1 my $details = $self->sqla->_connection_info;
13 1 return $details->{SQL_DBMS_NAME} eq 'SQLite';
14 }
15 5 );
16  
17 # NOTE - upstream impl fails to put `group_by` and `having` before the setops; that's
18 # fixed here
19 sub _expand_select {
20 41 ▶ my ($self, $orig, $before_setop, @args) = @_;
Subroutine _expand_select: called CC=3 SCAR=11.0
21 41 my $exp = $self->sqla->$orig(@args);
22 41 ▶ return $exp unless my $setop = (my $sel = $exp->{-select})->{setop};
Branch: 1 branch
BranchTrueFalseTotal
unless my $setop = +(my $sel = $exp->{"-select"})->{"setop"} 40 1 41
23 1 ▶ if (my @keys = grep $sel->{$_}, @$before_setop, qw/group_by having/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@keys) = grep($sel->{$_}, @$before_setop, ("group_by", "having"))) 1 0 1
24 1 my %inner;
25 1 @inner{@keys} = delete @{$sel}{@keys};
26 1 unshift @{ (values(%$setop))[0]{queries} }, { -select => \%inner };
27 }
28 1 return $exp;
29 }
30  
31 sub _render_setop {
32 1 ▶ my ($self, $setop, $args) = @_;
Subroutine _render_setop: called CC=5 SCAR=16.5
33 1 ▶ if ($self->no_setop_parens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->no_setop_parens) 1 0 1
34 1 for my $q (@{ $args->{queries} }) {
35 2 ▶ if ($q->{-literal}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($q->{"-literal"}) 1 1 2
36 1 $q->{-literal}[0] =~ s/^\(|\)$//g;
37 }
38 }
39 }
40 $self->join_query_parts(
41 { -keyword => ' ' . join('_', $setop, ($args->{type} || ())) . ' ' },
42 map $self->render_aqt($_, $self->no_setop_parens),
43 1 ▶ @{ $args->{queries} }
Condition33%1/3
$args->{'type'} || ()
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'type'} || ()
$args->{'type'} ()
Truth table33%1/3
A || B
A= $args->{'type'}B= ()
ABresult
1X1
011
000
44 );
45 }
46  
47 # NOTE - upstream accidentally double expands `using`, so we need to replace that here
48 sub _expand_join {
49 3 ▶ my ($self, undef, $args) = @_;
Subroutine _expand_join: called CC=7 SCAR=20.6
50 3 ▶ my %proto = (
Branch: 1 branch
BranchTrueFalseTotal
ref $args eq 'HASH' ? : 0 3 3
51 ref($args) eq 'HASH'
52 ? %$args
53 : (to => @$args)
54 );
55 3 ▶ if (my $as = delete $proto{as}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $as = delete $proto{"as"}) 0 3 3
56 0 $proto{to} = $self->expand_expr({ -as => [ { -from_list => $proto{to} }, $as ] });
57 }
58 3 my $using;
59 3 ▶ if (defined($proto{using}) and ref(my $using = $proto{using}) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proto{"using"} and ref(my $using = $proto{"using"}) ne "HASH") 1 2 3
Condition66%2/3
defined $proto{"using"} and ref(my $using = $proto{"using"}) ne "HASH"
!ll&&!rl&&r
201
MC/DC50%1/2
defined $proto{"using"} and ref(my $using = $proto{"using"}) ne "HASH"
defined $proto{"using"} ref(my $using = $proto{"using"}) ne "HASH"
Truth table66%2/3
A and B
A= defined $proto{"using"}B= ref(my $using = $proto{"using"}) ne "HASH"
ABresult
0X0
100
111
60 1 ▶ $using = [ map [ $self->expand_expr($_, -ident) ], ref($using) eq 'ARRAY' ? @$using : $using ];
Branch: 1 branch
BranchTrueFalseTotal
ref $using eq 'ARRAY' ? : 0 1 1
61 }
62 my %ret = (
63 type => delete $proto{type},
64 3 ▶ to => $self->expand_expr({ -from_list => delete $proto{to} }, -ident),
Branch: 1 branch
BranchTrueFalseTotal
$using ? : 0 3 3
65 $using ? (using => $using) : (),
66 );
67 3 %ret = (%ret, map +($_ => $self->expand_expr($proto{$_}, -ident)), sort keys %proto);
68 3 return +{ -join => \%ret };
69 }
70  
71 5 9092;
72  
73 =encoding utf8
74  
75 =head1 NAME
76  
77 SQL::Abstract::Plugin::ExtraClausesFixed - Fixes for ExtraClauses
78  
79 =head1 DESCRIPTION
80  
81 This is a subclass of SQL::Abstract::Plugin::ExtraClauses that fixes a few annoying bugs . Details below !
82  
83 B <EXPERIMENTAL>
84  
85 =head2 Using with DBIx::Class
86  
87 In order to use this with DBIx::Class, you simply need to apply the DBIC-SQLA2 plugin,
88 and then your SQLMaker will support these fixes!
89  
90 =head2 Bugs fixed
91  
92 =head3 using in -join
93  
94 The ExtraClauses plugin has a bug that it double expands the using option for joins, making them unusable unless you explicitly pass in a hashref. This fixes, that allowing you to do natural joins using multiple columns.
95  
96 =head3 setop inner select marshalling
97  
98 ExtraClauses has a bug where it puts the group_by and having clauses after setops (like UNION and friends). This is incorrect, the inner subquery is meant to have those clauses. This is fixed here.
99  
100 In order to use this feature, you must pass group_by or having with the bang override syntax ('!group_by' => ['things', 'and', 'stuff']). I may get an idea one day and figure out how to support it even with a bare group_by.
101  
102 =head3 SQLite setop parens
103  
104 Syntax across different DBMSs is annoying. DBIC likes assuming that you can arbitrarily
105 wrap subqueries in as many parens as you'd like. SQLite considers it a syntax error if the
106 queries that you join with a UNION are parenthesized. This class handles the selective
107 parenthesizing. It will also strip parens if necessary from the output of a $rs->as_query,
108 allowing you to use the setops in the most natural way.
109  
110 =cut
↑ Summary blib/lib/SQL/Abstract/Plugin/WindowFunctions.pm »