File Coverage

blib/lib/Enbld/Condition.pm
Criterion Covered Total %
statement 33 34 97.0
branch 13 16 81.2
condition 8 9 88.8
subroutine 11 12 91.6
pod 0 9 0.0
total 65 80 81.2


line stmt bran cond sub pod time code
1             package Enbld::Condition;
2              
3 5     5   1742 use strict;
  5         11  
  5         207  
4 5     5   25 use warnings;
  5         9  
  5         2659  
5              
6             sub new {
7 86     86 0 26478 my $class = shift;
8              
9 86         708 my $self = {
10             version => 'latest',
11             make_test => undef,
12             module_file => undef,
13             arguments => undef,
14             annotation => undef,
15             @_,
16             };
17              
18 86         216 bless $self, $class;
19              
20 86         343 return $self;
21             }
22              
23 0     0 0 0 sub name { return $_[0]->{name} }
24 34     34 0 201 sub version { return $_[0]->{version} }
25 39     39 0 2065 sub make_test { return $_[0]->{make_test} }
26 34     34 0 452 sub module_file { return $_[0]->{module_file} }
27 35     35 0 809 sub arguments { return $_[0]->{arguments} }
28 6     6 0 20 sub annotation { return $_[0]->{annotation} }
29              
30             sub serialize {
31 50     50 0 95 my $self = shift;
32              
33 50         85 my %serialized;
34 50         88 foreach my $key ( sort keys %{ $self } ) {
  50         801  
35 254 100       581 next if ( ! $self->{$key} );
36              
37 56         349 $serialized{$key} = $self->{$key};
38             }
39              
40 50         377 return \%serialized;
41             }
42              
43             sub is_equal_to {
44 8     8 0 31 my ( $self, $condition ) = @_;
45              
46 8 100       35 return unless _is_equal( $self->{version}, $condition->version );
47 5 100       18 return unless _is_equal( $self->{make_test}, $condition->make_test );
48 3 50       15 return unless _is_equal( $self->{arguments}, $condition->arguments );
49 3 50       11 return unless _is_equal( $self->{annotation}, $condition->annotation );
50 3 50       14 return unless _is_equal( $self->{module_file}, $condition->module_file );
51              
52 3         18 return $self;
53             }
54              
55             sub _is_equal {
56 22     22   39 my ( $val1, $val2 ) = @_;
57              
58 22 100 66     108 return 1 if ( ( ! defined $val1 ) && ( ! defined $val2 ) );
59 11 100 100     117 return 1 if ( ( defined $val1 && defined $val2 ) && ( $val1 eq $val2 ));
      100        
60              
61 5         37 return;
62             }
63              
64             1;