Dpkg/Changelog/Entry.pm

filter: Statementstmt 65.2% 60 / 92 Branchbran 31.2% 10 / 32 Conditioncond 60.0% 6 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 58.3% 14 / 24 Podpod 100% 16 / 16 totaltotal 59.7% 107 / 179 CC 22 SCAR 19.2
CC
22
Cov
57%
normalize
30.0
extend_part
9.4
set_part
6.5
CRAP 6.8
« Dpkg/Interface/Storable.pm ↑ Summary Dpkg/Arch.pm »
1 # Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Dpkg::Changelog::Entry - represents a changelog entry
21  
22 =head1 DESCRIPTION
23  
24 This class represents a changelog entry. It is composed
25 of a set of lines with specific purpose: a header line, changes lines, a
26 trailer line. Blank lines can be between those kind of lines.
27  
28 =cut
29  
30 package Dpkg::Changelog::Entry 1.01;
31  
32 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use Dpkg::Control::Changelog;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 use overload
41 2 ▶ '""' => \&output,
Subroutine BEGIN: called CC=1 SCAR=1.2
42 0 ▶ 'eq' => sub { defined($_[1]) and "$_[0]" eq "$_[1]" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and "$_[0]" eq "$_[1]" 0 0 0
43 2 fallback => 1;
44  
45 =head1 METHODS
46  
47 =over 4
48  
49 =item $entry = Dpkg::Changelog::Entry->new()
50  
51 Creates a new object. It doesn't represent a real changelog entry
52 until one has been successfully parsed or built from scratch.
53  
54 =cut
55  
56 250 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
57 250 my $this = shift;
58 250 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
02500
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
59  
60 250 my $self = {
61 header => undef,
62 changes => [],
63 trailer => undef,
64 blank_after_header => [],
65 blank_after_changes => [],
66 blank_after_trailer => [],
67 };
68 250 bless $self, $class;
69 250 return $self;
70 }
71  
72 =item $string = "$entry"
73  
74 =item $string = $entry->output([$fh])
75  
76 Get a string representation of the changelog entry.
77  
78 Optionally, print the string representation of the changelog entry to a
79 filehandle.
80  
81 =cut
82  
83 1528 ▶sub _format_output_block {
Subroutine _format_output_block: called CC=1 SCAR=0.0
84 1528 my $lines = shift;
85 1528 return join('', map { $_ . "\n" } @{$lines});
86 }
87  
88 382 ▶sub output {
Subroutine output: called CC=4 SCAR=14.4
Pod documented
89 382 my ($self, $fh) = @_;
90 382 my $str = '';
91 382 ▶ $str .= $self->{header} . "\n" if defined($self->{header});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"header"} 382 0 382
92 382 $str .= _format_output_block($self->{blank_after_header});
93 382 $str .= _format_output_block($self->{changes});
94 382 $str .= _format_output_block($self->{blank_after_changes});
95 382 ▶ $str .= $self->{trailer} . "\n" if defined($self->{trailer});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"trailer"} 382 0 382
96 382 $str .= _format_output_block($self->{blank_after_trailer});
97 0 ▶ print { $fh } $str if defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fh 0 382 382
98 382 return $str;
99 }
100  
101 =item $string = $entry->get_part($part)
102  
103 =item @part = $entry->get_part($part)
104  
105 Return either a string (for a single line) or an array ref (for multiple
106 lines) corresponding to the requested part. $part can be
107 "header, "changes", "trailer", "blank_after_header",
108 "blank_after_changes", "blank_after_trailer".
109  
110 =cut
111  
112 1478 ▶sub get_part {
Subroutine get_part: called CC=2 SCAR=7.1
Pod documented
113 1478 my ($self, $part) = @_;
114 1478 ▶ croak "invalid part of changelog entry: $part" unless exists $self->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$part} 0 1478 1478
115 1478 return $self->{$part};
116 }
117  
118 =item $entry->set_part($part, $value)
119  
120 Set the value of the corresponding part. $value can be a string
121 or an array ref.
122  
123 =cut
124  
125 498 ▶sub set_part {
Subroutine set_part: called CC=4 SCAR=18.7
Pod documented
126 498 my ($self, $part, $value) = @_;
127 498 ▶ croak "invalid part of changelog entry: $part" unless exists $self->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$part} 0 498 498
128 498 ▶ if (ref($self->{$part})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$part}) { } 0 498 498
129 0 ▶ if (ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
130 0 $self->{$part} = $value;
131 } else {
132 0 $self->{$part} = [ $value ];
133 }
134 } else {
135 498 $self->{$part} = $value;
136 }
137 }
138  
139 =item $entry->extend_part($part, $value)
140  
141 Concatenate $value at the end of the part. If the part is already a
142 multi-line value, $value is added as a new line otherwise it's
143 concatenated at the end of the current line.
144  
145 =cut
146  
147 3266 ▶sub extend_part {
Subroutine extend_part: called CC=6 SCAR=22.4
Pod documented
148 3266 my ($self, $part, $value, @rest) = @_;
149 3266 ▶ croak "invalid part of changelog entry: $part" unless exists $self->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$part} 0 3266 3266
150 3266 ▶ if (ref($self->{$part})) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{$part}) { } 3266 0 3266
elsif (defined $self->{$part}) { } 0 0 0
151 3266 ▶ if (ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 2782 484 3266
152 2782 push @{$self->{$part}}, @$value;
153 } else {
154 484 push @{$self->{$part}}, $value;
155 }
156 } elsif (defined $self->{$part}) {
157 0 ▶ if (ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
158 0 $self->{$part} = [ $self->{$part}, @$value ];
159 } else {
160 0 $self->{$part} .= $value;
161 }
162 } else {
163 0 $self->{$part} = $value;
164 }
165 }
166  
167 =item $bool = $entry->is_empty()
168  
169 Returns 1 if the changelog entry doesn't contain anything at all.
170 Returns 0 as soon as it contains something in any of its non-blank
171 parts.
172  
173 =cut
174  
175 266 ▶sub is_empty {
Subroutine is_empty: called CC=3 SCAR=11.0
Pod documented
176 266 my $self = shift;
177 return ! (defined($self->{header}) || defined($self->{trailer}) ||
178 266 ▶ scalar(@{$self->{changes}}));
Condition80%4/5
defined $self->{'header'} || defined $self->{'trailer'} || scalar @{$self->{'changes'};}
l!l
25016
defined $self->{"header"} or defined $self->{"trailer"}
l!l&&r!l&&!r
250016
MC/DC50%1/2
defined $self->{'header'} || defined $self->{'trailer'} || scalar @{$self->{'changes'};}
defined $self->{"header"} defined $self->{"trailer"}
Truth table66%2/3
A or B
A= defined $self->{"header"}B= defined $self->{"trailer"}
ABresult
1X1
011
000
179 }
180  
181 =item $entry->normalize()
182  
183 Normalize the content. Strip whitespaces at end of lines, use a single
184 empty line to separate each part.
185  
186 =cut
187  
188 0 ▶sub normalize {
Subroutine normalize: not called CC=5 SCAR=34.0
Pod documented
189 0 my $self = shift;
190 0 ▶ if (defined($self->{header})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'header'}) { } 0 0 0
191 0 $self->{header} =~ s/\s+$//g;
192 0 $self->{blank_after_header} = [ '' ];
193 } else {
194 0 $self->{blank_after_header} = [];
195 }
196 0 ▶ if (scalar(@{$self->{changes}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{'changes'};}) { } 0 0 0
197 0 s/\s+$//g foreach @{$self->{changes}};
198 0 $self->{blank_after_changes} = [ '' ];
199 } else {
200 0 $self->{blank_after_changes} = [];
201 }
202 0 ▶ if (defined($self->{trailer})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'trailer'}) { } 0 0 0
203 0 $self->{trailer} =~ s/\s+$//g;
204 0 $self->{blank_after_trailer} = [ '' ];
205 } else {
206 0 $self->{blank_after_trailer} = [];
207 }
208 }
209  
210 =item $src = $entry->get_source()
211  
212 Return the name of the source package associated to the changelog entry.
213  
214 =cut
215  
216 0 ▶sub get_source {
Subroutine get_source: not called CC=1 SCAR=6.9
Pod documented
217 0 return;
218 }
219  
220 =item $ver = $entry->get_version()
221  
222 Return the version associated to the changelog entry.
223  
224 =cut
225  
226 0 ▶sub get_version {
Subroutine get_version: not called CC=1 SCAR=6.9
Pod documented
227 0 return;
228 }
229  
230 =item @dists = $entry->get_distributions()
231  
232 Return a list of target distributions for this version.
233  
234 =cut
235  
236 0 ▶sub get_distributions {
Subroutine get_distributions: not called CC=1 SCAR=6.9
Pod documented
237 0 return;
238 }
239  
240 =item $ctrl = $entry->get_optional_fields()
241  
242 Return a set of optional fields exposed by the changelog entry.
243 It always returns a L<Dpkg::Control> object (possibly empty though).
244  
245 =cut
246  
247 0 ▶sub get_optional_fields {
Subroutine get_optional_fields: not called CC=1 SCAR=6.9
Pod documented
248 0 return Dpkg::Control::Changelog->new();
249 }
250  
251 =item $urgency = $entry->get_urgency()
252  
253 Return the urgency of the associated upload.
254  
255 =cut
256  
257 0 ▶sub get_urgency {
Subroutine get_urgency: not called CC=1 SCAR=6.9
Pod documented
258 0 return;
259 }
260  
261 =item $maint = $entry->get_maintainer()
262  
263 Return the string identifying the person who signed this changelog entry.
264  
265 =cut
266  
267 0 ▶sub get_maintainer {
Subroutine get_maintainer: not called CC=1 SCAR=6.9
Pod documented
268 0 return;
269 }
270  
271 =item $time = $entry->get_timestamp()
272  
273 Return the timestamp of the changelog entry.
274  
275 =cut
276  
277 0 ▶sub get_timestamp {
Subroutine get_timestamp: not called CC=1 SCAR=6.9
Pod documented
278 0 return;
279 }
280  
281 =item $time = $entry->get_timepiece()
282  
283 Return the timestamp of the changelog entry as a L<Time::Piece> object.
284  
285 This function might return undef if there was no timestamp.
286  
287 =cut
288  
289 0 ▶sub get_timepiece {
Subroutine get_timepiece: not called CC=1 SCAR=6.9
Pod documented
290 0 return;
291 }
292  
293 =item $string = $entry->get_dpkg_changes()
294  
295 Returns a string that is suitable for usage in a C<Changes> field
296 in the output format of C<dpkg-parsechangelog>.
297  
298 =cut
299  
300 738 ▶sub get_dpkg_changes {
Subroutine get_dpkg_changes: called CC=2 SCAR=7.0
Pod documented
301 738 my $self = shift;
302 738 ▶ my $header = $self->get_part('header') // '';
Condition50%1/2
$self->get_part("header") // ""
l!l
7380
MC/DC0%0/1
$self->get_part("header") // ""
$self->get_part("header")
Truth table50%1/2
A
A= $self->get_part("header")
Aresult
11
00
303 738 $header =~ s/\s+$//;
304 738 return "\n$header\n\n" . join("\n", @{$self->get_part('changes')});
305 }
306  
307 =back
308  
309 =head1 CHANGES
310  
311 =head2 Version 1.01 (dpkg 1.18.8)
312  
313 New method: $entry->get_timepiece().
314  
315 =head2 Version 1.00 (dpkg 1.15.6)
316  
317 Mark the module as public.
318  
319 =cut
320  
321 2 1;
« Dpkg/Interface/Storable.pm ↑ Summary Dpkg/Arch.pm »