« lib/Reaction/UI/ViewPort/Field/Mutable/Array.pm
↑ Summary
lib/Reaction/Meta/InterfaceModel/Action/ParameterAttribute.pm »
| 1 | package Reaction::UI::ViewPort::Collection::Role::Order; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use Reaction::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use MooseX::Types::Moose qw/Int HashRef Str ArrayRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | has enable_order_by => (is => 'rw', isa => ArrayRef); | |||||||||
| 8 | 5 | has coerce_order_by => (is => 'rw', isa => HashRef); | |||||||||
| 9 | |||||||||||
| 10 | 5 | has order_by => ( | |||||||||
| 11 | isa => Str, | ||||||||||
| 12 | is => 'rw', | ||||||||||
| 13 | trigger_adopt('order_by'), | ||||||||||
| 14 | clearer => 'clear_order_by' | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 5 | has order_by_desc => ( | |||||||||
| 18 | isa => Int, | ||||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | trigger_adopt('order_by'), | ||||||||||
| 21 | lazy_build => 1 | ||||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub _build_order_by_desc { 0 } | ||||||||
|
Subroutine
_build_order_by_desc: not called CC=1 SCAR=6.9
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub adopt_order_by { | ||||||||
|
Subroutine
adopt_order_by: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | 0 | shift->clear_current_collection; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub can_order_by { | ||||||||
|
Subroutine
can_order_by: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 31 | 0 | my ($self,$order_by) = @_; | |||||||||
| 32 | 0 | ▶ | return 1 unless $self->has_enable_order_by; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | return scalar grep { $order_by eq $_ } @{ $self->enable_order_by }; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub _order_search_attrs { | ||||||||
|
Subroutine
_order_search_attrs: not called CC=5 SCAR=34.0
| |||||||||||
| 37 | 0 | my $self = shift; | |||||||||
| 38 | 0 | my %attrs; | |||||||||
| 39 | 0 | ▶ | if ($self->has_order_by) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | my $order_by = $self->order_by; | |||||||||
| 41 | 0 | ▶ | if( $self->has_coerce_order_by ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | $order_by = $self->coerce_order_by->{$order_by} | ||||||||||
| 43 | 0 | ▶ | if exists $self->coerce_order_by->{$order_by}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | } | ||||||||||
| 45 | 0 | ▶ | my $key = $self->order_by_desc ? '-desc' : '-asc'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | $attrs{order_by} = { $key => $order_by }; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | return \%attrs; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | after clear_order_by => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 52 | 0 | my ($self) = @_; | |||||||||
| 53 | 0 | $self->order_by_desc(0); | |||||||||
| 54 | 0 | $self->clear_current_collection; | |||||||||
| 55 | 5 | }; | |||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | around _build_current_collection => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 58 | 0 | my $orig = shift; | |||||||||
| 59 | 0 | my ($self) = @_; | |||||||||
| 60 | 0 | my $collection = $orig->(@_); | |||||||||
| 61 | 0 | return $collection->where(undef, $self->_order_search_attrs); | |||||||||
| 62 | 5 | }; | |||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | around accept_events => sub { ('order_by', 'order_by_desc', shift->(@_)); }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 65 | |||||||||||
| 66 | 5 | 1; | |||||||||
| 67 | |||||||||||
| 68 | __END__; | ||||||||||