blib/lib/Shape/RegularPolygon.pm

filter: Statementstmt 100% 44 / 44 Branchbran 81.2% 13 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 83.3% 5 / 6 totaltotal 92.5% 75 / 81 CC 11 SCAR 9.3
CC
11
Cov
94%
new
4.1
sides
3.0
center
3.0
CRAP 2.5
↑ Summary
1 package Shape::RegularPolygon;
2  
3 1 ▶use 5.008006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Exporter;
10  
11 1 our @ISA = qw(Exporter);
12 1 our @EXPORT = qw();
13  
14 1 our $VERSION = '0.01';
15  
16  
17 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.1
Pod undocumented
18 4 my $class = shift;
19 4 my %params = @_;
20  
21 4 my $self = {CenterX => 0,
22 CenterY => 0,
23 Sides => 3,
24 Radius => 50,
25 Angle => 0.0,
26 };
27  
28 4 foreach my $name (keys %params) {
29 10 ▶ $self->{$name} = $params{$name} if exists $self->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$name} 10 0 10
30 }
31  
32 4 ▶ ($self->{Sides} >= 3) or die "Sides is too small.";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"Sides"} >= 3 or die "Sides is too small." 4 0 4
33  
34 4 bless($self, $class);
35 }
36  
37 5 ▶sub center {
Subroutine center: called CC=3 SCAR=11.0
Pod documented
38 5 my ($self, $x, $y) = @_;
39 return ($self->{CenterX}, $self->{CenterY})
40 5 ▶ if !defined $x || !defined $y;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x and defined $y 3 2 5
Condition66%2/3
defined $x and defined $y
!ll&&!rl&&r
302
MC/DC50%1/2
defined $x and defined $y
defined $x defined $y
Truth table66%2/3
A and B
A= defined $xB= defined $y
ABresult
0X0
100
111
41 2 $self->{CenterX} = $x;
42 2 $self->{CenterY} = $y;
43 }
44 5 ▶sub sides {
Subroutine sides: called CC=3 SCAR=11.0
Pod documented
45 5 my ($self, $sides) = @_;
46 5 ▶ return $self->{Sides} if not defined $sides;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sides 3 2 5
47  
48 2 ▶ ($sides >= 3) or die "Sides is too smaill.";
Branch: 1 branch
BranchTrueFalseTotal
$sides >= 3 or die "Sides is too smaill." 2 0 2
49 2 $self->{Sides} = $sides;
50 }
51 5 ▶sub radius {
Subroutine radius: called CC=2 SCAR=6.9
Pod documented
52 5 my ($self, $radius) = @_;
53 5 ▶ return $self->{Radius} if not defined $radius;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $radius 3 2 5
54 2 $self->{Radius} = $radius;
55 }
56 5 ▶sub angle {
Subroutine angle: called CC=2 SCAR=6.9
Pod documented
57 5 my ($self, $angle) = @_;
58 5 ▶ return $self->{Angle} if not defined $angle;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $angle 3 2 5
59 2 $self->{Angle} = $angle;
60 }
61  
62 2 ▶sub points {
Subroutine points: called CC=2 SCAR=6.9
Pod documented
63 2 my ($self) = @_;
64  
65 2 my @points;
66  
67 2 my $rad = - pi / 2 + $self->{Angle}; # -90 degree
68 2 ▶ for (my $i = 0 ; $i < $self->{Sides} ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"Sides"}) 10 2 12
69 push @points, {x => cos($rad) * $self->{Radius} + $self->{CenterX},
70 10 y => sin($rad) * $self->{Radius} + $self->{CenterY}};
71  
72 10 $rad += pi * 2 / $self->{Sides};
73 }
74  
75 2 return @points;
76 }
77  
78 1 1;
79 __END__
↑ Summary