File Coverage

blib/lib/Lego/Part.pm
Criterion Covered Total %
statement 33 33 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 8 8 100.0
pod 4 4 100.0
total 56 56 100.0


line stmt bran cond sub pod time code
1             package Lego::Part;
2              
3 6     6   234209 use strict;
  6         10  
  6         233  
4 6     6   59 use warnings;
  6         11  
  6         374  
5              
6 6     6   3212 use Class::Utils qw(set_params);
  6         74398  
  6         131  
7 6     6   483 use Error::Pure qw(err);
  6         13  
  6         2000  
8              
9             our $VERSION = 0.04;
10              
11             # Constructor.
12             sub new {
13 8     8 1 1298672 my ($class, @params) = @_;
14              
15             # Create object.
16 8         39 my $self = bless {}, $class;
17              
18             # Color.
19 8         37 $self->{'color'} = undef;
20              
21             # Lego design id.
22 8         49 $self->{'design_id'} = undef;
23              
24             # Lego element id.
25 8         19 $self->{'element_id'} = undef;
26              
27             # Process parameters.
28 8         42 set_params($self, @params);
29              
30             # Check design id or element id.
31 6 100 100     118 if (! defined $self->{'element_id'}
32             && ! defined $self->{'design_id'}) {
33              
34 1         6 err "Parameter 'element_id' or 'design_id' is required.";
35             }
36              
37             # Object.
38 5         24 return $self;
39             }
40              
41             # Get or set color.
42             sub color {
43 2     2 1 9 my ($self, $color) = @_;
44 2 100       9 if ($color) {
45 1         3 $self->{'color'} = $color;
46             }
47 2         13 return $self->{'color'};
48             }
49              
50             # Get or set lego design id.
51             sub design_id {
52 2     2 1 15 my ($self, $design_id) = @_;
53 2 100       8 if ($design_id) {
54 1         4 $self->{'design_id'} = $design_id;
55             }
56 2         13 return $self->{'design_id'};
57             }
58              
59             # Get or set lego element id.
60             sub element_id {
61 2     2 1 26 my ($self, $element_id) = @_;
62 2 100       7 if ($element_id) {
63 1         4 $self->{'element_id'} = $element_id;
64             }
65 2         11 return $self->{'element_id'};
66             }
67              
68             1;
69              
70             __END__