| 1 | package Enbld::Config; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | require Enbld::Exception; | |||||||||
| 9 | |||||||||||
| 10 | 47 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 11 | 47 | my $class = shift; | |||||||||
| 12 | |||||||||||
| 13 | 47 | my $self = { | |||||||||
| 14 | name => undef, | ||||||||||
| 15 | enabled => undef, | ||||||||||
| 16 | installed => {}, | ||||||||||
| 17 | @_, | ||||||||||
| 18 | }; | ||||||||||
| 19 | |||||||||||
| 20 | 47 | bless $self, $class; | |||||||||
| 21 | |||||||||||
| 22 | 47 | return $self; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 22 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 26 | 22 | return $_[0]->{name}; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 4 | ▶ | sub installed { | ||||||||
|
Subroutine
installed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 4 | return $_[0]->{installed}; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 29 | ▶ | sub condition { | ||||||||
|
Subroutine
condition: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 34 | 29 | my ( $self, $version ) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 29 | require Enbld::Condition; | |||||||||
| 37 | |||||||||||
| 38 | 29 | ▶ | if ( ! $version ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | return Enbld::Condition->new( | ||||||||||
| 40 | 25 | %{ $self->{installed}{$self->enabled} } | |||||||||
| 41 | ); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 4 | ▶ | if ( exists $self->{installed}{$version} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | return Enbld::Condition->new( | ||||||||||
| 46 | 3 | %{ $self->{installed}{$version} } | |||||||||
| 47 | ); | ||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 1 | return; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 7 | ▶ | sub is_installed_version { | ||||||||
|
Subroutine
is_installed_version: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 54 | 7 | my ( $self, $version ) = @_; | |||||||||
| 55 | |||||||||||
| 56 | 7 | ▶ | return unless $version; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 6 | ▶ | return unless keys %{ $self->{installed} }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 5 | ▶ | return $version if ( exists $self->{installed}{$version} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | 2 | return; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 98 | ▶ | sub enabled { | ||||||||
|
Subroutine
enabled: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 65 | 98 | return $_[0]->{enabled}; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 2 | ▶ | sub drop_enabled { | ||||||||
|
Subroutine
drop_enabled: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 69 | 2 | my $self = shift; | |||||||||
| 70 | |||||||||||
| 71 | 2 | return ( $self->{enabled} = undef ); | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 48 | ▶ | sub set_enabled { | ||||||||
|
Subroutine
set_enabled: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 75 | 48 | my ( $self, $version, $condition ) = @_; | |||||||||
| 76 | |||||||||||
| 77 | 48 | $self->{enabled} = $version; | |||||||||
| 78 | 48 | $self->{installed}{$version} = $condition->serialize; | |||||||||
| 79 | |||||||||||
| 80 | 48 | return $self->{enabled}; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | ▶ | sub serialize { | ||||||||
|
Subroutine
serialize: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 84 | 1 | my $self = shift; | |||||||||
| 85 | |||||||||||
| 86 | 1 | my $serialized; | |||||||||
| 87 | 1 | foreach my $key ( sort keys %{ $self } ) { | |||||||||
| 88 | 3 | $serialized->{$key} = $self->{$key}; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 1 | return $serialized; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 3 | ▶ | sub DSL { | ||||||||
|
Subroutine
DSL: called CC=6 SCAR=18.6
Pod
undocumented
| |||||||||||
| 95 | 3 | my $self = shift; | |||||||||
| 96 | |||||||||||
| 97 | 3 | my @config; | |||||||||
| 98 | |||||||||||
| 99 | 3 | require Enbld::Feature; | |||||||||
| 100 | 3 | ▶ | my $version = Enbld::Feature->is_current_mode ? | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | $self->enabled : $self->condition->version; | ||||||||||
| 102 | |||||||||||
| 103 | 3 | push @config, "target '" . $self->name . "' => define {\n"; | |||||||||
| 104 | 3 | push @config, " version '". $version . "';\n"; | |||||||||
| 105 | 3 | ▶ | if ( $self->condition->make_test ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 1 | push @config, " make_test '" . $self->condition->make_test . "';\n"; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 3 | ▶ | if ( $self->condition->arguments ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | push @config, " arguments '" . $self->condition->arguments . "';\n"; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 3 | ▶ | if ( $self->condition->annotation ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | push @config, " annotation '" . $self->condition->annotation ."';\n"; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 3 | ▶ | if ( $self->condition->module_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 0 | push @config, " module_file '" . $self->condition->module_file ."';\n"; | |||||||||
| 119 | |||||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 3 | push @config, "};\n"; | |||||||||
| 123 | |||||||||||
| 124 | 3 | return \@config; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 3 | 1; | |||||||||