Data-CloudWeights
view release on metacpan or search on metacpan
lib/Data/CloudWeights.pm view on Meta::CPAN
documentation => 'Sort order - asc or desc', default => 'asc';
has 'sort_type' => is => 'rw', isa => $SORT_TYPE,
documentation => 'Sort type - alpha or numeric',
default => 'alpha';
has 'total_count' => is => 'rwp', isa => Int, default => 0,
documentation => 'Current total for all tags in the cloud';
# Private attributes
has '_index' => is => 'ro', isa => HashRef, default => sub { {} };
has '_sorts' => is => 'ro', isa => HashRef, default => sub { {
alpha => {
asc => sub { my $x = shift; sub { $_[ 0 ]->{ $x } cmp $_[ 1 ]->{ $x } }
},
desc => sub { my $x = shift; sub { $_[ 1 ]->{ $x } cmp $_[ 0 ]->{ $x } }
},
},
numeric => {
asc => sub { my $x = shift; sub { $_[ 0 ]->{ $x } <=> $_[ 1 ]->{ $x } }
},
desc => sub { my $x = shift; sub { $_[ 1 ]->{ $x } <=> $_[ 0 ]->{ $x } }
},
} } };
has '_tags' => is => 'ro', isa => ArrayRef, default => sub { [] };
# Private methods
my $_get_sort_method = sub {
my $self = shift; # Add called multiple times, determine the sorting method
# No sorting if sort field is false
my $field = $self->sort_field or return sub { return 0 };
ref $field and return $field; # User supplied subroutine
my $orderby = $self->_sorts->{ lc $self->sort_type }
( run in 0.571 second using v1.01-cache-2.11-cpan-5f2e87ce722 )