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

Commit

Permalink
Add option cache_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Feb 27, 2016
1 parent 322336f commit 1f79d9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 8 additions & 4 deletions lib/App/txtnix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use Mojo::ByteStream 'b';

our $VERSION = '0.01';

has 'ua' => sub { shift->_build_ua };
has cache => sub { App::txtnix::Cache->new() };
has 'ua' => sub { shift->_build_ua };
has cache => sub { App::txtnix::Cache->new( cache_dir => shift->cache_dir ) };

has twtfile => sub { path('~/twtxt') };
has twtfile => sub { path('~/.cache/txtnix') };
has pager => sub { 1 };
has sorting => sub { "descending" };
has timeout => sub { 5 };
Expand All @@ -32,7 +33,7 @@ has nick => sub { $ENV{USER} };
has since => sub { 0 };
has until => sub { time };

has [qw( twturl pre_tweet_hook post_tweet_hook config force )];
has [qw( twturl pre_tweet_hook post_tweet_hook config force cache_dir )];

sub new {
my ( $class, @args ) = @_;
Expand Down Expand Up @@ -62,7 +63,10 @@ sub new {
$args->{following} = $config->{following};
}
}
$args->{twtfile} = path( $args->{twtfile} ) if exists $args->{twtfile};
for my $path (qw(twtfile cache_dir)) {
$args->{$path} = path( $args->{$path} ) if exists $args->{$path};
}

return bless {%$args}, ref $class || $class;
}

Expand Down
14 changes: 9 additions & 5 deletions lib/App/txtnix/Cache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use Mojo::ByteStream 'b';
use Path::Tiny;
use Mojo::JSON qw(encode_json decode_json);

has cache_dir => sub {
my $dir = path('~/.cache/txtnix/');
$dir->mkpath if not $dir->exists;
return $dir;
};
has cache_dir => sub { path('~/.cache/txtnix/') };

sub new {
my $class = shift;
my $self = bless @_ ? @_ > 1 ? {@_} : { %{ $_[0] } } : {},
ref $class || $class;
$self->cache_dir->mkpath if not $self->cache_dir->exists;
return $self;
}

sub get {
my ( $self, $key ) = @_;
Expand Down
9 changes: 9 additions & 0 deletions lib/App/txtnix/Cmd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ opt cache => (
isa => 'Bool',
comment => 'Cache remote twtxt files locally.',
);
opt cache_dir => (
isa => 'Str',
comment => 'Directory for saving twtxt files locally.',
);
opt timeout => (
isa => 'Int',
comment => 'Maximum time requests are allowed to take.',
);
opt pager => (
isa => 'Bool',
comment => 'Use a pager to display content.',
default => 1,
);
opt time_format => (
isa => 'Str',
Expand Down Expand Up @@ -94,6 +99,10 @@ opt cache => (
isa => 'Bool',
comment => 'Cache remote twtxt files locally.',
);
opt cache_dir => (
isa => 'Str',
comment => 'Directory for saving twtxt files locally.',
);
opt timeout => (
isa => 'Int',
comment => 'Maximum time requests are allowed to take.',
Expand Down

0 comments on commit 1f79d9d

Please sign in to comment.