| 1 | package EntityModel::EntityCollection; | ||||||||||||||
| 2 | { | ||||||||||||||
| 3 | 2 | $EntityModel::EntityCollection::VERSION = '0.102'; | |||||||||||||
| 4 | } | ||||||||||||||
| 5 | 2 | ▶ | use EntityModel::Class { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | _isa => [qw(EntityModel::Collection)], | |||||||||||||
| 7 | query => { type => qw(EntityModel::Query) }, | ||||||||||||||
| 8 | 2 | }; | |||||||||||||
| 9 | |||||||||||||||
| 10 | =head1 NAME | ||||||||||||||
| 11 | |||||||||||||||
| 12 | EntityModel::EntityCollection - deal with collections of entities | ||||||||||||||
| 13 | |||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||
| 15 | |||||||||||||||
| 16 | version 0.102 | ||||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||
| 19 | |||||||||||||||
| 20 | =cut | ||||||||||||||
| 21 | |||||||||||||||
| 22 | =head2 group | ||||||||||||||
| 23 | |||||||||||||||
| 24 | =cut | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 0 | ▶ | sub group { | ||||||||||||
|
Subroutine
group: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||||
| 28 | 0 | my $param = shift; | |||||||||||||
| 29 | 0 | logDebug("Group by %s", $param); | |||||||||||||
| 30 | 0 | $self->query->add_group($param); | |||||||||||||
| 31 | 0 | $self->pending(1); | |||||||||||||
| 32 | return defined wantarray | ||||||||||||||
| 33 | 0 | ▶ | ? $self | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | : $self->commit | ||||||||||||||
| 35 | } | ||||||||||||||
| 36 | |||||||||||||||
| 37 | =head2 select | ||||||||||||||
| 38 | |||||||||||||||
| 39 | =cut | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | ▶ | sub select : method { | ||||||||||||
|
Subroutine
select: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||
| 43 | 0 | foreach my $param (@_) { | |||||||||||||
| 44 | 0 | logDebug("Select %s", $param); | |||||||||||||
| 45 | 0 | $self->query->add_field($param); | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | 0 | $self->pending(1); | |||||||||||||
| 48 | return defined wantarray | ||||||||||||||
| 49 | 0 | ▶ | ? $self | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | : $self->commit | ||||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head2 order | ||||||||||||||
| 54 | |||||||||||||||
| 55 | =cut | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | sub order { | ||||||||||||
|
Subroutine
order: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||
| 59 | 0 | foreach my $param (@_) { | |||||||||||||
| 60 | 0 | logDebug("Order by %s", $param); | |||||||||||||
| 61 | 0 | $self->query->add_order($param); | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | 0 | $self->pending(1); | |||||||||||||
| 64 | return defined wantarray | ||||||||||||||
| 65 | 0 | ▶ | ? $self | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | : $self->commit | ||||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | =head2 apply | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =cut | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | sub apply { | ||||||||||||
|
Subroutine
apply: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||
| 75 | logInfo("Will run query: %s", | ||||||||||||||
| 76 | 'select ' . join(', ', map { | ||||||||||||||
| 77 | (exists($_->{op}) | ||||||||||||||
| 78 | ? $_->{op} . '(' . $_->{field} . ')' | ||||||||||||||
| 79 | : $_->{field}) | ||||||||||||||
| 80 | 0 | ▶ | . ' as "' . $_->{alias} . '"' | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 0 | } @{ $self->{select} }) | |||||||||||||
| 82 | . ' from article' | ||||||||||||||
| 83 | . ' where 1=1' | ||||||||||||||
| 84 | . ' group by ' . join(', ', map { | ||||||||||||||
| 85 | (exists($_->{op}) | ||||||||||||||
| 86 | ? $_->{op} . '(' . $_->{field} . ')' | ||||||||||||||
| 87 | : $_->{field}) | ||||||||||||||
| 88 | 0 | ▶ | } @{ $self->{group} }) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | . ' order by ' . join(', ', map { | ||||||||||||||
| 90 | exists($_->{alias}) | ||||||||||||||
| 91 | ? $_->{alias} | ||||||||||||||
| 92 | : (exists($_->{op}) | ||||||||||||||
| 93 | ? $_->{op} . '(' . $_->{field} . ')' | ||||||||||||||
| 94 | : $_->{field}) | ||||||||||||||
| 95 | 0 | ▶ | } @{ $self->{order} }) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 96 | ); | ||||||||||||||
| 97 | # $self->(item => 'xyz', map rand(1023), @{$self->{select}}); | ||||||||||||||
| 98 | 0 | return $self; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | |||||||||||||||
| 101 | 2 | 1; | |||||||||||||
| 102 | |||||||||||||||
| 103 | __END__ | ||||||||||||||