Search/Match.pm

filter: Statementstmt 62.0% 31 / 50 Branchbran 28.5% 4 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 2 totaltotal 57.8% 44 / 76 CC 8 SCAR 19.1
CC
8
Cov
55%
from_position
20.0
new
5.3
BEGIN
1.0
CRAP 6.7
« Search/Image.pm ↑ Summary Search/Driver.pm »
1 package Imager::Search::Match;
2  
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Params::Util qw{ _POSINT _NONNEGINT _INSTANCE };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 $VERSION = '1.01';
11 }
12  
13 6 ▶use Object::Tiny::XS qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
14 name
15 top
16 bottom
17 left
18 right
19 height
20 width
21 center_x
22 center_y
23 6 };
24  
25  
26  
27  
28  
29 #####################################################################
30 # Constructor
31  
32 10 ▶sub new {
Subroutine new: called CC=5 SCAR=16.6
Pod undocumented
33 10 my $self = shift->SUPER::new(@_);
34  
35 # Temporary checks for the basic geometry
36 10 ▶ defined(_NONNEGINT($self->top)) or die "Missing or invalid top value";
Branch: 1 branch
BranchTrueFalseTotal
defined &_NONNEGINT(scalar $self->top) or die "Missing or invalid top value" 10 0 10
37 10 ▶ defined(_NONNEGINT($self->left)) or die "Missing or invalid left value";
Branch: 1 branch
BranchTrueFalseTotal
defined &_NONNEGINT(scalar $self->left) or die "Missing or invalid left value" 10 0 10
38 10 ▶ defined(_NONNEGINT($self->height)) or die "Missing or invalid height value";
Branch: 1 branch
BranchTrueFalseTotal
defined &_NONNEGINT(scalar $self->height) or die "Missing or invalid height value" 10 0 10
39 10 ▶ defined(_NONNEGINT($self->width)) or die "Missing or invalid width value";
Branch: 1 branch
BranchTrueFalseTotal
defined &_NONNEGINT(scalar $self->width) or die "Missing or invalid width value" 10 0 10
40  
41 # Assume that we've been provided the basic (top/left/height/width)
42 # geometry, and from that derive the rest.
43 10 $self->{bottom} = $self->top + $self->height - 1;
44 10 $self->{right} = $self->left + $self->width - 1;
45 10 $self->{center_x} = int( ($self->left + $self->right ) / 2 );
46 10 $self->{center_y} = int( ($self->top + $self->bottom) / 2 );
47  
48 10 return $self;
49 }
50  
51 0 ▶sub from_position {
Subroutine from_position: not called CC=4 SCAR=30.0
Pod undocumented
52 0 my $class = shift;
53 0 my $image = _INSTANCE(shift, 'Imager::Search::Image');
54 0 my $pattern = _INSTANCE(shift, 'Imager::Search::Pattern');
55 0 my $position = _NONNEGINT(shift);
56  
57 # Check params
58 0 ▶ unless ( $image ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($image) 0 0 0
59 0 Carp::croak("Failed to provide Imager::Search::Image param");
60 }
61 0 ▶ unless ( $pattern ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern) 0 0 0
62 0 Carp::croak("Failed to provide Imager::Search::Pattern param");
63 }
64 0 ▶ unless ( defined $position ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $position) 0 0 0
65 0 Carp::croak("Failed to provide position");
66 }
67  
68 # Derive additional values from the basic values
69 0 my $width = $pattern->width;
70 0 my $height = $pattern->height;
71 0 my $top = int($position / $image->width);
72 0 my $left = $position % $image->width;
73 0 my $bottom = $top + $height - 1;
74 0 my $right = $left + $width - 1;
75 0 my $center_x = int(($left + $right) / 2);
76 0 my $center_y = int(($top + $bottom) / 2);
77  
78 # Create the object
79 0 return $class->new(
80 left => $left,
81 right => $right,
82 top => $top,
83 bottom => $bottom,
84 height => $height,
85 width => $width,
86 center_x => $center_x,
87 center_y => $center_y,
88 );
89 }
90  
91 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
92 6 *centre_x = *center_x;
93 6 *centre_y = *center_y;
94 }
95  
96 6 1;
97  
98 __END__
« Search/Image.pm ↑ Summary Search/Driver.pm »