| 1 | package DBomb::Query::OrderBy; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | =head1 NAME | ||||||||||||||
| 4 | |||||||||||||||
| 5 | DBomb::Query::OrderBy - An ORDER BY clause. | ||||||||||||||
| 6 | |||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||
| 8 | |||||||||||||||
| 9 | =cut | ||||||||||||||
| 10 | |||||||||||||||
| 11 | 12 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 12 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 12 | our $VERSION = '$Revision: 1.4 $'; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 12 | ▶ | use Carp::Assert; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | use Class::MethodMaker | ||||||||||||||
| 17 | 12 | ▶ | 'new_with_init' => 'new', | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 'get_set' => [qw(names)], | ||||||||||||||
| 19 | 'boolean' => [qw(is_desc)], | ||||||||||||||
| 20 | 12 | ; | |||||||||||||
| 21 | |||||||||||||||
| 22 | ## new OrderBy([cols,...]) | ||||||||||||||
| 23 | ## new OrderBy(cols,...) | ||||||||||||||
| 24 | 4 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 25 | 4 | my $self = shift; | |||||||||||||
| 26 | 4 | assert(@_ > 0, 'valid parameters'); | |||||||||||||
| 27 | 4 | ▶ | assert(@_ == 1 ? (ref($_[0])? ref($_[0]) eq 'ARRAY' : 1) : 1, 'valid parameters'); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 28 | 4 | $self->names([]); | |||||||||||||
| 29 | 4 | $self->append(@_); | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 4 | ▶ | sub append { | ||||||||||||
|
Subroutine
append: called CC=3 SCAR=15.4
Pod
undocumented
| |||||||||||||||
| 33 | 4 | my $self = shift; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 4 | ▶ | if (UNIVERSAL::isa($_[0],__PACKAGE__)){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | 0 | push @{$self->names}, @{$_[0]->names}; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | elsif (ref($_[0]) eq 'ARRAY'){ | ||||||||||||||
| 39 | 0 | push @{$self->names}, @{$_->[0]} | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | else { | ||||||||||||||
| 42 | 4 | push @{$self->names}, @_; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 0 | ▶ | sub asc { | ||||||||||||
|
Subroutine
asc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||
| 48 | 0 | assert(@_ == 0, 'asc takes no arguments'); | |||||||||||||
| 49 | 0 | $self->is_desc(0); | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 2 | ▶ | sub desc { | ||||||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 53 | 2 | my $self = shift; | |||||||||||||
| 54 | 2 | assert(@_ == 0, 'desc takes no arguments'); | |||||||||||||
| 55 | 2 | $self->is_desc(1); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | sub sql { | ||||||||||||
|
Subroutine
sql: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 59 | 0 | my ($self, $dbh) = @_; | |||||||||||||
| 60 | 0 | my $names = $self->names; | |||||||||||||
| 61 | 0 | ▶ | return '' unless @$names; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 0 | ▶ | return join(",", @$names) . ($self->is_desc ? ' DESC ' : ' ASC '); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | |||||||||||||||
| 66 | 12 | 1; | |||||||||||||
| 67 | __END__ | ||||||||||||||