blib/lib/RPM/Specfile.pm

filter: Statementstmt 66.6% 260 / 390 Branchbran 56.7% 67 / 118 Conditioncond 54.5% 24 / 44 MC/DCmcdc 20.8% 5 / 24 Subroutinesub 77.9% 46 / 59 Podpod 98.1% 54 / 55 totaltotal 66.0% 456 / 690 CC 90 SCAR 22.3
CC
90
Cov
64%
generate_specfile
36.6
buildrequire
7.0
changelog
7.0
CRAP 9.3
↑ Summary
1 package RPM::Specfile;
2  
3 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $VERSION = '1.51';
10  
11 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 1 my $class = shift;
13  
14 1 my $self = bless { }, $class;
15  
16 1 return $self;
17 }
18  
19 1 my @simple_accessors =
20 qw(
21 build buildarch buildrequires buildroot check clean description distribution
22 epoch file_param group install license macros name packager post postun
23 pre preun prep release requires summary url vendor version
24 );
25  
26 1 foreach my $field (@simple_accessors) {
27 27 my $sub = q {
28 sub RPM::Specfile::[[field]] {
29 my $self = shift;
30 if (@_) {
31 my $value = shift;
32 $self->{__[[field]]__} = $value;
33 }
34 return $self->{__[[field]]__};
35 }
36 };
37  
38 27 $sub =~ s/\[\[field\]\]/$field/g;
39 0 ▶ eval $sub;
Subroutine build: called CC=2 SCAR=7.0
Subroutine buildarch: called CC=2 SCAR=7.0
Subroutine buildrequires: called CC=2 SCAR=7.0
Subroutine buildroot: called CC=2 SCAR=7.0
Subroutine check: called CC=2 SCAR=7.0
Subroutine clean: called CC=2 SCAR=7.0
Subroutine description: called CC=2 SCAR=7.0
Subroutine distribution: called CC=2 SCAR=7.0
Subroutine epoch: called CC=2 SCAR=7.0
Subroutine file_param: called CC=2 SCAR=7.0
Subroutine group: called CC=2 SCAR=7.0
Subroutine install: called CC=2 SCAR=7.0
Subroutine license: called CC=2 SCAR=7.0
Subroutine macros: called CC=2 SCAR=7.0
Subroutine name: called CC=2 SCAR=7.0
Subroutine packager: called CC=2 SCAR=7.0
Subroutine post: called CC=2 SCAR=7.0
Subroutine postun: called CC=2 SCAR=7.0
Subroutine pre: called CC=2 SCAR=7.0
Subroutine prep: called CC=2 SCAR=7.0
Subroutine preun: called CC=2 SCAR=7.0
Subroutine release: called CC=2 SCAR=7.0
Subroutine requires: called CC=2 SCAR=7.0
Subroutine summary: called CC=2 SCAR=7.0
Subroutine url: called CC=2 SCAR=7.0
Subroutine vendor: called CC=2 SCAR=7.0
Subroutine version: called CC=2 SCAR=7.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 27 branches
BranchTrueFalseTotal
if (@_) 1 2 3
if (@_) 0 1 1
if (@_) 0 1 1
if (@_) 1 3 4
if (@_) 0 1 1
if (@_) 0 1 1
if (@_) 1 2 3
if (@_) 0 1 1
if (@_) 0 1 1
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 0 1 1
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 2 3 5
if (@_) 1 2 3
if (@_) 1 2 3
if (@_) 0 1 1
if (@_) 0 1 1
if (@_) 0 1 1
if (@_) 0 1 1
if (@_) 1 2 3
40  
41 27 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 27 27
42 0 die $@;
43 }
44 }
45  
46 1 my @array_accessors = qw/source patch changelog provide require file buildrequire prefix/;
47  
48 1 foreach my $field (@array_accessors) {
49 8 my $sub = q {
50 sub RPM::Specfile::[[field]] {
51 my $self = shift;
52 $self->{__[[field]]__} ||= [ ];
53  
54 if (@_) {
55 my $index = shift;
56 if (@_) {
57 my $value = shift;
58 $self->{__[[field]]__}->[$index] = $value;
59 }
60 return $self->{__[[field]]__}->[$index];
61 }
62 else {
63 return @{$self->{__[[field]]__}};
64 }
65 }
66  
67 sub RPM::Specfile::push_[[field]] {
68 my $self = shift;
69 my $entry = shift;
70  
71 $self->{__[[field]]__} ||= [ ];
72 push @{$self->{__[[field]]__}}, $entry;
73 }
74  
75 sub RPM::Specfile::clear_[[field]] {
76 my $self = shift;
77 my $entry = shift;
78  
79 $self->{__[[field]]__} = [ ];
80 }
81  
82 };
83  
84 8 $sub =~ s/\[\[field\]\]/$field/g;
85 0 ▶ eval $sub;
Subroutine buildrequire: called CC=4 SCAR=19.4
Subroutine changelog: called CC=4 SCAR=19.4
Subroutine clear_buildrequire: not called CC=1 SCAR=1.7
Subroutine clear_changelog: not called CC=1 SCAR=1.7
Subroutine clear_file: not called CC=1 SCAR=1.7
Subroutine clear_patch: not called CC=1 SCAR=1.7
Subroutine clear_prefix: not called CC=1 SCAR=1.7
Subroutine clear_provide: not called CC=1 SCAR=1.7
Subroutine clear_require: not called CC=1 SCAR=1.7
Subroutine clear_source: not called CC=1 SCAR=1.7
Subroutine file: called CC=4 SCAR=19.4
Subroutine patch: called CC=4 SCAR=19.4
Subroutine prefix: called CC=4 SCAR=19.4
Subroutine provide: not called CC=4 SCAR=19.4
Subroutine push_buildrequire: called CC=2 SCAR=10.1
Subroutine push_changelog: called CC=2 SCAR=10.1
Subroutine push_file: not called CC=2 SCAR=10.1
Subroutine push_patch: called CC=2 SCAR=10.1
Subroutine push_prefix: called CC=2 SCAR=10.1
Subroutine push_provide: not called CC=2 SCAR=10.1
Subroutine push_require: called CC=2 SCAR=10.1
Subroutine push_source: called CC=2 SCAR=10.1
Subroutine require: called CC=4 SCAR=19.4
Subroutine source: called CC=4 SCAR=19.4
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 16 branches
BranchTrueFalseTotal
if (@_) { } 0 1 1
if (@_) 0 0 0
if (@_) { } 0 1 1
if (@_) 0 0 0
if (@_) { } 0 1 1
if (@_) 0 0 0
if (@_) { } 0 1 1
if (@_) 0 0 0
if (@_) { } 0 1 1
if (@_) 0 0 0
if (@_) { } 0 0 0
if (@_) 0 0 0
if (@_) { } 0 1 1
if (@_) 0 0 0
if (@_) { } 0 1 1
if (@_) 0 0 0
Condition53%17/32
$self->{"__buildrequire__"} ||= []
l!l
10
$self->{"__changelog__"} ||= []
l!l
10
$self->{"__file__"} ||= []
l!l
01
$self->{"__patch__"} ||= []
l!l
10
$self->{"__prefix__"} ||= []
l!l
10
$self->{"__provide__"} ||= []
l!l
00
$self->{"__buildrequire__"} ||= []
l!l
11
$self->{"__changelog__"} ||= []
l!l
01
$self->{"__file__"} ||= []
l!l
00
$self->{"__patch__"} ||= []
l!l
11
$self->{"__prefix__"} ||= []
l!l
01
$self->{"__provide__"} ||= []
l!l
00
$self->{"__require__"} ||= []
l!l
11
$self->{"__source__"} ||= []
l!l
11
$self->{"__require__"} ||= []
l!l
10
$self->{"__source__"} ||= []
l!l
10
MC/DC0%0/1
$self->{"__buildrequire__"} ||= []
$self->{"__buildrequire__"}
MC/DC0%0/1
$self->{"__changelog__"} ||= []
$self->{"__changelog__"}
MC/DC0%0/1
$self->{"__file__"} ||= []
$self->{"__file__"}
MC/DC0%0/1
$self->{"__patch__"} ||= []
$self->{"__patch__"}
MC/DC0%0/1
$self->{"__prefix__"} ||= []
$self->{"__prefix__"}
MC/DC0%0/1
$self->{"__provide__"} ||= []
$self->{"__provide__"}
MC/DC100%1/1
$self->{"__buildrequire__"} ||= []
$self->{"__buildrequire__"}
MC/DC0%0/1
$self->{"__changelog__"} ||= []
$self->{"__changelog__"}
MC/DC0%0/1
$self->{"__file__"} ||= []
$self->{"__file__"}
MC/DC100%1/1
$self->{"__patch__"} ||= []
$self->{"__patch__"}
MC/DC0%0/1
$self->{"__prefix__"} ||= []
$self->{"__prefix__"}
MC/DC0%0/1
$self->{"__provide__"} ||= []
$self->{"__provide__"}
MC/DC100%1/1
$self->{"__require__"} ||= []
$self->{"__require__"}
MC/DC100%1/1
$self->{"__source__"} ||= []
$self->{"__source__"}
MC/DC0%0/1
$self->{"__require__"} ||= []
$self->{"__require__"}
MC/DC0%0/1
$self->{"__source__"} ||= []
$self->{"__source__"}
Truth table50%1/2
A
A= $self->{"__buildrequire__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__changelog__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__file__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__patch__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__prefix__"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"__provide__"}
Aresult
11
00
Truth table100%2/2
A
A= $self->{"__buildrequire__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__changelog__"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"__file__"}
Aresult
11
00
Truth table100%2/2
A
A= $self->{"__patch__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__prefix__"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"__provide__"}
Aresult
11
00
Truth table100%2/2
A
A= $self->{"__require__"}
Aresult
11
00
Truth table100%2/2
A
A= $self->{"__source__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__require__"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"__source__"}
Aresult
11
00
86  
87 8 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
88 0 die $@;
89 }
90 }
91  
92  
93 0 ▶sub add_changelog_entry {
Subroutine add_changelog_entry: not called CC=2 SCAR=17.9
Pod documented
94 0 my $self = shift;
95 0 my $who = shift;
96 0 my $entry = shift;
97 0 my $version = shift;
98  
99 0 POSIX::setlocale( &POSIX::LC_ALL, "C" );
100  
101 0 my $output;
102 0 $output .= strftime("* %a %b %d %Y $who", localtime time);
103 0 ▶ $output .= " - $version" if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 0 0 0
104 0 $output .= "\n- $entry\n";
105  
106 0 $self->push_changelog($output);
107 }
108  
109 1 ▶sub generate_specfile {
Subroutine generate_specfile: called CC=26 SCAR=36.0
Pod documented
110 1 my $self = shift;
111  
112 1 my $output;
113  
114 1 my %defaults =
115 ( buildroot => "%{_tmppath}/%{name}-%{version}-%{release}-root" );
116 1 ▶ $self->$_($self->$_() || $defaults{$_}) foreach keys %defaults;
Condition33%1/3
$self->$_ || $defaults{$_}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->$_ || $defaults{$_}
$self->$_ $defaults{$_}
Truth table33%1/3
A || B
A= $self->$_B= $defaults{$_}
ABresult
1X1
011
000
117  
118 1 my %proper_names = ( url => 'URL',
119 buildroot => 'BuildRoot',
120 buildrequires => 'BuildRequires',
121 buildarch => 'BuildArch',
122 );
123  
124 #
125 # Add any macro definitions to the begining.
126 1 ▶ $output .= $self->macros() . "\n" if defined $self->macros();
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->macros 1 0 1
127  
128 1 foreach my $tag (qw/summary name version release epoch packager vendor distribution license group url buildroot buildarch/) {
129 13 ▶ my $proper = $proper_names{$tag} || ucfirst $tag;
Condition66%2/3
$proper_names{$tag} || ucfirst $tag
l!l&&r!l&&!r
3100
MC/DC0%0/2
$proper_names{$tag} || ucfirst $tag
$proper_names{$tag} ucfirst $tag
Truth table66%2/3
A || B
A= $proper_names{$tag}B= ucfirst $tag
ABresult
1X1
011
000
130  
131 13 ▶ next unless defined $self->$tag();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->$tag 7 6 13
132 6 $output .= "$proper: " . $self->$tag() . "\n";
133 }
134  
135 4 ▶ my $req_format = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
136 4 my $req = shift;
137 4 my $ver = shift;
138  
139 4 ▶ if (ref $req) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $req) 2 2 4
140 2 ($req, $ver) = @$req;
141 }
142  
143 4 ▶ if (defined $ver and $ver != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ver and $ver != 0) { } 2 2 4
Condition66%2/3
defined $ver and $ver != 0
!ll&&!rl&&r
202
MC/DC50%1/2
defined $ver and $ver != 0
defined $ver $ver != 0
Truth table66%2/3
A and B
A= defined $verB= $ver != 0
ABresult
0X0
100
111
144 2 return "$req >= $ver";
145 }
146 else {
147 2 return "$req";
148 }
149 1 };
150  
151 1 foreach my $tag (qw/requires buildrequires/) {
152 2 ▶ my $proper = $proper_names{$tag} || ucfirst $tag;
Condition66%2/3
$proper_names{$tag} || ucfirst $tag
l!l&&r!l&&!r
110
MC/DC0%0/2
$proper_names{$tag} || ucfirst $tag
$proper_names{$tag} ucfirst $tag
Truth table66%2/3
A || B
A= $proper_names{$tag}B= ucfirst $tag
ABresult
1X1
011
000
153  
154 2 ▶ next unless defined $self->$tag();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->$tag 2 0 2
155  
156 0 $output .= "$proper: " . $req_format->($self->$tag) . "\n";
157 }
158  
159 1 my @reqs = $self->buildrequire;
160 1 for my $i (0 .. $#reqs) {
161 2 $output .= "BuildRequires: " . $req_format->($reqs[$i]) . "\n";
162 }
163  
164 1 @reqs = $self->require;
165 1 for my $i (0 .. $#reqs) {
166 2 $output .= "Requires: " . $req_format->($reqs[$i]) . "\n";
167 }
168  
169 1 my @sources = $self->source;
170 1 for my $i (0 .. $#sources) {
171 2 $output .= "Source$i: $sources[$i]\n";
172 }
173  
174 1 my @patches = $self->patch;
175 1 for my $i (0 .. $#patches) {
176 2 $output .= "Patch$i: $patches[$i]\n";
177 }
178  
179 #
180 # Add any prefixes:
181 1 my @prefixes = $self->prefix;
182 1 for my $i (0 .. $#prefixes) {
183 1 $output .= "Prefix: $prefixes[$i]\n";
184 }
185 1 $output .= "\n";
186  
187 #
188 # Add patch entries to the %prep section if they exist:
189 1 my $prep = $self->prep();
190 1 for my $i (0 .. $#patches) {
191 2 ▶ $prep .= "\n" if($i == 0); # Just in case they did not add a newline
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 1 1 2
192 2 $prep .= "%patch${i} -p1\n";
193 }
194 1 ▶ $self->prep($prep) if(defined($prep));
Branch: 1 branch
BranchTrueFalseTotal
if defined $prep 1 0 1
195  
196 1 ▶ if ($self->check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->check) 0 1 1
197 0 my $build = $self->build;
198  
199 0 my ($cond, $body) = (undef, $self->check);
200 0 ▶ if (ref $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $body) 0 0 0
201 0 $cond = $body->[0];
202 0 $body = $body->[1];
203 }
204  
205 0 $build .= "\n%check";
206 0 ▶ if ($cond) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond) 0 0 0
207 0 $build .= " $cond";
208 }
209 0 $build .= "\n$body\n";
210  
211 0 $self->build($build);
212 }
213  
214 1 foreach my $sect (qw/description prep build install clean pre post preun postun/) {
215 9 ▶ next if(!defined($self->$sect()));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->$sect 1 8 9
216 8 $output .= "%$sect\n";
217 8 my $content = $self->$sect();
218 # remove leading and trailing whitespace and spurious linefeeds
219 8 $content =~ s/^\s*\n*//s;
220 8 $content =~ s/[\s\n]*$/\n\n/s;
221 8 $output .= $content;
222 }
223  
224 1 ▶ if ($self->file_param) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file_param) { } 1 0 1
225 1 $output .= "%files " . $self->file_param . "\n";
226 }
227 else {
228 0 $output .= "%files\n";
229 }
230 1 $output .= "$_\n" foreach $self->file;
231  
232 1 $output .= "\n%changelog\n";
233 1 $output .= "$_\n" foreach $self->changelog;
234  
235 1 return $output;
236 }
237  
238 0 ▶sub write_specfile {
Subroutine write_specfile: not called CC=2 SCAR=17.9
Pod documented
239 0 my $self = shift;
240 0 my $dest = shift;
241  
242 0 ▶ open FH, ">$dest"
Branch: 1 branch
BranchTrueFalseTotal
open FH, ">$dest" or die "Can't open ${dest}: $!" 0 0 0
243 or die "Can't open $dest: $!";
244  
245 0 print FH $self->generate_specfile;
246  
247 0 close FH;
248 }
249  
250 1 1;
251  
252 __END__
↑ Summary