Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Use sorting but convert ascending and descending
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Feb 25, 2016
1 parent 59cf675 commit 5b15d67
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/App/txtnix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ has twtfile => (
);

has pager => ( is => 'rw', default => sub { 1 } );
has ascending => ( is => 'rw', default => sub { 0 } );
has descending => ( is => 'rw', default => sub { 1 } );
has sorting => ( is => 'rw', default => sub { "descending" } );
has timeout => ( is => 'rw', default => sub { 5 } );
has use_cache => ( is => 'rw', default => sub { 1 } );
has limit => ( is => 'rw', default => sub { 20 } );
Expand All @@ -52,6 +51,13 @@ sub BUILDARGS {
$args->{config} =
path( $args->{config} || '~/.config/twtxt/config' );

if ( exists $args->{ascending} and $args->{ascending} ) {
$args->{sorting} = 'ascending';
}
if ( exists $args->{descending} and $args->{descending} ) {
$args->{sorting} = 'descending';
}

if ( $args->{config}->exists ) {
my $config = $class->read_file( $args->{config} );
if ( $config->{twtxt} ) {
Expand Down Expand Up @@ -200,9 +206,9 @@ sub filter_tweets {
@tweets;

@tweets = sort {
$self->ascending
? $a->timestamp <=> $b->timestamp
: $b->timestamp <=> $a->timestamp
$self->sorting eq 'descending'
? $b->timestamp <=> $a->timestamp
: $a->timestamp <=> $b->timestamp
} @tweets;

my $limit = $self->limit;
Expand Down

0 comments on commit 5b15d67

Please sign in to comment.