aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGuillermo Ramos2019-06-24 12:04:15 +0200
committerGuillermo Ramos2019-06-24 12:04:15 +0200
commit47fb4fc02407def9d9b19a2746983b8c65937e3f (patch)
tree75b72d0b8ff49d9e25e0192760d07061a514ab5c /lib
parent07975e3f25a20d30238442ce3fc98dc2b24f14a9 (diff)
downloadtgutils-47fb4fc02407def9d9b19a2746983b8c65937e3f.tar.gz
TgLib.{Cache,Env}
Diffstat (limited to 'lib')
-rw-r--r--lib/TgLib.pm6
-rw-r--r--lib/TgLib/Cache.pm34
-rw-r--r--lib/TgLib/Env.pm10
3 files changed, 50 insertions, 0 deletions
diff --git a/lib/TgLib.pm b/lib/TgLib.pm
new file mode 100644
index 0000000..9be77d7
--- /dev/null
+++ b/lib/TgLib.pm
@@ -0,0 +1,6 @@
+package TgLib;
+
+use parent qw<Exporter>;
+our @EXPORT = qw<>;
+
+1;
diff --git a/lib/TgLib/Cache.pm b/lib/TgLib/Cache.pm
new file mode 100644
index 0000000..d3723b7
--- /dev/null
+++ b/lib/TgLib/Cache.pm
@@ -0,0 +1,34 @@
+package TgLib::Cache;
+
+use Storable qw<store retrieve>;
+use File::Basename qw<dirname>;
+
+use TgLib::Env qw<$CACHE_HOME>;
+
+use parent qw<Exporter>;
+our @EXPORT = qw<new>;
+
+my $CACHE_FILE = "$CACHE_HOME/tgutils/cache";
+
+sub new {
+ my $class = shift;
+
+ # Fetch cache
+ return bless((-f $CACHE_FILE
+ ? retrieve($CACHE_FILE)
+ : {'version' => $main::VERSION}), $class);
+}
+
+sub offset {
+ my $cache = shift;
+ $cache->{'offset'} = shift if @_;
+ return $cache->{'offset'};
+}
+
+sub save {
+ my $cache = shift;
+ mkdir dirname $CACHE_FILE;
+ store($cache, $CACHE_FILE);
+}
+
+1;
diff --git a/lib/TgLib/Env.pm b/lib/TgLib/Env.pm
new file mode 100644
index 0000000..b1e94aa
--- /dev/null
+++ b/lib/TgLib/Env.pm
@@ -0,0 +1,10 @@
+package TgLib::Env;
+
+use parent qw<Exporter>;
+our @EXPORT = qw<$HOME $CONFIG_HOME $CACHE_HOME>;
+
+our $HOME = $ENV{'HOME'};
+our $CONFIG_HOME = $ENV{'XDG_CONFIG_HOME'} || "$HOME/.config";
+our $CACHE_HOME = $ENV{'XDG_CACHE_HOME'} || "$HOME/.cache";
+
+1;