blib/lib/SVG/Estimate/Line.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 51 CC 7 SCAR 39.0
CC
7
Cov
0%
BUILDARGS
56.0
BEGIN
2.0
CRAP 49.2
1 package SVG::Estimate::Line;
2 $SVG::Estimate::Line::VERSION = '1.0111';
3 use Moo;
4  
5 extends 'SVG::Estimate::Shape';
6 with 'SVG::Estimate::Role::Pythagorean';
7  
8 =head1 NAME
9  
10 SVG::Estimate::Line - Handles estimating straight lines.
11  
12 =head1 VERSION
13  
14 version 1.0111
15  
16 =head1 SYNOPSIS
17  
18 my $line = SVG::Estimate::Line->new(
19 transformer => $transform,
20 start_point => [45,13],
21 x1 => 1,
22 y1 => 3,
23 x2 => 4.6,
24 y2 => 3,
25 );
26  
27 my $length = $line->length;
28  
29 =head1 INHERITANCE
30  
31 This class extends L<SVG::Estimate::Shape> and consumes L<SVG::Estimate::Role::Pythagorean>.
32  
33 =head1 METHODS
34  
35 =head2 new()
36  
37 Constructor.
38  
39 =over
40  
41 =item x1
42  
43 Float representing the x start point.
44  
45 =item y1
46  
47 Float representing the y start point.
48  
49 =item x2
50  
51 Float representing the x end point.
52  
53 =item y2
54  
55 Float representing the y end point.
56  
57 =back
58  
59 =cut
60  
61 has x1 => (
62 is => 'ro',
63 default => sub { 0 },
64 );
65  
66 has y1 => (
67 is => 'ro',
68 default => sub { 0 },
69 );
70  
71 has x2 => (
72 is => 'ro',
73 default => sub { 0 },
74 );
75  
76 has y2 => (
77 is => 'ro',
78 default => sub { 0 },
79 );
80  
81 sub BUILDARGS {
82 my ($class, @args) = @_;
83 ##Upgrade to hashref
84 my $args = @args % 2 ? $args[0] : { @args };
85 foreach my $arg (qw(x1 x2 y1 y2)) {
86 $args->{$arg} //= 0;
87 }
88 return $args unless exists $args->{transformer};
89 my $point1 = $args->{transformer}->transform([$args->{x1}, $args->{y1}]);
90 my $point2 = $args->{transformer}->transform([$args->{x2}, $args->{y2}]);
91 $args->{x1} = $point1->[0];
92 $args->{y1} = $point1->[1];
93 $args->{x2} = $point2->[0];
94 $args->{y2} = $point2->[1];
95 $args->{draw_start} = $point1;
96 $args->{draw_end} = $point2;
97 $args->{min_y} = $args->{y1} < $args->{y2} ? $args->{y1} : $args->{y2};
98 $args->{max_y} = $args->{y1} > $args->{y2} ? $args->{y1} : $args->{y2};
99 $args->{min_x} = $args->{x1} < $args->{x2} ? $args->{x1} : $args->{x2};
100 $args->{max_x} = $args->{x1} > $args->{x2} ? $args->{x1} : $args->{x2};
101 $args->{shape_length} = $class->pythagorean($point1, $point2);
102 return $args;
103 }
104  
105 1;