File Coverage

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


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