| 1 | 24 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package DBIx::Class::Smooth::ResultSetBase; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Short intro | ||||||||||||||||||||||||||||
| 8 | 24 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||
| 9 | 24 | our $VERSION = '0.0104'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 24 | ▶ | use parent 'DBIx::Class::ResultSet'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 24 | ▶ | use List::SomeUtils qw/any/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 24 | ▶ | use Safe::Isa qw/$_isa/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 24 | ▶ | use Carp qw/croak confess/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 24 | ▶ | use DBIx::Class::Smooth::Q; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 24 | ▶ | use DBIx::Class::Smooth::FilterItem; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 24 | ▶ | use experimental qw/signatures postderef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | ▶ | sub _smooth__prepare_for_filter($self, @args) { | |||||||||||||||||||||||||||
|
Subroutine
_smooth__prepare_for_filter: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 20 | 0 | my @qobjs = grep { $_->$_isa('DBIx::Class::Smooth::Q') } @args; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | if(scalar @qobjs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if(scalar @args > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | die "Don't mix Q() and normal args"; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | else { | ||||||||||||||||||||||||||||
| 26 | 0 | @args = $args[0]->value->@*; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $i = undef; | |||||||||||||||||||||||||||
| 31 | 0 | my $prepared_args = []; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ARG: | ||||||||||||||||||||||||||||
| 34 | 0 | for my $fori (0..scalar @args - 1) { | |||||||||||||||||||||||||||
| 35 | # We do it this way since not all search args are key => value pairs (such as \[] searches) | ||||||||||||||||||||||||||||
| 36 | # meaning that sometimes we need to $i += 1 and sometimes $i += 2 | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $i = $fori if !defined $i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $possible_key = $args[$i]; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $possible_value = $i + 1 <= scalar @args - 1 ? $args[$i + 1] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # Dig deeper into the search structure | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if($possible_value && any { $possible_key eq $_ } (qw/-and -or -not_bool/)) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
$possible_value and &any(sub {
MC/DC0%0/2
$possible_value and &any(sub {
$possible_key eq $_;
}
, "-and", "-or", "-not_bool")
$possible_value
&any(sub {
$possible_key eq $_;
}
, "-and", "-or", "-not_bool")
Truth table0%0/3
A and B
A= $possible_valueB= &any(sub {
$possible_key eq $_;
}
, "-and", "-or", "-not_bool")
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if(ref $possible_value eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | push $prepared_args->@* => ($possible_key => $self->_smooth__prepare_for_filter($possible_value->@*)); | |||||||||||||||||||||||||||
| 46 | 0 | $i += 2; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | # There is no $possible_value for \[] searches, the value is already in the arrayrefref | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if(ref $possible_key eq 'REF') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 0 | push $prepared_args->@* => $possible_key; | |||||||||||||||||||||||||||
| 53 | 0 | $i++; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | ▶ | elsif(defined $possible_key && defined $possible_value) { | |||||||||||||||||||||||||||
|
Condition0%0/3
defined $possible_key and defined $possible_value
MC/DC0%0/2
defined $possible_key and defined $possible_value
defined $possible_key
defined $possible_value
Truth table0%0/3
A and B
A= defined $possible_keyB= defined $possible_value
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my @key_parts = split /__/ => $possible_key; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my $item = DBIx::Class::Smooth::FilterItem->new(resultset => $self, parts => \@key_parts, value => $possible_value); | |||||||||||||||||||||||||||
| 60 | 0 | ($possible_key, $possible_value) = $item->parse; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if($possible_key) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | push $prepared_args->@* => ($possible_key, $possible_value); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||
| 66 | 0 | push $prepared_args->@* => $possible_value; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | $i += 2; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | return $prepared_args; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | ▶ | sub filter($self, @args) { | |||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | # only compatible with array and Q | ||||||||||||||||||||||||||||
| 77 | 0 | my $args = $self->_smooth__prepare_for_filter(-and => \@args); | |||||||||||||||||||||||||||
| 78 | 0 | return $self->search($args); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | ▶ | sub filterattr($self, %args) { | |||||||||||||||||||||||||||
|
Subroutine
filterattr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 0 | return $self->search({}, \%args); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 24 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =pod | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 NAME | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | DBIx::Class::Smooth::ResultSetBase - Short intro | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head1 VERSION | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Version 0.0104, released 2020-08-30. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 SOURCE | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | L<https://github.com/Csson/p5-DBIx-Class-Smooth> | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | L<https://metacpan.org/release/DBIx-Class-Smooth> | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Erik Carlsson <info@code301.com> | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | This software is copyright (c) 2018 by Erik Carlsson. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 118 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||