Distribconf/MediaCFG.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 75.0% 12 / 16 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 80.2% 69 / 86 SCAR 24.5
CC
11
Cov
83%
_valid_param
7.3
__ANON__
6.0
__ANON__
4.0
CRAP 11.6
« Distribconf/Utils.pm ↑ Summary
1 package MDV::Distribconf::MediaCFG;
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 3 ▶use MDV::Distribconf;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = (qq$Revision: 224942 $ =~ /(\d+)/)[0];
8  
9 =head1 NAME
10  
11 MDV::Distribconf::MediaCFG
12  
13 =head1 DESCRIPTION
14  
15 This module provides documenation of known values in F<media.cfg>.
16  
17 =head1 MEDIACFG VERSION
18  
19 The media.cfg version is given by the 'mediacfg_version' in 'media_info'.
20 This value should be set is you want to use new features that can change the
21 behavior of this module.
22  
23 =head2 1
24  
25 This is the default and the first version of media.cfg format.
26  
27 =head2 2
28  
29 Since this version, all media paths are relative to the media_info path.
30 Previously, media paths were relative to media_info except when beginning with
31 F</>, which were relative to the root of the distrib.
32  
33 =head2 3
34  
35 This version allows to include in values variables that refer to
36 other values defined in the configuration file:
37  
38 =over 4
39  
40 =item ${...}
41  
42 refers to a global value (distribution version, arch...)
43  
44 =item %{...}
45  
46 refers to a value specific to the media (name, ...)
47  
48 =back
49  
50 =head1 VALUE
51  
52 =cut
53  
54 3 my $value = {};
55  
56 =head2 GLOBAL VALUES
57  
58 This value can only be set into 'media_info' section.
59  
60 =cut
61  
62 $value->{mediacfg_version} = {
63 validation => sub {
64 0 ▶ my ($val) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
65 0 ▶ if ($val !~ /^(\d|.)+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /^(\d|.)+$/) 0 0 0
66 0 return ("should be a number");
67 }
68 0 return ();
69 },
70 3 };
71  
72 =head3 mediacfg_version
73  
74 The version of the media_cfg
75  
76 See L<MEDIACFG VERSION>
77  
78 =cut
79  
80 3 $value->{version} = { section => 'media_info' };
81  
82 =head3 version
83  
84 The version of distrib
85  
86 =cut
87  
88 3 $value->{arch} = { section => 'media_info' };
89  
90 =head3 arch
91  
92 The arcitecture of the distribution
93  
94 =cut
95  
96 3 $value->{suppl} = { section => 'media_info' };
97  
98 =head3 suppl
99  
100 This tag is used to change installer behavior, when set, user should be allow
101 to add media not provided by this distribution.
102  
103 =cut
104  
105 3 $value->{askmedia} = { section => 'media_info' };
106  
107 =head3 askmedia
108  
109 This tag is used to change installer behavior, when set, user should be prompt
110 before adding each media.
111  
112 =cut
113  
114 3 $value->{branch} = { section => 'media_info' };
115  
116 =head3 branch
117  
118 The branch of the distribution.
119  
120 =cut
121  
122 3 $value->{product} = { section => 'media_info' };
123  
124 =head3 product
125  
126 The name of the product, 'Download' by default
127  
128 =cut
129  
130 3 $value->{minor} = { section => 'media_info' };
131  
132 =head3 minor
133  
134 No documentation
135  
136 =cut
137  
138 3 $value->{subversion} = { section => 'media_info' };
139  
140 =head3 subversion
141  
142 No documentation
143  
144 =cut
145  
146 =head2 MEDIA VALUES
147  
148 =cut
149  
150 3 foreach (qw(hdlist name synthesis pubkey)) {
151 12 $value->{$_} = { };
152 }
153  
154 =head3 name
155  
156 The name of the media. If unset, the section is the name.
157  
158 =head3 hdlist
159  
160 The hdlist file holding rpm infos for the media
161  
162 =head3 synthesis
163  
164 The synthesis file holding rpm infos for the media
165  
166 =head3 pubkey
167  
168 The file holding public gpg key used to sign rpms in this media.
169  
170 =cut
171  
172 3 $value->{srpms} = { deny => 'rpms', cross => 'rpms', ismedialist => 1 };
173  
174 =head3 srpms
175  
176 If the media hold binaries rpms, this parameter contains
177 the list of medias holding corresponding sources rpms.
178  
179 =cut
180  
181 3 $value->{rpms} = { deny => 'srpms', cross => 'srpms', ismedialist => 1 };
182  
183 =head3 rpms
184  
185 If the media hold sources rpms, this parameter contains
186 the list of media holding binaries rpms build by srpms from this media.
187  
188 =cut
189  
190 3 $value->{updates_for} = { ismedialist => 1 };
191  
192 =head3 updates_for
193  
194 If the media contain updates, it contain the list of media for which
195 rpms are updates.
196  
197 =cut
198  
199 3 $value->{debug_for} = { ismedialist => 1 };
200  
201 =head3 debug_for
202  
203 If the media contain debug rpms, it contain the list of media for which
204 rpms are debug rpms.
205  
206 =cut
207  
208 3 $value->{noauto} = {};
209  
210 =head3 noauto
211  
212 This value is used by tools to assume if the media should automatically
213 added to the config (urpmi).
214  
215 =cut
216  
217 $value->{size} = {
218 validation => sub {
219 4 ▶ my ($v) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
220 4 ▶ if ($v =~ /^(\d+)(\w)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^(\d+)(\w)?$/) { } 3 1 4
221 3 ▶ if ($2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 2 1 3
222 2 ▶ if (! grep { lc($2) eq $_ } qw(k m g t p)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {lc $2 eq $_;} "k", "m", "g", "t", "p") 1 1 2
223 1 return("wrong unit");
224 }
225 }
226 2 return;
227 } else {
228 1 return ("malformed value");
229 }
230 },
231 3 };
232  
233 =head3 size
234  
235 The size of the media. The value is suffixed by the unit.
236  
237 =cut
238  
239 # valid_param($media, $var, $val)
240 #
241 # Return a list of errors (if any) about having such value in the config
242  
243 sub _valid_param {
244 5 ▶ my ($media, $var, $val) = @_[-3..-1];
Subroutine _valid_param: called CC=6 SCAR=19.9
245 5 ▶ if (!exists($value->{$var})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $value->{$var}) 0 5 5
246 0 return ("unknow var");
247 }
248 5 ▶ $media ||= 'media_info'; # assume default
Condition50%1/2
$media ||= "media_info"
l!l
50
MC/DC0%0/1
$media ||= "media_info"
$media
Truth table50%1/2
A
A= $media
Aresult
11
00
249 5 my @errors;
250 5 ▶ if ($value->{$var}{section} && $value->{$var}{section} ne $media) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{$var}{"section"} and $value->{$var}{"section"} ne $media) 0 5 5
Condition33%1/3
$value->{$var}{"section"} and $value->{$var}{"section"} ne $media
!ll&&!rl&&r
500
MC/DC0%0/2
$value->{$var}{"section"} and $value->{$var}{"section"} ne $media
$value->{$var}{"section"} $value->{$var}{"section"} ne $media
Truth table33%1/3
A and B
A= $value->{$var}{"section"}B= $value->{$var}{"section"} ne $media
ABresult
0X0
100
111
251 0 push(@errors, "wrong section: should be in $value->{$var}{section}");
252 }
253 5 ▶ if ($value->{$var}{validation}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{$var}{"validation"}) 4 1 5
254 4 push(@errors, $value->{$var}{validation}->($val));
255 }
256 5 return @errors;
257 }
258  
259 # Retun a hash containing information about $var
260  
261 sub _value_info {
262 3 ▶ my ($var) = $_[-1];
Subroutine _value_info: called CC=2 SCAR=6.9
263 3 ▶ if (exists($value->{$var})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $value->{$var}) 1 2 3
264 1 return $value->{$var}
265 }
266 2 return;
267 }
268  
269 3 1;
270  
271 __END__
« Distribconf/Utils.pm ↑ Summary