« blib/lib/Alien/Build/Plugin/Digest/SHA.pm
↑ Summary
blib/lib/Alien/Build/Plugin/Build/Autoconf.pm »
| 1 | package Alien::Build::Interpolate; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Advanced interpolation engine for Alien builds | ||||||||||||||||||||||||||||
| 8 | 13 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||||||||||
| 12 | 64 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 64 | my($class) = @_; | |||||||||||||||||||||||||||
| 14 | 64 | my $self = bless { | |||||||||||||||||||||||||||
| 15 | helper => {}, | ||||||||||||||||||||||||||||
| 16 | classes => {}, | ||||||||||||||||||||||||||||
| 17 | }, $class; | ||||||||||||||||||||||||||||
| 18 | 64 | $self; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub add_helper | ||||||||||||||||||||||||||||
| 23 | 1433 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_helper: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 1433 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | 1433 | my $name = shift; | |||||||||||||||||||||||||||
| 26 | 1433 | my $code = shift; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1433 | ▶ | if(defined $self->{helper}->{$name}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 1 | require Carp; | |||||||||||||||||||||||||||
| 31 | 1 | Carp::croak("duplicate implementation for interpolated key $name"); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1432 | my $require; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1432 | ▶ | if(ref $_[0] eq 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 422 | $require = shift; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else | ||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 1010 | $require = []; | |||||||||||||||||||||||||||
| 43 | 1010 | ▶ | while(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 789 | my $module = shift; | |||||||||||||||||||||||||||
| 46 | 789 | my $version = shift; | |||||||||||||||||||||||||||
| 47 | 789 | ▶ | $version ||= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$version ||= 0
MC/DC100%1/1
$version ||= 0
$version
Truth table100%2/2
A
A= $version
| |||||||||||||||||||||||||||||
| 48 | 789 | push @$require, $module => $version; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1432 | $self->{helper}->{$name} = Alien::Build::Helper->new( | |||||||||||||||||||||||||||
| 53 | $name, | ||||||||||||||||||||||||||||
| 54 | $code, | ||||||||||||||||||||||||||||
| 55 | $require, | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub replace_helper | ||||||||||||||||||||||||||||
| 61 | 22 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
replace_helper: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 22 | my($name) = @_; | |||||||||||||||||||||||||||
| 64 | 22 | delete $self->{helper}->{$name}; | |||||||||||||||||||||||||||
| 65 | 22 | $self->add_helper(@_); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub has_helper | ||||||||||||||||||||||||||||
| 70 | 69 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
has_helper: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 69 | my($self, $name) = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 69 | ▶ | return unless defined $self->{helper}->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 63 | my @require = $self->{helper}->{$name}->require; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 63 | ▶ | while(@require) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 15 | my $module = shift @require; | |||||||||||||||||||||||||||
| 80 | 15 | my $version = shift @require; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 15 | my $pm = "$module.pm"; | |||||||||||||||||||||||||||
| 84 | 15 | $pm =~ s/::/\//g; | |||||||||||||||||||||||||||
| 85 | 15 | require $pm; | |||||||||||||||||||||||||||
| 86 | 14 | ▶ | $module->VERSION($version) if $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 13 | ▶ | unless($self->{classes}->{$module}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 6 | ▶ | if($module->can('alien_helper')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 1 | my $helpers = $module->alien_helper; | |||||||||||||||||||||||||||
| 94 | 1 | foreach my $k (keys %$helpers) | |||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 2 | $self->{helper}->{$k}->code($helpers->{$k}); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 6 | $self->{classes}->{$module} = 1; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 61 | my $code = $self->{helper}->{$name}->code; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 61 | ▶ | return unless defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 61 | ▶ | if(ref($code) ne 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 7 | my $perl = $code; | |||||||||||||||||||||||||||
| 110 | package Alien::Build::Interpolate::Helper; | ||||||||||||||||||||||||||||
| 111 | 4 | ▶ | $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 112 | ## no critic | ||||||||||||||||||||||||||||
| 113 | 4 | my $value = eval $perl; | |||||||||||||||||||||||||||
| 114 | ## use critic | ||||||||||||||||||||||||||||
| 115 | 4 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 4 | $value; | |||||||||||||||||||||||||||
| 117 | 7 | }; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 61 | $code; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub execute_helper | ||||||||||||||||||||||||||||
| 125 | 58 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
execute_helper: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 58 | my($self, $name) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 58 | my $code = $self->has_helper($name); | |||||||||||||||||||||||||||
| 129 | 56 | ▶ | die "no helper defined for $name" unless defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 52 | $code->(); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub _get_prop | ||||||||||||||||||||||||||||
| 136 | 38 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_get_prop: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 137 | 38 | my($name, $prop, $orig) = @_; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 38 | $name =~ s/^\./alien./; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 38 | ▶ | if($name =~ /^(.*?)\.(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | 27 | my($key,$rest) = ($1,$2); | |||||||||||||||||||||||||||
| 144 | 27 | return _get_prop($rest, $prop->{$key}, $orig); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | elsif(exists $prop->{$name}) | ||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||
| 148 | 10 | return $prop->{$name}; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | else | ||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||
| 152 | 1 | require Carp; | |||||||||||||||||||||||||||
| 153 | 1 | Carp::croak("No property $orig is defined"); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub interpolate | ||||||||||||||||||||||||||||
| 158 | 118 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
interpolate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 118 | my($self, $string, $build) = @_; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 118 | ▶ | my $prop = defined $build && eval { $build->isa('Alien::Build') } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $build and eval {
do {
$build->isa("Alien::Build")
}
}
MC/DC100%2/2
defined $build and eval {
do {
$build->isa("Alien::Build")
}
}
defined $build
eval {
do {
$build->isa("Alien::Build")
}
}
Truth table100%3/3
A and B
A= defined $buildB= eval {
do {
$build->isa("Alien::Build")
}
}
| |||||||||||||||||||||||||||||
| 162 | ? $build->_command_prop | ||||||||||||||||||||||||||||
| 163 | : {}; | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 118 | $string =~ s{(?<!\%)\%\{([a-zA-Z_][a-zA-Z_0-9]+)\}}{$self->execute_helper($1)}eg; | |||||||||||||||||||||||||||
| 166 | 112 | $string =~ s{(?<!\%)\%\{([a-zA-Z_\.][a-zA-Z_0-9\.]+)\}}{_get_prop($1,$prop,$1)}eg; | |||||||||||||||||||||||||||
| 167 | 111 | $string =~ s/\%(?=\%)//g; | |||||||||||||||||||||||||||
| 168 | 111 | $string; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | sub requires | ||||||||||||||||||||||||||||
| 173 | 227 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
requires: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 227 | my($self, $string) = @_; | |||||||||||||||||||||||||||
| 175 | map { | ||||||||||||||||||||||||||||
| 176 | 227 | my $helper = $self->{helper}->{$_}; | |||||||||||||||||||||||||||
| 177 | 56 | ▶ | $helper ? $helper->require : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | } $string =~ m{(?<!\%)\%\{([a-zA-Z_][a-zA-Z_0-9]+)\}}g; | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | sub clone | ||||||||||||||||||||||||||||
| 183 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | require Storable; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 1 | my %helper; | |||||||||||||||||||||||||||
| 189 | 1 | foreach my $name (keys %{ $self->{helper} }) | |||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||
| 191 | 1 | $helper{$name} = $self->{helper}->{$name}->clone; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | my $new = bless { | ||||||||||||||||||||||||||||
| 195 | helper => \%helper, | ||||||||||||||||||||||||||||
| 196 | 1 | classes => Storable::dclone($self->{classes}), | |||||||||||||||||||||||||||
| 197 | }, ref $self; | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | package Alien::Build::Helper; | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub new | ||||||||||||||||||||||||||||
| 203 | 1433 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 204 | 1433 | my($class, $name, $code, $require) = @_; | |||||||||||||||||||||||||||
| 205 | 1433 | bless { | |||||||||||||||||||||||||||
| 206 | name => $name, | ||||||||||||||||||||||||||||
| 207 | code => $code, | ||||||||||||||||||||||||||||
| 208 | require => $require, | ||||||||||||||||||||||||||||
| 209 | }, $class; | ||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 1 | ▶ | sub name { shift->{name} } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | sub code | ||||||||||||||||||||||||||||
| 215 | 66 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
code: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 216 | 66 | my($self, $code) = @_; | |||||||||||||||||||||||||||
| 217 | 66 | ▶ | $self->{code} = $code if $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 66 | $self->{code}; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | sub require | ||||||||||||||||||||||||||||
| 222 | 119 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
require: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 223 | 119 | my($self) = @_; | |||||||||||||||||||||||||||
| 224 | 119 | ▶ | if(ref $self->{require} eq 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||
| 226 | 4 | $self->{require} = [ $self->{require}->($self) ]; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 119 | @{ $self->{require} }; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | sub clone | ||||||||||||||||||||||||||||
| 232 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 233 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 234 | 1 | my $class = ref $self; | |||||||||||||||||||||||||||
| 235 | 1 | $class->new( | |||||||||||||||||||||||||||
| 236 | $self->name, | ||||||||||||||||||||||||||||
| 237 | $self->code, | ||||||||||||||||||||||||||||
| 238 | [ $self->require ], | ||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 13 | 1; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | __END__ | ||||||||||||||||||||||||||||