Catalyst-Controller-SimpleCAS
view release on metacpan or search on metacpan
lib/Catalyst/Controller/SimpleCAS/Store.pm view on Meta::CPAN
package Catalyst::Controller::SimpleCAS::Store;
use strict;
use Moose::Role;
use Digest::SHA1;
use IO::File;
use MIME::Base64;
use Try::Tiny;
use File::MimeInfo::Magic;
use Image::Size;
use Email::MIME;
use IO::All;
use Path::Class qw( file dir );
requires qw(
content_exists
fetch_content
add_content
checksum_to_path
);
sub add_content_base64 {
my $self = shift;
my $data = decode_base64(shift) or die "Error decoding base64 data. $@";
return $self->add_content($data);
}
sub add_content_file {
my $self = shift;
my $file = shift;
my $checksum = $self->file_checksum($file);
return $checksum if ($self->content_exists($checksum));
return $self->add_content(scalar(io($file)->slurp));
}
sub add_content_file_mv {
my $self = shift;
my $file = shift;
my $result = $self->add_content_file($file);
die "SimpleCAS: Failed to move file '$file' into storage" unless $result;
unlink $file;
return $result;
}
sub image_size {
my $self = shift;
my $checksum = shift;
my $content_type = $self->content_mimetype($checksum) or return undef;
my ($mime_type,$mime_subtype) = split(/\//,$content_type);
return undef unless ($mime_type eq 'image');
my ($width,$height) = imgsize($self->checksum_to_path($checksum)) or return undef;
return ($width,$height);
}
sub content_mimetype {
my $self = shift;
my $checksum = shift;
# See if this is an actual MIME file with a defined Content-Type:
( run in 0.733 second using v1.01-cache-2.11-cpan-39bf76dae61 )