Acme-CatFS

 view release on metacpan or  search on metacpan

lib/Acme/CatFS.pm  view on Meta::CPAN

use strict;
use warnings;
package Acme::CatFS;

# ABSTRACT: Fuse filesystem with a random pic of a cat

use feature qw(say state);
use Carp;
use Try::Tiny;
use LWP::Simple;
use Fuse::Simple;

use Moo;
use MooX::Options;
use Types::Path::Tiny qw(Dir);

option mountpoint => ( 
  is       => 'ro', 
  isa      => Dir,
  required => 1,
  format   => 's',
  coerce   => Dir->coercion,
  doc      => 'mount point for catfs (should be a directory). Required.',
);

option cat_url => (
  is      => 'ro',
  format  => 's',
  default => sub {
    'http://thecatapi.com/api/images/get?format=src&type=jpg'
  },
  doc     => 'url used to find a random pic of a cat (default thecatapi.com)',
);

option cat_file => (
  is      => 'ro',
  format  => 's',
  default => sub { 'cat.jpg' },
  doc     => 'name of the file (default is cat.jpg)',
);

option forking => (
  is  => 'ro',
  doc => 'if enable, will fork and exit (default false)',
);

option debug => (
  is  => 'ro',
  doc => 'if enable, will run Fuse::Simple in debug mode (default false)',
);

option cached => (
  is  => 'ro',
  doc => 'if enable, will cached the picture instead choose another each open (default false)',
);

sub _get_cat_picture {
  my $self = shift;
  state $cached_content;
  
  if($self->cached && $cached_content){
    return $cached_content;
  }

  my $content = try { 
    LWP::Simple::get($self->cat_url) 
  } catch {
    carp $_ if $self->debug;
  };

  if($self->cached){
    $cached_content = $content
  }

  $content
}

sub run {
  my ($self) = @_;



( run in 0.945 second using v1.01-cache-2.11-cpan-5837b0d9d2c )