blib/lib/LCFG/Build/PkgSpec.pm

filter: Statementstmt 81.2% 208 / 256 Branchbran 88.0% 44 / 50 Conditioncond 73.0% 19 / 26 MC/DCmcdc 68.7% 11 / 16 Subroutinesub 74.0% 37 / 50 Podpod 91.3% 21 / 23 totaltotal 80.7% 340 / 421 CC 37 SCAR 17.6
CC
37
Cov
82%
new_from_cfgmk
18.2
_update_version
6.0
perl_version
6.0
CRAP 5.8
↑ Summary Build »
1 package LCFG::Build::PkgSpec; # -*-perl-*-
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # $Id: PkgSpec.pm.in 35434 2019-01-18 10:43:38Z squinney@INF.ED.AC.UK $
6 # $Source: /var/cvs/dice/LCFG-Build-PkgSpec/lib/LCFG/Build/PkgSpec.pm.in,v $
7 # $Revision: 35434 $
8 # $HeadURL: https://svn.lcfg.org/svn/source/tags/LCFG-Build-PkgSpec/LCFG_Build_PkgSpec_0_2_6/lib/LCFG/Build/PkgSpec.pm.in $
9 # $Date: 2019-01-18 10:43:38 +0000 (Fri, 18 Jan 2019) $
10  
11 10 our $VERSION = '0.2.6';
12  
13 10 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 ▶use Data::Structure::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Email::Address ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶use Email::Valid ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 10 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # A type and coercion to allow the attribute to be set as either an
26 # ref to an array or a scalar string.
27  
28 10 subtype 'ArrayRefOrString' => as 'ArrayRef[Str]';
29 0 ▶coerce 'ArrayRefOrString' => from 'Str' => via { [ split /\s*,\s*/, $_ ] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
30  
31 subtype 'EmailAddress'
32 => as 'Str'
33 9 ▶ => where { Email::Valid->address( -address => $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
34 0 ▶ => message { "Address ($_) for report must be a valid email address" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
35  
36 10 subtype 'EmailAddressList'
37 => as 'ArrayRef[EmailAddress]';
38  
39 coerce 'EmailAddressList'
40 => from 'Str'
41 3 ▶ => via { [ map { $_->format } Email::Address->parse($_)] };
Subroutine __ANON__: called CC=1 SCAR=0.0
42  
43 coerce 'EmailAddressList'
44 => from 'ArrayRef'
45 0 ▶ => via { [ map { $_->format } map { Email::Address->parse($_) } @{$_} ] };
Subroutine __ANON__: not called CC=1 SCAR=4.1
46  
47 subtype 'VersionString'
48 => as 'Str'
49 32 ▶ => where { $_ =~ m/^\d+\.\d+\.\d+(\.dev\d*)?$/ }
Subroutine __ANON__: called CC=1 SCAR=0.0
50 5 ▶ => message { $_ = 'undef' if !defined $_; "Version string ($_) does not match the expected LCFG format." };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 1 4 5
51  
52 subtype 'ReleaseString'
53 => as 'Str'
54 37 ▶ => where { $_ =~ m/^\d+/ }
Subroutine __ANON__: called CC=1 SCAR=0.0
55 0 ▶ => message { "Release string ($_) does not match the expected LCFG format." };
Subroutine __ANON__: not called CC=1 SCAR=1.2
56  
57 10 has 'name' => ( is => 'rw', required => 1 );
58 10 has 'base' => ( is => 'rw', default => q{} );
59 10 has 'abstract' => ( is => 'rw' );
60  
61 10 has 'version' => (
62 is => 'rw',
63 required => 1,
64 isa => 'VersionString',
65 default => '0.0.0',
66 );
67  
68 10 has 'release' => (
69 is => 'rw',
70 isa => 'Maybe[ReleaseString]',
71 default => 1,
72 );
73  
74 10 has 'schema' => (
75 is => 'rw',
76 isa => 'Int',
77 default => 1,
78 );
79  
80 10 has 'group' => ( is => 'rw');
81 10 has 'vendor' => ( is => 'rw');
82 10 has 'license' => ( is => 'rw');
83  
84 10 has 'translate' => (
85 is => 'rw',
86 isa => 'ArrayRef[Str]',
87 auto_deref => 1,
88 );
89  
90 has 'date' => (
91 is => 'rw',
92 isa => 'Str',
93 5 ▶ default => sub { DateTime->now->strftime('%d/%m/%y %T') },
Subroutine __ANON__: called CC=1 SCAR=0.0
94 10 );
95  
96 10 has 'metafile' => (
97 is => 'rw',
98 isa => 'Maybe[Str]',
99 );
100  
101 # I would quite like to treat author and platforms as sets but that
102 # doesn't seem to be available at present.
103  
104 has 'author' => (
105 is => 'rw',
106 isa => 'EmailAddressList',
107 coerce => 1,
108 auto_deref => 1,
109 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 10 );
111  
112 has 'platforms' => (
113 is => 'rw',
114 isa => 'ArrayRefOrString',
115 coerce => 1,
116 auto_deref => 1,
117 4 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
118 10 );
119  
120 has 'build' => (
121 traits => ['Hash'],
122 is => 'rw',
123 isa => 'HashRef[Str]',
124 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 10 lazy => 1,
126 handles => {
127 exists_in_buildinfo => 'exists',
128 ids_in_buildinfo => 'keys',
129 get_buildinfo => 'get',
130 set_buildinfo => 'set',
131 },
132 );
133  
134 has 'vcs' => (
135 traits => ['Hash'],
136 is => 'rw',
137 isa => 'HashRef[Str]',
138 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
139 10 handles => {
140 exists_in_vcsinfo => 'exists',
141 ids_in_vcsinfo => 'keys',
142 get_vcsinfo => 'get',
143 set_vcsinfo => 'set',
144 },
145 );
146  
147 10 has 'orgident' => (
148 is => 'rw',
149 isa => 'Str',
150 default => 'org.lcfg'
151 );
152  
153 10 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 10 __PACKAGE__->meta->make_immutable;
155  
156 sub perl_version {
157 0 ▶ my ($self) = @_;
Subroutine perl_version: not called CC=2 SCAR=17.9
Pod documented
158  
159 0 my $perl_version = $self->version;
160 0 ▶ if ( $perl_version =~ s/\.dev\d*$// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_version =~ s/\.dev\d*$//) 0 0 0
161  
162 # Cannot use a non-numeric in a Perl version string. A "devel"
163 # version is signified with a suffix which is an underscore
164 # and a release number. See "perldoc version" for details.
165  
166 0 $perl_version = join q{.}, $self->get_major, $self->get_minor, $self->get_micro;
167 0 $perl_version .= q{_} . $self->release;
168 }
169  
170 0 return $perl_version;
171 }
172  
173 sub deb_version {
174 0 ▶ my ($self) = @_;
Subroutine deb_version: not called CC=1 SCAR=6.9
Pod documented
175  
176 0 my $deb_version = $self->version;
177  
178 0 $deb_version =~ s/[^a-zA-Z0-9~.+-]//;
179  
180 0 return $deb_version;
181 }
182  
183 sub get_major {
184 19 ▶ my ($self) = @_;
Subroutine get_major: called CC=1 SCAR=0.0
Pod documented
185  
186 19 my $version = $self->version;
187  
188 19 my $major = (split /\./, $version)[0];
189  
190 19 return $major;
191 }
192  
193 sub get_minor {
194 19 ▶ my ($self) = @_;
Subroutine get_minor: called CC=1 SCAR=0.0
Pod documented
195  
196 19 my $version = $self->version;
197  
198 19 my $minor = (split /\./, $version)[1];
199  
200 19 return $minor;
201 }
202  
203 sub get_micro {
204 19 ▶ my ($self) = @_;
Subroutine get_micro: called CC=1 SCAR=0.0
Pod documented
205  
206 19 my $version = $self->version;
207  
208 19 my $micro = (split /\./, $version)[2];
209  
210 19 return $micro;
211 }
212  
213 sub pkgident {
214 0 ▶ my ($self) = @_;
Subroutine pkgident: not called CC=1 SCAR=6.9
Pod documented
215  
216 0 my $org = $self->orgident;
217 0 my $name = $self->fullname;
218 0 my $id = join q{.}, $org, $name;
219  
220 0 return $id;
221 }
222  
223 sub fullname {
224 6 ▶ my ($self) = @_;
Subroutine fullname: called CC=3 SCAR=11.0
Pod documented
225  
226 6 my $fullname;
227 6 ▶ if ( defined $self->base && length $self->base > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->base and length $self->base > 0) { } 3 3 6
Condition66%2/3
defined $self->base and length $self->base > 0
!ll&&!rl&&r
033
MC/DC50%1/2
defined $self->base and length $self->base > 0
defined $self->base length $self->base > 0
Truth table66%2/3
A and B
A= defined $self->baseB= length $self->base > 0
ABresult
0X0
100
111
228 3 $fullname = join q{-}, $self->base, $self->name;
229 }
230 else {
231 3 $fullname = $self->name;
232 }
233  
234 6 return $fullname;
235 }
236  
237 sub deb_name {
238 0 ▶ my ($self) = @_;
Subroutine deb_name: not called CC=1 SCAR=6.9
Pod documented
239  
240 # By convention debian package names are lower-case
241 0 my $name = lc $self->fullname;
242  
243 # underscores are not permitted, helpfully replace with dashes
244 0 $name =~ s/_/-/g;
245  
246 # For safety remove any other invalid characters
247 0 $name =~ s/[^a-z0-9-]//;
248  
249 0 return $name;
250 }
251  
252 sub tarname {
253 2 ▶ my ( $self, $comp ) = @_;
Subroutine tarname: called CC=2 SCAR=6.9
Pod documented
254 2 ▶ $comp ||= 'gz';
Condition100%2/2
$comp ||= "gz"
l!l
11
MC/DC100%1/1
$comp ||= "gz"
$comp
Truth table100%2/2
A
A= $comp
Aresult
11
00
255  
256 2 my $packname = join q{-}, $self->fullname, $self->version;
257 2 my $tarname = $packname . ".tar.$comp";
258  
259 2 return $tarname;
260 }
261  
262 sub deb_srctarname {
263 0 ▶ my ( $self, $comp ) = @_;
Subroutine deb_srctarname: not called CC=2 SCAR=17.9
Pod undocumented
264 0 ▶ $comp ||= 'gz';
Condition0%0/2
$comp ||= "gz"
l!l
00
MC/DC0%0/1
$comp ||= "gz"
$comp
Truth table0%0/2
A
A= $comp
Aresult
11
00
265  
266 0 my $packname = join q{_}, $self->deb_name, $self->deb_version;
267 0 my $tarname = $packname . ".orig.tar.$comp";
268  
269 0 return $tarname;
270 }
271  
272 sub deb_tarname {
273 0 ▶ my ( $self, $comp ) = @_;
Subroutine deb_tarname: not called CC=2 SCAR=17.9
Pod documented
274 0 ▶ $comp ||= 'gz';
Condition0%0/2
$comp ||= "gz"
l!l
00
MC/DC0%0/1
$comp ||= "gz"
$comp
Truth table0%0/2
A
A= $comp
Aresult
11
00
275  
276 0 my $packname = join q{_}, $self->deb_name, $self->deb_version;
277 0 my $tarname = $packname . "-1.debian.tar.$comp";
278  
279 0 return $tarname;
280 }
281  
282 sub deb_dscname {
283 0 ▶ my ($self) = @_;
Subroutine deb_dscname: not called CC=1 SCAR=6.9
Pod documented
284  
285 0 my $packname = join q{_}, $self->deb_name, $self->deb_version;
286 0 my $dscname = $packname . "-1.dsc";
287  
288 0 return $dscname;
289 }
290  
291 sub rpmspec_name {
292 0 ▶ my ( $self, $base ) = @_;
Subroutine rpmspec_name: not called CC=1 SCAR=6.9
Pod documented
293  
294 0 return $self->fullname . '.spec';
295 }
296  
297 sub clone {
298 1 ▶ my ($self) = @_;
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
299  
300 1 require Storable;
301 1 my $clone = Storable::dclone($self);
302  
303 1 return $clone;
304 }
305  
306 sub new_from_metafile {
307 6 ▶ my ( $class, $file ) = @_;
Subroutine new_from_metafile: called CC=4 SCAR=13.9
Pod documented
308  
309 6 ▶ if ( !defined $file || !length $file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $file && length $file) { } 2 4 6
elsif (not -f $file) { } 1 3 4
Condition100%3/3
defined $file && length $file
!ll&&!rl&&r
114
MC/DC100%2/2
defined $file && length $file
defined $file length $file
Truth table100%3/3
A && B
A= defined $fileB= length $file
ABresult
0X0
100
111
310 2 die "Error: You need to specify the LCFG meta-data file name\n";
311 }
312 elsif ( !-f $file ) {
313 1 die "Error: Cannot find LCFG meta-data file '$file'\n";
314 }
315  
316 3 require YAML::Syck;
317 3 my $data;
318 {
319 # Allow true/false, yes/no for booleans
320 3 local $YAML::Syck::ImplicitTyping = 1;
321  
322 3 $data = YAML::Syck::LoadFile($file);
323  
324 # We unbless as previously saved metafiles are going to have a
325 # blessing. We want all input files treated with the same
326 # amount of contempt.
327  
328 3 Data::Structure::Util::unbless($data);
329 }
330  
331 3 my $self = $class->new($data);
332  
333 3 $self->metafile($file);
334  
335 3 return $self;
336 }
337  
338 sub new_from_cfgmk {
339 9 ▶ my ( $proto, $file ) = @_;
Subroutine new_from_cfgmk: called CC=18 SCAR=29.0
Pod documented
340  
341 9 ▶ if ( !defined $file || !length $file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $file && length $file) { } 2 7 9
elsif (not -f $file) { } 1 6 7
Condition100%3/3
defined $file && length $file
!ll&&!rl&&r
117
MC/DC100%2/2
defined $file && length $file
defined $file length $file
Truth table100%3/3
A && B
A= defined $fileB= length $file
ABresult
0X0
100
111
342 2 die "Error: You need to specify the LCFG config file name\n";
343 }
344 elsif ( !-f $file ) {
345 1 die "Error: Cannot find LCFG config file '$file'\n";
346 }
347  
348 6 my %translator = (
349 COMP => 'name',
350 DESCR => 'abstract',
351 V => 'version',
352 R => 'release',
353 SCHEMA => 'schema',
354 GROUP => 'group',
355 AUTHOR => 'author',
356 ORGANIZATION => 'vendor',
357 DATE => 'date',
358 );
359  
360 6 my %spec;
361  
362 6 ▶ my $in = IO::File->new( $file, 'r' ) or die "Could not open $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $in = "IO::File"->new($file, "r") or die "Could not open ${file}: $!\n" 0 6 6
363  
364 6 ▶ while ( defined ( my $line = <$in> ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 173 6 179
365 173 $line =~ s/^\s+//;
366 173 $line =~ s/\s+$//;
367  
368 173 ▶ while ( $line =~ m{^(.*?)\\$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(.*?)\\$/) 0 173 173
369 0 my $extra = <$in>;
370 0 $line = $1 . $extra;
371 }
372  
373 173 ▶ if ( $line =~ m/^([^=]+)=(.+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^=]+)=(.+)$/) 143 30 173
374 143 my ( $key, $value ) = ( $1, $2 );
375 143 ▶ if ( exists $translator{$key} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $translator{$key}) { } 53 90 143
elsif ($key eq 'PLATFORMS') { } 6 84 90
elsif ($key eq 'NAME') { } 6 78 84
376 53 $spec{ $translator{$key} } = $value;
377 }
378 elsif ( $key eq 'PLATFORMS' ) {
379 6 my @platforms = split /,\s*/, $value;
380 6 $spec{platforms} = [@platforms];
381 }
382 elsif ( $key eq 'NAME' ) {
383 6 my $compname;
384 6 ▶ if ( $value =~ m/^(.+?)-(.+?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(.+?)-(.+?)$/) { } 6 0 6
385 6 ( $spec{base}, $compname ) = ( $1, $2 );
386 }
387 else {
388 0 $compname = $value;
389 }
390  
391 6 ▶ if ( $compname ne '$(COMP)' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compname ne "\$(COMP)") 1 5 6
392 1 $spec{name} = $compname;
393 }
394 }
395 }
396  
397 }
398  
399 6 $in->close;
400  
401 6 my $pkgspec;
402 6 ▶ if ( !ref $proto ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $proto) { } 3 3 6
elsif (defined builtin::blessed($proto) and $proto->isa(__PACKAGE__)) { } 1 2 3
403 3 $spec{license} = 'GPLv2';
404 3 ▶ $spec{vendor} ||= 'University of Edinburgh';
Condition100%2/2
$spec{"vendor"} ||= "University of Edinburgh"
l!l
21
MC/DC100%1/1
$spec{"vendor"} ||= "University of Edinburgh"
$spec{"vendor"}
Truth table100%2/2
A
A= $spec{"vendor"}
Aresult
11
00
405 3 $spec{vcs} = { logname => 'ChangeLog' };
406 3 $spec{build} = { gencmake => 1 };
407 3 $spec{translate} = [ '*.cin' ];
408 3 $pkgspec = $proto->new(\%spec);
409 }
410 ▶ elsif ( defined Scalar::Util::blessed($proto) && $proto->isa(__PACKAGE__) ) {
Condition100%3/3
defined builtin::blessed($proto) and $proto->isa(__PACKAGE__)
!ll&&!rl&&r
111
MC/DC100%2/2
defined builtin::blessed($proto) and $proto->isa(__PACKAGE__)
defined builtin::blessed($proto) $proto->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= defined builtin::blessed($proto)B= $proto->isa(__PACKAGE__)
ABresult
0X0
100
111
411 1 $pkgspec = $proto;
412 1 for my $key ( keys %spec ) {
413 11 $pkgspec->$key($spec{$key});
414 }
415 }
416 else {
417 2 die "Error: new_from_cfgmk method called on wrong class or object\n";
418 }
419  
420 3 return $pkgspec;
421 }
422  
423 sub save_metafile {
424 3 ▶ my ( $self, $file ) = @_;
Subroutine save_metafile: called CC=4 SCAR=13.9
Pod documented
425  
426 3 ▶ $file ||= $self->metafile;
Condition66%2/3
$file ||= $self->metafile
l!l&&r!l&&!r
102
MC/DC50%1/2
$file ||= $self->metafile
$file $self->metafile
Truth table66%2/3
A ||= B
A= $fileB= $self->metafile
ABresult
1X1
011
000
427  
428 3 ▶ if ( !defined $file || !length $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file and length $file) 2 1 3
Condition66%2/3
defined $file and length $file
!ll&&!rl&&r
201
MC/DC50%1/2
defined $file and length $file
defined $file length $file
Truth table66%2/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
429 2 die "Error: You need to specify the LCFG config file name\n";
430 }
431  
432 1 require YAML::Syck;
433 {
434 1 local $YAML::Syck::SortKeys = 1;
435 1 my $dump = \%{$self};
436 1 delete $dump->{metafile};
437 1 YAML::Syck::DumpFile( $file, $dump );
438 }
439  
440 1 return;
441 }
442  
443 sub dev_version {
444 2 ▶ my ($self) = @_;
Subroutine dev_version: called CC=1 SCAR=0.0
Pod documented
445  
446 2 $self->update_release;
447  
448 2 my $dev_version = 'dev' . $self->release;
449  
450 2 $dev_version = join q{.}, $self->get_major, $self->get_minor,
451 $self->get_micro, $dev_version;
452  
453 2 $self->version($dev_version);
454  
455 2 return $self->version;
456 }
457  
458 sub update_release {
459 6 ▶ my ($self) = @_;
Subroutine update_release: called CC=2 SCAR=6.9
Pod documented
460  
461 6 my $release = $self->release;
462  
463 6 ▶ if ( !defined $release ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $release) { } 1 5 6
464 1 $release = 1;
465 }
466 else {
467 5 $release++;
468 }
469  
470 6 $self->release($release);
471  
472 6 return;
473 }
474  
475 sub update_date {
476 12 ▶ my ($self) = @_;
Subroutine update_date: called CC=1 SCAR=0.0
Pod documented
477  
478 12 my $now = DateTime->now->strftime('%d/%m/%y %T');
479  
480 12 $self->date($now);
481  
482 12 return;
483 }
484  
485 sub update_major {
486 3 ▶ my ($self) = @_;
Subroutine update_major: called CC=1 SCAR=0.0
Pod documented
487 3 return $self->_update_version('major');
488 }
489  
490 sub update_minor {
491 3 ▶ my ($self) = @_;
Subroutine update_minor: called CC=1 SCAR=0.0
Pod documented
492 3 return $self->_update_version('minor');
493 }
494  
495 sub update_micro {
496 4 ▶ my ($self) = @_;
Subroutine update_micro: called CC=1 SCAR=0.0
Pod documented
497 4 return $self->_update_version('micro');
498 }
499  
500 sub _update_version {
501 11 ▶ my ( $self, $uptype ) = @_;
Subroutine _update_version: called CC=6 SCAR=17.9
502  
503 11 my $major = $self->get_major;
504 11 my $minor = $self->get_minor;
505 11 my $micro = $self->get_micro;
506  
507 11 ▶ if ( $uptype eq 'major' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($uptype eq 'major') { } 3 8 11
elsif ($uptype eq 'minor') { } 3 5 8
elsif ($uptype eq 'micro') { } 4 1 5
508 3 $major++;
509 3 $minor = 0;
510 3 $micro = 0;
511 }
512 elsif ( $uptype eq 'minor' ) {
513 3 $minor++;
514 3 $micro = 0;
515 }
516 elsif ( $uptype eq 'micro' ) {
517 4 $micro++;
518 }
519 else {
520 1 die "Unknown version update-type: $uptype\n";
521 }
522  
523 10 my $newver = join q{.}, $major, $minor, $micro;
524  
525 10 my $rel = $self->release;
526 10 my $newrel;
527 10 ▶ if ( defined $rel ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rel) { } 9 1 10
528 9 ▶ if ( $rel =~ m/^\d+(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel =~ /^\d+(.*)$/) { } 9 0 9
529 9 $newrel = q{1} . $1;
530 }
531 else {
532 0 die "Release string, '$rel', does not match expected format\n";
533 }
534 }
535 else {
536 1 $newrel = 1;
537 }
538  
539 # Only update the attributes if everything else has succeeded
540 # (i.e. we got this far in the code).
541  
542 10 $self->version($newver);
543 10 $self->release($newrel);
544 10 $self->update_date();
545  
546 10 return;
547 }
548  
549 10 1;
550 __END__
551  
552 =head1 NAME
553  
554 LCFG::Build::PkgSpec - Object-oriented interface to LCFG build metadata
555  
556 =head1 VERSION
557  
558 This documentation refers to LCFG::Build::PkgSpec version 0.2.6
559  
560 =head1 SYNOPSIS
561  
562 my $spec = LCFG::Build::PkgSpec->new( name => "foo",
563 version => "0.0.1" );
564  
565 $spec->schema(2);
566  
567 $spec->save_metafile("./lcfg.yml");
568  
569 my $spec2 =
570 LCFG::Build::PkgSpec->new_from_metafile("./lcfg.yml");
571  
572 print "Package name is: " . $spec2->name . "\n";
573  
574 $spec2->update_major();
575  
576 $spec->save_metafile("./lcfg.yml");
577  
578 =head1 DESCRIPTION
579  
580 This class provides an object-oriented interface to the LCFG build
581 tools metadata file. All simple fields are available through attribute
582 accessors. Specific methods are also provided for querying and
583 modifying the more complex data types (e.g. lists and hashes).
584  
585 This class has methods for carrying out specific procedures related to
586 tagging releases with the LCFG build tools. It also has methods for
587 handling the old format LCFG build configuration files.
588  
589 More information on the LCFG build tools is available from the website
590 http://www.lcfg.org/doc/buildtools/
591  
592 =head1 ATTRIBUTES
593  
594 =over
595  
596 =item name
597  
598 This is the name of the project or LCFG component. In the case of the
599 component think of it as the "foo" part of "lcfg-foo". When an object
600 is created this field MUST be specified, there is no default value.
601  
602 =item base
603  
604 This is only really meaningful in terms of LCFG components, in which
605 case it is the "lcfg" part of "lcfg-foo" or the "dice" part of
606 "dice-foo". This is optional and the default value is an empty string.
607  
608 =item abstract
609  
610 This is a short description of the project, it is optional and there
611 is no default.
612  
613 =item version
614  
615 This is the version of the project, it is required and if not
616 specified at object creation time it will default to '0.0.0'. Due to
617 backwards compatibility reasons this version must be in 3 integer
618 parts separated with the period character. Any attempt to set it
619 otherwise will result in an error being thrown.
620  
621 =item release
622  
623 This is the release number for a project and is directly related to
624 the release field used for RPMs and Debian packages. It is optional
625 and defaults to 1. If used, the first character of the release field
626 MUST be an integer, after that you can put in whatever you like.
627  
628 =item schema
629  
630 This is only really meaningful in terms of LCFG components. It is the
631 schema number of the defaults file which specifies the details for the
632 supported resources. It is optional and will default to 1.
633  
634 =item group
635  
636 This is the software group into which this project best fits, it is
637 mainly provided for RPM specfile generation support
638 (e.g. "Development/Libraries"). It is optional and has no default
639 value.
640  
641 =item vendor
642  
643 This matches the "Vendor" field used in RPMs, it is optional and has
644 no default value.
645  
646 =item orgident
647  
648 This is an identifier for your organisation which is based on the
649 reversed form of your domain name, C<com.example> or C<org.example>
650 for example. No validation is done to check if this is the reversal of
651 a real domain name, you can use whatever you want, the default value
652 is C<org.lcfg>. This is used by the C<pkgident> method as part of the
653 process of generating MacOSX packages.
654  
655 =item license
656  
657 This is the short string used in RPMs to specify the license for the
658 project. This field is optional and there is no default value.
659  
660 =item date
661  
662 This is used to show the date and time at which the project version
663 was last altered. If not specified it will default to the current date
664 and time in the format 'DD/MM/YY HH:MM:SS'.
665  
666 =item author
667  
668 This is the name (or list of names) of the project author(s). The
669 default value is an empty list. You should note that calling this
670 accessor with no arguments returns a list not a scalar value. See
671 below for convenience methods provided for accessing and managing the
672 information contained with the list.
673  
674 =item platforms
675  
676 This is the list of supported platforms for the project. The default
677 value is an empty list. You should note that calling this accessor
678 with no arguments returns a list not a scalar value. See below for
679 convenience methods provided for accessing and managing the
680 information contained with the list.
681  
682 =item vcs
683  
684 This is a reference to a hash containing details of the version
685 control system used for the project. This is optional and defaults to
686 an empty hash. See below for convenience methods provided for
687 accessing and managing the information contained with the hash.
688  
689 =back
690  
691 =head1 SUBROUTINES/METHODS
692  
693 =over
694  
695 =item fullname
696  
697 Returns the full name of the package, if the 'base' attribute is
698 specified then this will be a combination of base and package name
699 separated with a hyphen, e.g. 'lcfg-foo'. If no base is specified then
700 this is just the package name, e.g. 'foo'.
701  
702 =item deb_name
703  
704 Returns a name for the package which is safe for use as a Debian
705 package name. Debian package names must not contain the C<_>
706 (underscore) character so those are replace with hyphens, also by
707 convention the name is lower-cased. Any invalid characters (not in the
708 set C<[a-zA-Z0-9-]>) are simply removed.
709  
710 =item deb_version
711  
712 Returns a version for the package which is safe for use with Debian
713 packages. Typically this will be identical to the standard C<version>
714 string. Debian package versions must only contain characters in the
715 set C<[a-zA-Z0-9~.+-]>, any invalid characters are simply removed
716  
717 =item deb_tarname
718  
719 Returns the name of the debian source package tarfile which would be
720 generated for this version of the package. This combines the full name
721 and the version, for example, C<lcfg-foo_1.0.1-1.debian.tar.gz>. Note
722 that the LCFG build tools will only actually generate this file when a
723 project contains a C<debian> sub-directory.
724  
725 =item deb_dscname
726  
727 Returns the name of the debian source control (dsc) file which would
728 be generated for this version of the package. This combines the full
729 name and the version, for example, C<lcfg-foo_1.0.1-1.dsc>. Note that
730 the LCFG build tools will only actually generate this file when a
731 project contains a C<debian> sub-directory.
732  
733 =item pkgident
734  
735 This returns a string formed by the concatenation of the C<orgident>
736 and C<fullname> values, joined with a period character,
737 C<com.example.lcfg-client> for example. This is used as the identifier
738 name for MacOSX packages.
739  
740 =item rpmspec_name
741  
742 This returns the name of the RPM specfile for the project. This is
743 just based on the full name with a C<.spec> suffix
744 (e.g. C<lcfg-foo.spec>).
745  
746 =item tarname
747  
748 Returns the standard LCFG name of the tarfile which would be generated
749 for this version of the package. This combines the full name and the
750 version, for example, C<lcfg-foo_1.0.1.orig.tar.gz>
751  
752 =item new_from_metafile($file)
753  
754 Create a new object which represents the LCFG build metadata stored in
755 the YAML file.
756  
757 =item save_metafile($file)
758  
759 Save the object data into the LCFG metadata file.
760  
761 =item new_from_cfgmk($file)
762  
763 Create from the old-style LCFG config.mk a new object which represents
764 the LCFG build metadata.
765  
766 =item perl_version
767  
768 This returns the package version as a string in a style which is safe
769 for use in Perl modules. If this is a development release the C<dev>
770 suffix is replaced with the value of the release. This is done because
771 Perl versions are not permitted to contain non-numeric characters.
772  
773 =item get_major
774  
775 Get just the major (first) part of the package version.
776  
777 =item get_minor
778  
779 Get just the minor (middle) part of the package version.
780  
781 =item get_micro
782  
783 Get just the micro (last) part of the package version.
784  
785 =item update_major
786  
787 Increment by one the first (largest) part of the version. This will
788 also reset the second and third parts of the version to 0 (zero) and
789 the release field to 1. For example, version 1.2.3 would become 2.0.0
790 and the release field would go from 5 to 1.
791  
792 =item update_minor
793  
794 Increment by one the second (middle) part of the version. This will
795 also reset the third part of the version to 0 (zero) and the release
796 field to 1. For example, version 1.2.3 would become 1.3.0 and the
797 release field would go from 5 to 1.
798  
799 =item update_micro
800  
801 Increment by one the third (smallest) part of the version field. This
802 will also reset the release field to 1. For example, version 1.2.3
803 would become 1.2.4 and the release field would go from 5 to 1.
804  
805 =item update_date
806  
807 Update the date attribute to the current time, this is set to the
808 format 'DD/MM/YY HH:MM::SS'. You should not normally need to call this
809 method, it is called at the end of the update_micro, update_minor and
810 update_major methods to show when the version update occurred.
811  
812 =item update_release
813  
814 This method updates the release field by incrementing the value. If it
815 was not previously defined then it will be set to one.
816  
817 =item dev_version
818  
819 This method converts the version to the development format. If it is
820 not already present an C<.dev> string is appended to the version
821 string along with the value of the release field. The release field is
822 also incremented. For example, the first dev version for C<1.2.3>
823 would be C<1.2.3.dev1> and the second would be C<1.2.3.dev2>.
824  
825 =item add_author
826  
827 A convenience method for adding new authors to the list of project
828 authors. Note that this does not prevent an author being added
829 multiple times.
830  
831 =item add_platform
832  
833 A convenience method for adding new platforms to the list of
834 supported platforms for this project. Note that this does not prevent
835 a platform being added multiple times.
836  
837 =item exists_in_vcsinfo($key)
838  
839 A convenience method to see if a particular key exists in the
840 version-control information.
841  
842 =item ids_in_vcsinfo
843  
844 A convenience method to get a list of all the keys in the
845 version-control information.
846  
847 =item get_vcsinfo($key)
848  
849 A convenience method to get the data associated with a particular key
850 in the version-control information.
851  
852 =item set_vcsinfo($key, $value)
853  
854 A convenience method to set the data associated with a particular key
855 in the version-control information.
856  
857 =item exists_in_buildinfo($key)
858  
859 A convenience method to see if a particular key exists in the
860 build information.
861  
862 =item ids_in_buildinfo
863  
864 A convenience method to get a list of all the keys in the
865 build information.
866  
867 =item get_buildinfo($key)
868  
869 A convenience method to get the data associated with a particular key
870 in the build information.
871  
872 =item set_buildinfo($key, $value)
873  
874 A convenience method to set the data associated with a particular key
875 in the build information.
876  
877 =back
878  
879 =head1 DEPENDENCIES
880  
881 This module is L<Moose> powered. It also requires
882 L<Data::Structure::Util>, L<DateTime> and if you want to parse and
883 write LCFG metadata files you will need L<YAML::Syck>.
884  
885 =head1 SEE ALSO
886  
887 lcfg-cfg2meta(1), lcfg-pkgcfg(1), LCFG::Build::Tools(3)
888  
889 =head1 PLATFORMS
890  
891 This is the list of platforms on which we have tested this
892 software. We expect this software to work on any Unix-like platform
893 which is supported by Perl.
894  
895 ScientificLinux5, ScientificLinux6
896  
897 =head1 BUGS AND LIMITATIONS
898  
899 There are no known bugs in this application. Please report any
900 problems to bugs@lcfg.org, feedback and patches are also always very
901 welcome.
902  
903 =head1 AUTHOR
904  
905 Stephen Quinney <squinney@inf.ed.ac.uk>
906  
907 =head1 LICENSE AND COPYRIGHT
908  
909 Copyright (C) 2008-2019 University of Edinburgh. All rights reserved.
910  
911 This library is free software; you can redistribute it and/or modify
912 it under the terms of the GPL, version 2 or later.
913  
914 =cut
↑ Summary Build »