Catalyst-Controller-SimpleCAS
view release on metacpan or search on metacpan
lib/Catalyst/Controller/SimpleCAS.pm view on Meta::CPAN
package Catalyst::Controller::SimpleCAS;
use strict;
use warnings;
# ABSTRACT: General-purpose content-addressed storage (CAS) for Catalyst
our $VERSION = '1.002';
use Moose;
use Types::Standard qw(:all);
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
with 'Catalyst::Controller::SimpleCAS::Role::TextTranscode';
use Catalyst::Controller::SimpleCAS::Content;
use Module::Runtime;
use Try::Tiny;
use Catalyst::Utils;
use Path::Class qw(file dir);
use JSON;
use MIME::Base64;
use String::Random;
use Scalar::Util 'blessed';
has store_class => ( is => 'ro', default => sub {
'+File'
});
has store_path => ( is => 'ro', lazy => 1, default => sub {
my $self = shift;
my $c = $self->_app;
# Default Cas Store path if none was supplied in the config:
return dir( Catalyst::Utils::home($c), 'cas_store' )->stringify;
});
has store_args => ( is => 'ro', isa => 'HashRef', lazy => 1, default => sub {
my $self = shift;
return {
store_dir => $self->store_path,
};
});
has Store => (
does => 'Catalyst::Controller::SimpleCAS::Store',
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
my $class = $self->store_class;
if ($class =~ m/^\+([\w:]+)/) {
$class = 'Catalyst::Controller::SimpleCAS::Store::'.$1;
}
Module::Runtime::require_module($class);
return $class->new(
simplecas => $self,
%{$self->store_args},
);
},
handles => [qw(
file_checksum
calculate_checksum
)],
);
### ----------------------------------------------------------------------
### New sugar/convenience methods:
###
sub fetch {
my ($self, $cas_id) = @_;
$self->uri_find_Content($cas_id)
}
sub fetch_fh {
my ($self, $cas_id) = @_;
my $checksum = $self->_find_prune_checksum($cas_id) or return undef;
( run in 0.789 second using v1.01-cache-2.11-cpan-39bf76dae61 )