ProductsSyndication/ConfigData.pm

filter: Statementstmt 18.1% 8 / 44 Branchbran 4.5% 1 / 22 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 11.1% 1 / 9 Podpod 100% 8 / 8 totaltotal 19.1% 18 / 94 CC 15 SCAR 40.8
CC
15
Cov
12%
feature
110.0
write
42.0
config
2.0
CRAP 59.3
↑ Summary ProductsSyndication.pm »
1 package XML::Grammar::ProductsSyndication::ConfigData;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶my $arrayref = eval do {local $/; <DATA>}
Branch: 1 branch
BranchTrueFalseTotal
my $arrayref = eval do { local $/; readline DATA } or die "Couldn't load ConfigData data: $@" 5 0 5
4 or die "Couldn't load ConfigData data: $@";
5 5 close DATA;
6 5 my ($config, $features, $auto_features) = @$arrayref;
7  
8 0 ▶sub config { $config->{$_[1]} }
Subroutine config: not called CC=1 SCAR=6.9
Pod documented
9  
10 0 ▶sub set_config { $config->{$_[1]} = $_[2] }
Subroutine set_config: not called CC=1 SCAR=6.9
Pod documented
11 0 ▶sub set_feature { $features->{$_[1]} = 0+!!$_[2] } # Constrain to 1 or 0
Subroutine set_feature: not called CC=1 SCAR=6.9
Pod documented
12  
13 0 ▶sub auto_feature_names { sort grep !exists $features->{$_}, keys %$auto_features }
Subroutine auto_feature_names: not called CC=1 SCAR=6.9
Pod documented
14  
15 0 ▶sub feature_names {
Subroutine feature_names: not called CC=1 SCAR=6.9
Pod documented
16 0 my @features = (sort keys %$features, auto_feature_names());
17 0 @features;
18 }
19  
20 0 ▶sub config_names { sort keys %$config }
Subroutine config_names: not called CC=1 SCAR=6.9
Pod documented
21  
22 0 ▶sub write {
Subroutine write: not called CC=6 SCAR=37.4
Pod documented
23 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 ▶ open(my $fh, '+<', $me) or die "Can't rewrite $me: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $me or die "Can't rewrite ${me}: $!" 0 0 0
32 0 seek($fh, 0, 0);
33 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
34 0 ▶ last if /^__DATA__$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^__DATA__$/ 0 0 0
35 }
36 0 ▶ die "Couldn't find __DATA__ token in $me" if eof($fh);
Branch: 1 branch
BranchTrueFalseTotal
if eof $fh 0 0 0
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 ▶ chmod($mode_orig, $me)
Branch: 1 branch
BranchTrueFalseTotal
chmod $mode_orig, $me or warn "Couldn't restore permissions on ${me}: $!" 0 0 0
47 or warn "Couldn't restore permissions on $me: $!";
48 }
49  
50 0 ▶sub feature {
Subroutine feature: not called CC=10 SCAR=47.0
Pod documented
51 0 my ($package, $key) = @_;
52 0 ▶ return $features->{$key} if exists $features->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $features->{$key} 0 0 0
53  
54 0 ▶ my $info = $auto_features->{$key} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $auto_features->{$key} or return 0 0 0 0
55  
56 0 require Module::Build; # XXX should get rid of this
57 0 foreach my $type (sort keys %$info) {
58 0 my $prereqs = $info->{$type};
59 0 ▶ next if $type eq 'description' || $type eq 'recommends';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "description" or $type eq "recommends" 0 0 0
Condition0%0/3
$type eq "description" or $type eq "recommends"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "description" or $type eq "recommends"
$type eq "description" $type eq "recommends"
Truth table0%0/3
A or B
A= $type eq "description"B= $type eq "recommends"
ABresult
1X1
011
000
60  
61 0 foreach my $modname (sort keys %$prereqs) {
62 0 my $status = Module::Build->check_installed_status($modname, $prereqs->{$modname});
63 0 ▶ if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (not $status->{"ok"} xor $type =~ /conflicts$/) 0 0 0
Condition0%0/4
not $status->{"ok"} xor $type =~ /conflicts$/
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
not $status->{"ok"} xor $type =~ /conflicts$/
not $status->{"ok"} $type =~ /conflicts$/
Truth table0%0/4
not(A) xor B
A= not $status->{"ok"}B= $type =~ /conflicts$/
ABresult
110
101
011
000
64 0 ▶ if ( ! eval "require $modname; 1" ) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require $modname; 1") 0 0 0
65 }
66 }
67 0 return 1;
68 }
69  
70  
71 =head1 NAME
72  
73 XML::Grammar::ProductsSyndication::ConfigData - Configuration for XML::Grammar::ProductsSyndication
74  
75 =head1 SYNOPSIS
76  
77 use XML::Grammar::ProductsSyndication::ConfigData;
78 $value = XML::Grammar::ProductsSyndication::ConfigData->config('foo');
79 $value = XML::Grammar::ProductsSyndication::ConfigData->feature('bar');
80  
81 @names = XML::Grammar::ProductsSyndication::ConfigData->config_names;
82 @names = XML::Grammar::ProductsSyndication::ConfigData->feature_names;
83  
84 XML::Grammar::ProductsSyndication::ConfigData->set_config(foo => $new_value);
85 XML::Grammar::ProductsSyndication::ConfigData->set_feature(bar => $new_value);
86 XML::Grammar::ProductsSyndication::ConfigData->write; # Save changes
87  
88  
89 =head1 DESCRIPTION
90  
91 This module holds the configuration data for the C<XML::Grammar::ProductsSyndication>
92 module. It also provides a programmatic interface for getting or
93 setting that configuration data. Note that in order to actually make
94 changes, you'll have to have write access to the C<XML::Grammar::ProductsSyndication::ConfigData>
95 module, and you should attempt to understand the repercussions of your
96 actions.
97  
98  
99 =head1 METHODS
100  
101 =over 4
102  
103 =item config($name)
104  
105 Given a string argument, returns the value of the configuration item
106 by that name, or C<undef> if no such item exists.
107  
108 =item feature($name)
109  
110 Given a string argument, returns the value of the feature by that
111 name, or C<undef> if no such feature exists.
112  
113 =item set_config($name, $value)
114  
115 Sets the configuration item with the given name to the given value.
116 The value may be any Perl scalar that will serialize correctly using
117 C<Data::Dumper>. This includes references, objects (usually), and
118 complex data structures. It probably does not include transient
119 things like filehandles or sockets.
120  
121 =item set_feature($name, $value)
122  
123 Sets the feature with the given name to the given boolean value. The
124 value will be converted to 0 or 1 automatically.
125  
126 =item config_names()
127  
128 Returns a list of all the names of config items currently defined in
129 C<XML::Grammar::ProductsSyndication::ConfigData>, or in scalar context the number of items.
130  
131 =item feature_names()
132  
133 Returns a list of all the names of features currently defined in
134 C<XML::Grammar::ProductsSyndication::ConfigData>, or in scalar context the number of features.
135  
136 =item auto_feature_names()
137  
138 Returns a list of all the names of features whose availability is
139 dynamically determined, or in scalar context the number of such
140 features. Does not include such features that have later been set to
141 a fixed value.
142  
143 =item write()
144  
145 Commits any changes from C<set_config()> and C<set_feature()> to disk.
146 Requires write access to the C<XML::Grammar::ProductsSyndication::ConfigData> module.
147  
148 =back
149  
150  
151 =head1 AUTHOR
152  
153 C<XML::Grammar::ProductsSyndication::ConfigData> was automatically created using C<Module::Build>.
154 C<Module::Build> was written by Ken Williams, but he holds no
155 authorship claim or copyright claim to the contents of C<XML::Grammar::ProductsSyndication::ConfigData>.
156  
157 =cut
158  
159  
160 __DATA__
↑ Summary ProductsSyndication.pm »