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