| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 50 | 0 | ▶ | $width ||= $blio->thumbnail; | ||||||||||||||||||
|
Condition0%0/3
$width ||= $blio->thumbnail
MC/DC0%0/2
$width ||= $blio->thumbnail
$width
$blio->thumbnail
Truth table0%0/3
A ||= B
A= $widthB= $blio->thumbnail
| |||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||
| 52 | 0 | ▶ | $thumbnail->write( file => $target ) || die "Cannot write thumbnail $target" . $thumbnail->errstr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 19 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 56 | 19 | 1; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||