File Coverage

corpus/lib/Alien/Foo2/ConfigData.pm
Criterion Covered Total %
statement 4 40 10.0
branch 0 18 0.0
condition 0 7 0.0
subroutine 2 9 22.2
pod 0 8 0.0
total 6 82 7.3


line stmt bran cond sub pod time code
1             package Alien::Foo2::ConfigData;
2 1     1   5 use strict;
  1         3  
  1         527  
3             my $arrayref = eval do {local $/; }
4             or die "Couldn't load ConfigData data: $@";
5             close DATA;
6             my ($config, $features, $auto_features) = @$arrayref;
7              
8 19     19 0 78 sub config { $config->{$_[1]} }
9              
10 0     0 0   sub set_config { $config->{$_[1]} = $_[2] }
11 0     0 0   sub set_feature { $features->{$_[1]} = 0+!!$_[2] } # Constrain to 1 or 0
12              
13 0     0 0   sub auto_feature_names { grep !exists $features->{$_}, keys %$auto_features }
14              
15             sub feature_names {
16 0     0 0   my @features = (keys %$features, auto_feature_names());
17 0           @features;
18             }
19              
20 0     0 0   sub config_names { keys %$config }
21              
22             sub write {
23 0     0 0   my $me = __FILE__;
24              
25             # Can't use Module::Build::Dumper here because M::B is only a
26             # build-time prereq of this module
27 0           require Data::Dumper;
28              
29 0           my $mode_orig = (stat $me)[2] & 07777;
30 0           chmod($mode_orig | 0222, $me); # Make it writeable
31 0 0         open(my $fh, '+<', $me) or die "Can't rewrite $me: $!";
32 0           seek($fh, 0, 0);
33 0           while (<$fh>) {
34 0 0         last if /^__DATA__$/;
35             }
36 0 0         die "Couldn't find __DATA__ token in $me" if eof($fh);
37              
38 0           seek($fh, tell($fh), 0);
39 0           my $data = [$config, $features, $auto_features];
40 0           print($fh 'do{ my '
41             . Data::Dumper->new([$data],['x'])->Purity(1)->Dump()
42             . '$x; }' );
43 0           truncate($fh, tell($fh));
44 0           close $fh;
45              
46 0 0         chmod($mode_orig, $me)
47             or warn "Couldn't restore permissions on $me: $!";
48             }
49              
50             sub feature {
51 0     0 0   my ($package, $key) = @_;
52 0 0         return $features->{$key} if exists $features->{$key};
53              
54 0 0         my $info = $auto_features->{$key} or return 0;
55              
56             # Under perl 5.005, each(%$foo) isn't working correctly when $foo
57             # was reanimated with Data::Dumper and eval(). Not sure why, but
58             # copying to a new hash seems to solve it.
59 0           my %info = %$info;
60              
61 0           require Module::Build; # XXX should get rid of this
62 0           while (my ($type, $prereqs) = each %info) {
63 0 0 0       next if $type eq 'description' || $type eq 'recommends';
64              
65 0           my %p = %$prereqs; # Ditto here.
66 0           while (my ($modname, $spec) = each %p) {
67 0           my $status = Module::Build->check_installed_status($modname, $spec);
68 0 0 0       if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; }
  0            
69 0 0         if ( ! eval "require $modname; 1" ) { return 0; }
  0            
70             }
71             }
72 0           return 1;
73             }
74              
75             __DATA__