Screenshot/CanPad.pm

filter: Statementstmt 100% 35 / 35 Branchbran 50.0% 6 / 12 Conditioncond 58.3% 7 / 12 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 79.2% 61 / 77 CC 13 SCAR 14.8
CC
13
Cov
81%
coerce_image_size
6.8
cmp_image_dims
5.9
_get_largest_dimensions
3.1
CRAP 4.4
« Screenshot.pm ↑ Summary
1 package Selenium::Screenshot::CanPad;
2 2 $Selenium::Screenshot::CanPad::VERSION = '0.08';
3 2 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 # ABSTRACT: Provides subs for coercing two images to the exact width and height
6 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9  
10 1 ▶sub coerce_image_size {
Subroutine coerce_image_size: called CC=6 SCAR=19.1
Pod documented
11 1 my ($self, $image1, $image2) = @_;
12  
13 1 foreach ( $image1, $image2 ) {
14 2 ▶ croak 'Expected two Imager objects' unless blessed $_ && $_->isa('Imager');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_) and $_->isa("Imager") 0 2 2
Condition33%1/3
builtin::blessed($_) and $_->isa("Imager")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($_) and $_->isa("Imager")
builtin::blessed($_) $_->isa("Imager")
Truth table33%1/3
A and B
A= builtin::blessed($_)B= $_->isa("Imager")
ABresult
0X0
100
111
15 }
16  
17 1 my $coerce_dims = _get_largest_dimensions( $image1, $image2 );
18  
19 1 ▶ if ( _is_smaller( $image1, $coerce_dims ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_smaller($image1, $coerce_dims)) 1 0 1
20 1 $image1 = _pad_image( $image1, $coerce_dims );
21 }
22  
23 1 ▶ if ( _is_smaller( $image2, $coerce_dims ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_smaller($image2, $coerce_dims)) 1 0 1
24 1 $image2 = _pad_image( $image2, $coerce_dims );
25 }
26  
27 1 return ( $image1, $image2 );
28 }
29  
30  
31 2 ▶sub cmp_image_dims {
Subroutine cmp_image_dims: called CC=5 SCAR=17.8
Pod documented
32 2 my ($self, $image1, $image2) = @_;
33  
34 2 foreach ( $image1, $image2 ) {
35 4 ▶ croak 'Expected two Imager objects'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_) and $_->isa("Imager") 0 4 4
Condition33%1/3
builtin::blessed($_) and $_->isa("Imager")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($_) and $_->isa("Imager")
builtin::blessed($_) $_->isa("Imager")
Truth table33%1/3
A and B
A= builtin::blessed($_)B= $_->isa("Imager")
ABresult
0X0
100
111
36 unless blessed $_ && $_->isa('Imager');
37 }
38  
39 2 ▶ return $image1->getheight == $image2->getheight &&
Condition66%2/3
$image1->getheight == $image2->getheight && $image1->getwidth == $image2->getwidth
!ll&&!rl&&r
101
MC/DC50%1/2
$image1->getheight == $image2->getheight && $image1->getwidth == $image2->getwidth
$image1->getheight == $image2->getheight $image1->getwidth == $image2->getwidth
Truth table66%2/3
A && B
A= $image1->getheight == $image2->getheightB= $image1->getwidth == $image2->getwidth
ABresult
0X0
100
111
40 $image1->getwidth == $image2->getwidth;
41 }
42  
43 2 ▶sub _get_largest_dimensions {
Subroutine _get_largest_dimensions: called CC=3 SCAR=11.3
44 2 my ($image1, $image2) = @_;
45  
46 2 ▶ my $max_width = $image1->getwidth >= $image2->getwidth
Branch: 1 branch
BranchTrueFalseTotal
$image1->getwidth >= $image2->getwidth ? : 0 2 2
47 ? $image1->getwidth
48 : $image2->getwidth;
49  
50 2 ▶ my $max_height = $image1->getheight >= $image2->getheight
Branch: 1 branch
BranchTrueFalseTotal
$image1->getheight >= $image2->getheight ? : 2 0 2
51 ? $image1->getheight
52 : $image2->getheight;
53  
54 2 my $dimensions = {
55 width => $max_width,
56 height => $max_height
57 };
58  
59 2 return $dimensions
60 }
61  
62 4 ▶sub _is_smaller {
Subroutine _is_smaller: called CC=2 SCAR=6.9
63 4 my ($image, $dimensions) = @_;
64  
65 return $image->getwidth < $dimensions->{width} ||
66 4 ▶ $image->getheight < $dimensions->{height};
Condition100%3/3
$image->getwidth < $dimensions->{'width'} || $image->getheight < $dimensions->{'height'}
l!l&&r!l&&!r
211
MC/DC100%2/2
$image->getwidth < $dimensions->{'width'} || $image->getheight < $dimensions->{'height'}
$image->getwidth < $dimensions->{'width'} $image->getheight < $dimensions->{'height'}
Truth table100%3/3
A || B
A= $image->getwidth < $dimensions->{'width'}B= $image->getheight < $dimensions->{'height'}
ABresult
1X1
011
000
67 }
68  
69 3 ▶sub _pad_image {
Subroutine _pad_image: called CC=1 SCAR=0.0
70 3 my ($image, $dimensions) = @_;
71  
72 my $padded_image = Imager->new(
73 xsize => $dimensions->{width},
74 ysize => $dimensions->{height},
75 3 channels => $image->getchannels
76 );
77  
78 3 $padded_image->paste(
79 left => 0,
80 top => 0,
81 img => $image
82 );
83  
84 3 return $padded_image;
85 }
86  
87 2 1;
88  
89 __END__
« Screenshot.pm ↑ Summary