lib/Snig/Image.pm

filter: Statementstmt 45.9% 34 / 74 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 5 totaltotal 33.3% 42 / 126 CC 15 SCAR 44.5
CC
15
Cov
34%
resize
182.0
__ANON__
6.0
write_html_page
6.0
CRAP 85.9
↑ Summary lib/Snig/Collection.pm »
1 2 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶no warnings "experimental::class";
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 class Snig::Image {
6  
7 2 our $VERSION = '1.001'; # VERSION
8 # ABSTRACT: Snig Image Class
9 # PODNAME: Snig::Image
10  
11 2 ▶ use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶ use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶ use Image::ExifTool qw(ImageInfo);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶ use File::Copy qw(copy);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use File::Share qw(dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 field $file :reader :param;
18 2 field $exif :reader;
19 2 field $mtime :reader;
20 2 field $created :reader;
21 2 field $model :reader;
22 2 field $orientation :reader;
23  
24 2 field $next :reader;
25 2 field $prev :reader;
26 2 field $pos :reader;
27  
28 0 ▶ ADJUST {
Subroutine __ANON__: not called CC=2 SCAR=17.9
29 0 ▶ $file = path($file) if !ref($file);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $file 0 0 0
30 0 $exif = ImageInfo($file->stringify);
31 0 $mtime = $file->stat->mtime;
32 0 $created = $exif->{'CreateDate'};
33 0 $model = $exif->{'Model'};
34 0 $orientation = $exif->{'Orientation'};
35 }
36  
37 0 ▶ method set_chain($this_pos, $prev_image, $next_image) {
Subroutine set_chain: not called CC=1 SCAR=6.9
Pod undocumented
38 0 $pos = $this_pos;
39 0 $prev = $prev_image;
40 0 $next = $next_image;
41 }
42  
43 0 ▶ method resize ( $outdir, $thumbnail, $detail, $force = 0 ) {
Subroutine resize: not called CC=13 SCAR=52.0
Pod undocumented
44  
45 0 ▶ copy($file, $outdir->child('orig_'.$file->basename)) unless -e $outdir->child('orig_'.$file->basename);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $outdir->child('orig_' . $file->basename) 0 0 0
46  
47 0 my ($img, $w, $h, $format);
48  
49 0 for my $scale ({format=>'thumbnail',size=>$thumbnail},{format=>'preview',size=>$detail}) {
50  
51 0 my $scaled_file_name = $scale->{format}.'_'.$file->basename;
52 0 my $outfile = $outdir->child($scaled_file_name);
53 0 ▶ next if ($outfile->is_file && !$force);
Branch: 1 branch
BranchTrueFalseTotal
if $outfile->is_file and not $force 0 0 0
Condition0%0/3
$outfile->is_file and not $force
!ll&&!rl&&r
000
MC/DC0%0/2
$outfile->is_file and not $force
$outfile->is_file not $force
Truth table0%0/3
A and not(B)
A= $outfile->is_fileB= not $force
ABresult
0X0
100
111
54  
55 0 ▶ unless ($img) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($img) 0 0 0
56 0 ▶ $img = Imager->new(file=>$file->stringify) || die Imager->errstr();
Condition0%0/2
'Imager'->new('file', $file->stringify) || die('Imager'->errstr)
l!l
00
MC/DC0%0/1
'Imager'->new('file', $file->stringify) || die('Imager'->errstr)
'Imager'->new('file', $file->stringify)
Truth table0%0/2
A
A= 'Imager'->new('file', $file->stringify)
Aresult
11
00
57 0 ▶ if ($orientation && $orientation =~ /(\d+) CW/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($orientation and $orientation =~ /(\d+) CW/u) 0 0 0
Condition0%0/3
$orientation and $orientation =~ /(\d+) CW/u
!ll&&!rl&&r
000
MC/DC0%0/2
$orientation and $orientation =~ /(\d+) CW/u
$orientation $orientation =~ /(\d+) CW/u
Truth table0%0/3
A and B
A= $orientationB= $orientation =~ /(\d+) CW/u
ABresult
0X0
100
111
58 0 my $degrees = $1;
59 0 my $rotated = $img->rotate(right=>$degrees);
60 0 $log->debugf("Rotated %s %s degrees right", $file->basename, $degrees);
61 0 $img = $rotated;
62 }
63 0 $w = $img->getwidth;
64 0 $h = $img->getheight;
65 0 $format = $w / $h;
66 }
67  
68 0 my $scaled;
69 0 ▶ if ($format >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format >= 1) { } 0 0 0
70 0 ▶ $scaled = $img->scale(xpixels => $scale->{size}) || die "Cannot scale $file: ".$img->errstr;
Condition0%0/2
$img->scale('xpixels', $scale->{'size'}) || die("Cannot scale ${file}: " . $img->errstr)
l!l
00
MC/DC0%0/1
$img->scale('xpixels', $scale->{'size'}) || die("Cannot scale ${file}: " . $img->errstr)
$img->scale('xpixels', $scale->{'size'})
Truth table0%0/2
A
A= $img->scale('xpixels', $scale->{'size'})
Aresult
11
00
71 }
72 else {
73 0 my $scale_h = int($scale->{size}) / 3 * 2; # TODO get proper factor, needs to inspect all image formats in set
74 0 ▶ $scaled = $img->scale(ypixels => $scale_h) || die "Cannot scale $file: ".$img->errstr;
Condition0%0/2
$img->scale('ypixels', $scale_h) || die("Cannot scale ${file}: " . $img->errstr)
l!l
00
MC/DC0%0/1
$img->scale('ypixels', $scale_h) || die("Cannot scale ${file}: " . $img->errstr)
$img->scale('ypixels', $scale_h)
Truth table0%0/2
A
A= $img->scale('ypixels', $scale_h)
Aresult
11
00
75 }
76  
77 0 $scaled->write(file=>$outfile, jpgquality=>100);
78 0 $log->debugf("Scaled %s to %s", $file->basename, $outfile);
79 0 local $|=1;
80 0 print '.';
81 }
82  
83 }
84  
85 0 ▶ method url($format) {
Subroutine url: not called CC=1 SCAR=6.9
Pod undocumented
86 0 return $format .'_'. $file->basename;
87 }
88  
89 0 ▶ method html_file {
Subroutine html_file: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my $html = lc($file->basename);
91 0 $html =~s/\.(.*?)$/.html/;
92 0 return $html;
93 }
94  
95 0 ▶ method write_html_page($tt, $output, $collection) {
Subroutine write_html_page: not called CC=2 SCAR=17.9
Pod undocumented
96  
97 0 ▶ $tt->process(dist_file('Snig','page.tt'), {
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(dist_file("Snig", "page.tt"), {"image", $self, "collection", {"name", $collection->name, "size", scalar $collection->sorted}, "version", "Snig"->VERSION}, $output->child($self->html_file)->stringify) or die $tt->error 0 0 0
98 image => $self,
99 collection=> {
100 name => $collection->name,
101 size => scalar $collection->sorted,
102 },
103 version => Snig->VERSION,
104 }, $output->child($self->html_file)->stringify) || die $tt->error;
105  
106 }
107  
108 }
109  
110 __END__
↑ Summary lib/Snig/Collection.pm »