| 1 | package Catalyst::Controller::SimpleCAS::Store::DBIC; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | with qw( | |||||||||||
| 7 | Catalyst::Controller::SimpleCAS::Store | ||||||||||||
| 8 | ); | ||||||||||||
| 9 | |||||||||||||
| 10 | 1 | ▶ | use File::MimeInfo::Magic; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use Image::Size; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use Digest::SHA1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use IO::File; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 1 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 1 | ▶ | use MIME::Base64; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 1 | ▶ | use Try::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 1 | ▶ | use Path::Class qw( file dir ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 1 | ▶ | use IO::All; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | use bytes; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | 1 | has 'model' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||
| 24 | 0 | ▶ | has 'tempdir' => ( is => 'ro', isa => 'Str', lazy => 1, default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||
| 26 | 0 | return dir( Catalyst::Utils::class2tempdir($self->resultset->result_class), 'simplecas' )->stringify; | |||||||||||
| 27 | 1 | }); | |||||||||||
| 28 | |||||||||||||
| 29 | 0 | ▶ | sub resultset { | ||||||||||
|
Subroutine
resultset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 30 | 0 | my ( $self ) = @_; | |||||||||||
| 31 | 0 | $self->simplecas->_app->model($self->model); | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub get_result_by_checksum { | ||||||||||
|
Subroutine
get_result_by_checksum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 35 | 0 | my ( $self, $checksum ) = @_; | |||||||||||
| 36 | 0 | return $self->resultset->find({ | |||||||||||
| 37 | checksum => $checksum, | ||||||||||||
| 38 | }); | ||||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | sub add_content { | ||||||||||
|
Subroutine
add_content: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 42 | 0 | my ( $self, $data ) = @_; | |||||||||||
| 43 | 0 | my $checksum = $self->calculate_checksum($data); | |||||||||||
| 44 | 0 | ▶ | return $checksum if ($self->content_exists($checksum)); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | my $size = length($data); | |||||||||||
| 46 | 0 | my $result = $self->resultset->create({ | |||||||||||
| 47 | content => $data, | ||||||||||||
| 48 | checksum => $self->calculate_checksum($data), | ||||||||||||
| 49 | size => $size, | ||||||||||||
| 50 | }); | ||||||||||||
| 51 | 0 | ▶ | die "Unable to store data of $size bytes in Storage" unless $result; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 0 | return $result->checksum; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub checksum_to_path { | ||||||||||
|
Subroutine
checksum_to_path: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 56 | 0 | my ( $self, $checksum ) = @_; | |||||||||||
| 57 | 0 | my @parts = unpack("(A5)*", $checksum); | |||||||||||
| 58 | 0 | my $filename = pop @parts; | |||||||||||
| 59 | 0 | my $dir = join("/",$self->tempdir,@parts); | |||||||||||
| 60 | 0 | my $fullname = join("/",$dir,$filename); | |||||||||||
| 61 | 0 | ▶ | return $fullname if io($fullname)->exists; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 0 | io($dir)->mkpath; | |||||||||||
| 63 | 0 | my $entry = $self->get_result_by_checksum($checksum); | |||||||||||
| 64 | 0 | io($fullname)->print($entry->content); | |||||||||||
| 65 | 0 | return $fullname; | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | sub fetch_content { | ||||||||||
|
Subroutine
fetch_content: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 69 | 0 | my ( $self, $checksum ) = @_; | |||||||||||
| 70 | 0 | my $entry = $self->get_result_by_checksum($checksum); | |||||||||||
| 71 | 0 | ▶ | return "" unless $entry; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | 0 | return $entry->content; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 0 | ▶ | sub content_exists { | ||||||||||
|
Subroutine
content_exists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 76 | 0 | my ( $self, $checksum ) = @_; | |||||||||||
| 77 | 0 | ▶ | return $self->get_result_by_checksum($checksum) ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | 0 | ▶ | around content_mimetype => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||
| 81 | 0 | my $orig = shift; | |||||||||||
| 82 | 0 | my $self = shift; | |||||||||||
| 83 | 0 | my $checksum = shift; | |||||||||||
| 84 | 0 | my $result = $self->get_result_by_checksum($checksum); | |||||||||||
| 85 | 0 | ▶ | return undef unless $result; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 0 | ▶ | return $result->mimetype if defined $result->mimetype; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 0 | ▶ | my $mimetype = $self->$orig($checksum) || ''; | ||||||||||
|
Condition0%0/2
$self->$orig($checksum) || ''
MC/DC0%0/1
$self->$orig($checksum) || ''
$self->$orig($checksum)
Truth table0%0/2
A
A= $self->$orig($checksum)
| |||||||||||||
| 88 | 0 | $result->mimetype($mimetype); | |||||||||||
| 89 | 0 | $result->update; | |||||||||||
| 90 | 0 | return $mimetype; | |||||||||||
| 91 | 1 | }; | |||||||||||
| 92 | |||||||||||||
| 93 | 0 | ▶ | around image_size => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||
| 94 | 0 | my $orig = shift; | |||||||||||
| 95 | 0 | my $self = shift; | |||||||||||
| 96 | 0 | my $checksum = shift; | |||||||||||
| 97 | 0 | my $result = $self->get_result_by_checksum($checksum); | |||||||||||
| 98 | 0 | ▶ | return unless $result; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 0 | ▶ | if (defined $result->image_width) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | 0 | ▶ | return undef unless $result->image_width; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 0 | return ( $result->image_width, $result->image_height ); | |||||||||||
| 102 | } | ||||||||||||
| 103 | 0 | my ( $width, $height ) = $self->$orig($checksum); | |||||||||||
| 104 | 0 | ▶ | $width = 0 unless $width; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 0 | ▶ | $height = 0 unless $height; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 0 | $result->image_width($width); | |||||||||||
| 107 | 0 | $result->image_height($height); | |||||||||||
| 108 | 0 | $result->update; | |||||||||||
| 109 | 0 | ▶ | return undef unless $width; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | 0 | return ( $width, $height ); | |||||||||||
| 111 | 1 | }; | |||||||||||
| 112 | |||||||||||||
| 113 | 0 | ▶ | sub content_size { | ||||||||||
|
Subroutine
content_size: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 114 | 0 | my ( $self, $checksum ) = @_; | |||||||||||
| 115 | 0 | my $result = $self->get_result_by_checksum($checksum); | |||||||||||
| 116 | 0 | ▶ | return $result ? $result->size : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | #### --------------------- #### | ||||||||||||
| 120 | |||||||||||||
| 121 | 1 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 122 | #__PACKAGE__->meta->make_immutable; | ||||||||||||
| 123 | 1 | 1; | |||||||||||
| 124 | |||||||||||||
| 125 | __END__ | ||||||||||||