lib/Blio/Image.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 33.3% 2 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 79.7% 59 / 74 CC 6 SCAR 14.3
CC
6
Cov
79%
make_thumbnail
10.7
publish
2.0
BEGIN
1.0
CRAP 4.2
« lib/Blio.pm ↑ Summary script/blio.pl »
1 package Blio::Image;
2  
3 # ABSTRACT: An image node
4  
5 19 our $VERSION = '2.009'; # VERSION
6  
7 19 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Digest::SHA1;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 19 has 'base_dir' => ( is => 'ro', isa => 'Path::Class::Dir', required => 1 );
16 19 has 'source_file' =>
17 ( is => 'ro', isa => 'Path::Class::File', required => 1 );
18 19 has 'url' =>
19 ( is => 'ro', isa => 'Path::Class::File', required => 1, lazy_build=>1 );
20 7 ▶sub _build_url {
Subroutine _build_url: called CC=1 SCAR=0.0
21 7 my $self = shift;
22 7 return $self->source_file->relative($self->base_dir);
23 }
24 19 has 'thumbnail' =>
25 ( is => 'ro', isa => 'Path::Class::File', required => 1, lazy_build=>1);
26 4 ▶sub _build_thumbnail {
Subroutine _build_thumbnail: called CC=1 SCAR=0.0
27 4 my $self = shift;
28 4 my $th = $self->source_file->relative($self->base_dir)->stringify;
29 4 $th=~s{/([^/]+)$}{/th_$1};
30 4 return file($th);
31 }
32  
33 1 ▶sub publish {
Subroutine publish: called CC=2 SCAR=7.0
Pod documented
34 1 my ($self, $blio) = @_;
35  
36 1 $blio->output_dir->file($self->url)->parent->mkpath;
37 1 my $from = $self->source_file->stringify;
38 1 my $to = $blio->output_dir->file($self->url)->stringify;
39 1 ▶ copy($from, $to) || die "Cannot copy $from to $to: $!";
Branch: 1 branch
BranchTrueFalseTotal
copy($from, $to) or die "Cannot copy $from to ${to}: $!" 1 0 1
40 }
41  
42 1 ▶sub make_thumbnail {
Subroutine make_thumbnail: called CC=5 SCAR=23.7
Pod documented
43 1 my ($self, $blio, $width) = @_;
44  
45 1 $blio->output_dir->file($self->url)->parent->mkpath;
46 1 my $file = $self->source_file->stringify;
47 1 my $target = $blio->output_dir->file($self->thumbnail)->stringify;
48 1 my $image = Imager->new;
49 1 ▶ $image->read(file=>$file) || die "Cannot read image $file: ".$image->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$image->read("file", $file) or die "Cannot read image ${file}: " . $image->errstr 0 1 1
50 0 ▶ $width ||= $blio->thumbnail;
Condition0%0/3
$width ||= $blio->thumbnail
l!l&&r!l&&!r
000
MC/DC0%0/2
$width ||= $blio->thumbnail
$width $blio->thumbnail
Truth table0%0/3
A ||= B
A= $widthB= $blio->thumbnail
ABresult
1X1
011
000
51 0 ▶ my $thumbnail = $image->scale(xpixels => $width) || die "Cannot scale $file: ".$image->errstr;
Condition0%0/2
$image->scale('xpixels', $width) || die("Cannot scale ${file}: " . $image->errstr)
l!l
00
MC/DC0%0/1
$image->scale('xpixels', $width) || die("Cannot scale ${file}: " . $image->errstr)
$image->scale('xpixels', $width)
Truth table0%0/2
A
A= $image->scale('xpixels', $width)
Aresult
11
00
52 0 ▶ $thumbnail->write( file => $target ) || die "Cannot write thumbnail $target" . $thumbnail->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$thumbnail->write("file", $target) or die "Cannot write thumbnail $target" . $thumbnail->errstr 0 0 0
53 }
54  
55 19 __PACKAGE__->meta->make_immutable;
56 19 1;
57  
58 __END__
« lib/Blio.pm ↑ Summary script/blio.pl »