File Coverage

blib/lib/Lego/Part/Action.pm
Criterion Covered Total %
statement 18 40 45.0
branch 0 6 0.0
condition 0 3 0.0
subroutine 6 10 60.0
pod 3 3 100.0
total 27 62 43.5


line stmt bran cond sub pod time code
1             package Lego::Part::Action;
2              
3             # Pragmas.
4 3     3   23100 use strict;
  3         6  
  3         98  
5 3     3   11 use warnings;
  3         3  
  3         80  
6              
7             # Modules.
8 3     3   1442 use Class::Utils qw(set_params);
  3         58794  
  3         59  
9 3     3   180 use English;
  3         5  
  3         18  
10 3     3   1389 use Error::Pure qw(err);
  3         5  
  3         110  
11 3     3   13 use Scalar::Util qw(blessed);
  3         3  
  3         809  
12              
13             # Version.
14             our $VERSION = 0.01;
15              
16             # Constructor.
17             sub new {
18 0     0 1   my ($class, @params) = @_;
19              
20             # Create object.
21 0           my $self = bless {}, $class;
22              
23             # Process parameters.
24 0           set_params($self, @params);
25              
26             # Object.
27 0           return $self;
28             }
29              
30             # Load design id to Lego::Part object.
31             sub load_design_id {
32 0     0 1   my ($self, $part_transfer_class, $part) = @_;
33 0           $self->_check_part_transfer_class($part_transfer_class);
34 0           eval {
35 0           $part_transfer_class->element2design($part);
36             };
37 0 0         if ($EVAL_ERROR) {
38 0           err 'Cannot load design ID.',
39             'Error', $EVAL_ERROR;
40             }
41 0           return;
42             }
43              
44             # Load element id to Lego::Part object.
45             sub load_element_id {
46 0     0 1   my ($self, $part_transfer_class, $part) = @_;
47 0           $self->_check_part_transfer_class($part_transfer_class);
48 0           eval {
49 0           $part_transfer_class->design2element($part);
50             };
51 0 0         if ($EVAL_ERROR) {
52 0           err 'Cannot load element ID.',
53             'Error', $EVAL_ERROR;
54             }
55 0           return;
56             }
57              
58             # Check transfer class.
59             sub _check_part_transfer_class {
60 0     0     my ($self, $part_transfer_class) = @_;
61 0 0 0       if (! blessed($part_transfer_class)
62             || ! $part_transfer_class->isa('Lego::Part::Transfer')) {
63              
64 0           err "Bad transfer class. Must be 'Lego::Part::Transfer' ".
65             'class.';
66             }
67 0           return;
68             }
69              
70             1;
71              
72             __END__