File Coverage

blib/lib/SQL/OOP/Order.pm
Criterion Covered Total %
statement 56 56 100.0
branch 6 8 75.0
condition n/a
subroutine 16 16 100.0
pod 7 7 100.0
total 85 87 97.7


line stmt bran cond sub pod time code
1             package SQL::OOP::Order;
2 9     9   45 use strict;
  9         17  
  9         645  
3 9     9   47 use warnings;
  9         15  
  9         209  
4 9     9   41 use SQL::OOP::Base;
  9         23  
  9         216  
5 9     9   42 use base qw(SQL::OOP::Array);
  9         14  
  9         4795  
6              
7             ### ---
8             ### Constructor
9             ### ---
10             sub new {
11 7     7 1 6799 my ($class, @array) = @_;
12 4         17 return $class->SUPER::new(
13 7         40 map {SQL::OOP::ID->new($_)} @array)->set_sepa(', ');
14             }
15              
16             ### ---
17             ### fix generated string in list context
18             ### ---
19             sub fix_element_in_list_context {
20 32     32 1 39 my ($self, $obj) = @_;
21 32         72 return $obj->to_string;
22             }
23              
24             ### ---
25             ### Construct ORER BY clause by array
26             ### ---
27             sub abstract {
28 5     5 1 3342 my ($class, $array_ref) = @_;
29 5         23 my $self = $class->SUPER::new()->set_sepa(', ');
30 5         7 foreach my $rec_ref (@{$array_ref}) {
  5         9  
31 10 100       21 if (ref $rec_ref) {
32 8 100       16 if ($rec_ref->[1]) {
33 4         11 $self->append_desc($rec_ref->[0]);
34             } else {
35 4         11 $self->append_asc($rec_ref->[0]);
36             }
37             } else {
38 2         6 $self->append_asc($rec_ref);
39             }
40             }
41 5         14 return $self;
42             }
43              
44             ### ---
45             ### Get SQL::OOP::Order::Expression instance(ASC)
46             ### ---
47             sub new_asc {
48 3     3 1 890 my ($class_or_obj, $key) = @_;
49 3         11 return SQL::OOP::Order::Expression->new($key);
50             }
51              
52             ### ---
53             ### Get SQL::OOP::Order::Expression instance(DESC)
54             ### ---
55             sub new_desc {
56 2     2 1 743 my ($class_or_obj, $key) = @_;
57 2         6 return SQL::OOP::Order::Expression->new_desc($key);
58             }
59              
60             ### ---
61             ### Append element(ASC)
62             ### ---
63             sub append_asc {
64 9     9 1 93 my ($self, $key) = @_;
65 9         27 $self->_init_gen;
66 9         10 push(@{$self->{array}}, SQL::OOP::Order::Expression->new($key));
  9         42  
67 9         27 return $self;
68             }
69              
70             ### ---
71             ### Append element(DESC)
72             ### ---
73             sub append_desc {
74 8     8 1 23 my ($self, $key) = @_;
75 8         22 $self->_init_gen;
76 8         9 push(@{$self->{array}}, SQL::OOP::Order::Expression->new_desc($key));
  8         117  
77 8         117 return $self;
78             }
79              
80             package SQL::OOP::Order::Expression;
81 9     9   47 use strict;
  9         13  
  9         237  
82 9     9   40 use warnings;
  9         15  
  9         606  
83 9     9   48 use base qw(SQL::OOP::Base);
  9         12  
  9         1665  
84              
85             ### ---
86             ### Constructor
87             ### ---
88             sub new {
89 12     12   18 my ($class, $key) = @_;
90 12 50       40 if ($key) {
91 12         45 return $class->SUPER::new(SQL::OOP::ID->new($key));
92             }
93             }
94              
95             ### ---
96             ### DESC Constructor
97             ### ---
98             sub new_desc {
99 10     10   15 my ($class, $key) = @_;
100 10 50       47 if ($key) {
101 10         42 return $class->SUPER::new(
102             SQL::OOP::ID->new($key)->to_string. " DESC");
103             }
104             }
105              
106             1;
107              
108             __END__