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   1586 use strict;
  5         6  
  5         167  
4 5     5   17 use warnings;
  5         8  
  5         1619  
5              
6             sub new {
7 86     86 0 15392 my $class = shift;
8              
9 86         416 my $self = {
10             version => 'latest',
11             make_test => undef,
12             module_file => undef,
13             arguments => undef,
14             annotation => undef,
15             @_,
16             };
17              
18 86         179 bless $self, $class;
19              
20 86         249 return $self;
21             }
22              
23 0     0 0 0 sub name { return $_[0]->{name} }
24 34     34 0 153 sub version { return $_[0]->{version} }
25 39     39 0 1019 sub make_test { return $_[0]->{make_test} }
26 34     34 0 343 sub module_file { return $_[0]->{module_file} }
27 35     35 0 158 sub arguments { return $_[0]->{arguments} }
28 6     6 0 16 sub annotation { return $_[0]->{annotation} }
29              
30             sub serialize {
31 50     50 0 78 my $self = shift;
32              
33 50         93 my %serialized;
34 50         67 foreach my $key ( sort keys %{ $self } ) {
  50         465  
35 254 100       475 next if ( ! $self->{$key} );
36              
37 56         232 $serialized{$key} = $self->{$key};
38             }
39              
40 50         296 return \%serialized;
41             }
42              
43             sub is_equal_to {
44 8     8 0 22 my ( $self, $condition ) = @_;
45              
46 8 100       20 return unless _is_equal( $self->{version}, $condition->version );
47 5 100       13 return unless _is_equal( $self->{make_test}, $condition->make_test );
48 3 50       14 return unless _is_equal( $self->{arguments}, $condition->arguments );
49 3 50       443 return unless _is_equal( $self->{annotation}, $condition->annotation );
50 3 50       9 return unless _is_equal( $self->{module_file}, $condition->module_file );
51              
52 3         16 return $self;
53             }
54              
55             sub _is_equal {
56 22     22   61 my ( $val1, $val2 ) = @_;
57              
58 22 100 66     72 return 1 if ( ( ! defined $val1 ) && ( ! defined $val2 ) );
59 11 100 100     85 return 1 if ( ( defined $val1 && defined $val2 ) && ( $val1 eq $val2 ));
      100        
60              
61 5         32 return;
62             }
63              
64             1;