blib/lib/Mojolicious/Plugin/Thumbnail.pm

filter: Statementstmt 61.2% 19 / 31 Branchbran 16.6% 2 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 42.8% 27 / 63 CC 10 SCAR 37.1
CC
10
Cov
40%
__ANON__
56.5
register
1.4
BEGIN
1.0
CRAP 40.7
↑ Summary
1 package Mojolicious::Plugin::Thumbnail;
2 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7  
8 1 ▶has default_args => sub{+{
Subroutine __ANON__: called CC=1 SCAR=0.0
9 1 src => '',
10 dst => '',
11 width => 0,
12 height => 0,
13 1 }};
14  
15 1 ▶sub register {
Subroutine register: called CC=1 SCAR=3.4
Pod documented
16 1 my ($self, $app) = @_;
17  
18 4 ▶ $app->helper(thumbnail => sub {
Subroutine __ANON__: called CC=10 SCAR=40.4
19 4 my $app = shift;
20 4 ▶ my $conf = @_ ? { @_ } : return;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 0 4
21  
22 4 $conf = {%{$self->default_args}, %$conf};
23  
24 4 my $src_image = Imager->new();
25 4 my $dst_image;
26  
27 4 ▶ die 'Source file missing' unless $src_image->open(file => $conf->{src});
Branch: 1 branch
BranchTrueFalseTotal
unless $src_image->open("file", $conf->{"src"}) 4 0 4
28  
29 0 my ($src_width, $src_height) = ($src_image->getwidth, $src_image->getheight);
30 0 my ($dst_width, $dst_height) = (int $conf->{width}, int $conf->{height} );
31  
32 0 ▶ if (!$dst_height || ($dst_width && $src_width < $src_height)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dst_height or $dst_width and $src_width < $src_height) { } 0 0 0
Condition0%0/6
not $dst_height or $dst_width and $src_width < $src_height
l!l&&r!l&&!r
000
$dst_width and $src_width < $src_height
!ll&&!rl&&r
000
MC/DC0%0/3
not $dst_height or $dst_width and $src_width < $src_height
not $dst_height $dst_width $src_width < $src_height
Truth table0%0/4
not(A) or B and C
A= not $dst_heightB= $dst_widthC= $src_width < $src_height
ABCresult
1XX1
0111
00X0
0100
33 0 $dst_height = $src_height * $dst_width /$src_width;
34 } else {
35 0 $dst_width = $src_width * $dst_height/$src_height;
36 }
37  
38 0 $dst_image = $src_image->scaleX(pixels => $dst_width)->scaleY(pixels => $dst_height);
39  
40 0 ▶ if ($conf->{width} && $conf->{height}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"width"} and $conf->{"height"}) 0 0 0
Condition0%0/3
$conf->{"width"} and $conf->{"height"}
!ll&&!rl&&r
000
MC/DC0%0/2
$conf->{"width"} and $conf->{"height"}
$conf->{"width"} $conf->{"height"}
Truth table0%0/3
A and B
A= $conf->{"width"}B= $conf->{"height"}
ABresult
0X0
100
111
41 0 $dst_image = $dst_image->crop(width => $conf->{width}, height => $conf->{height});
42 }
43  
44 0 ▶ unless ($conf->{dst}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf->{"dst"}) 0 0 0
45 0 $conf->{dst} = $conf->{src};
46 0 $conf->{dst} =~ s{(.*?)\.(.+)$}{${1}_thumb.$2};
47 }
48  
49 0 ▶ $dst_image->write(file => $conf->{dst}) or die $dst_image->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dst_image->write("file", $conf->{"dst"}) or die $dst_image->errstr 0 0 0
50 1 });
51 }
52  
53 1 1;
54 __END__
↑ Summary