| 1 | package Class::DBI::AbstractSearch; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION @EXPORT); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | $VERSION = 0.07; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 8 | 1 | *import = \&Exporter::import; | |||||||||||||||||||||||||||
| 9 | 1 | @EXPORT = qw(search_where); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use SQL::Abstract::Limit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub search_where { | ||||||||||||||||||||||||||
|
Subroutine
search_where: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $where = (ref $_[0]) ? $_[0] : { @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $attr = (ref $_[0]) ? $_[1] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $order = ($attr) ? delete($attr->{order_by}) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $limit = ($attr) ? delete($attr->{limit}) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $offset = ($attr) ? delete($attr->{offset}) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # order is deprecated, but still backward compatible | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($attr && exists($attr->{order})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr and exists $attr->{"order"}
MC/DC0%0/2
$attr and exists $attr->{"order"}
$attr
exists $attr->{"order"}
Truth table0%0/3
A and B
A= $attrB= exists $attr->{"order"}
| |||||||||||||||||||||||||||||
| 23 | 0 | $order = delete($attr->{order}); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $class->can('retrieve_from_sql') or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | require Carp; | |||||||||||||||||||||||||||
| 28 | 0 | Carp::croak("$class should inherit from Class::DBI >= 0.90"); | |||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||
| 30 | 0 | my $sql = SQL::Abstract::Limit->new(%$attr); | |||||||||||||||||||||||||||
| 31 | 0 | my($phrase, @bind) = $sql->where($where, $order, $limit, $offset); | |||||||||||||||||||||||||||
| 32 | 0 | $phrase =~ s/^\s*WHERE\s*//i; | |||||||||||||||||||||||||||
| 33 | 0 | return $class->retrieve_from_sql($phrase, @bind); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | 1; | |||||||||||||||||||||||||||
| 37 | __END__ | ||||||||||||||||||||||||||||