File Coverage

blib/lib/DBomb/Query/OrderBy.pm
Criterion Covered Total %
statement 24 37 64.8
branch 5 12 41.6
condition n/a
subroutine 7 9 77.7
pod 2 5 40.0
total 38 63 60.3


line stmt bran cond sub pod time code
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     12   68 use strict;
  12         1245  
  12         416  
12 12     12   66 use warnings;
  12         26  
  12         517  
13             our $VERSION = '$Revision: 1.4 $';
14              
15 12     12   61 use Carp::Assert;
  12         23  
  12         75  
16             use Class::MethodMaker
17 12         104 'new_with_init' => 'new',
18             'get_set' => [qw(names)],
19             'boolean' => [qw(is_desc)],
20 12     12   1904 ;
  12         20  
21              
22             ## new OrderBy([cols,...])
23             ## new OrderBy(cols,...)
24             sub init {
25 4     4 0 34 my $self = shift;
26 4         11 assert(@_ > 0, 'valid parameters');
27 4 50       28 assert(@_ == 1 ? (ref($_[0])? ref($_[0]) eq 'ARRAY' : 1) : 1, 'valid parameters');
    100          
28 4         106 $self->names([]);
29 4         44 $self->append(@_);
30             }
31              
32             sub append {
33 4     4 0 5 my $self = shift;
34              
35 4 50       26 if (UNIVERSAL::isa($_[0],__PACKAGE__)){
    50          
36 0         0 push @{$self->names}, @{$_[0]->names};
  0         0  
  0         0  
37             }
38             elsif (ref($_[0]) eq 'ARRAY'){
39 0         0 push @{$self->names}, @{$_->[0]}
  0         0  
  0         0  
40             }
41             else {
42 4         6 push @{$self->names}, @_;
  4         102  
43             }
44             }
45              
46             sub asc {
47 0     0 1 0 my $self = shift;
48 0         0 assert(@_ == 0, 'asc takes no arguments');
49 0         0 $self->is_desc(0);
50             }
51              
52             sub desc {
53 2     2 1 3 my $self = shift;
54 2         6 assert(@_ == 0, 'desc takes no arguments');
55 2         56 $self->is_desc(1);
56             }
57              
58             sub sql {
59 0     0 0   my ($self, $dbh) = @_;
60 0           my $names = $self->names;
61 0 0         return '' unless @$names;
62 0 0         return join(",", @$names) . ($self->is_desc ? ' DESC ' : ' ASC ');
63             }
64              
65              
66             1;
67             __END__