1 # This module is part of debbugs, and
2 # is released under the terms of the GPL version 2, or any later
3 # version (at your option). See the file README and COPYING for more
5 # Copyright 2018 by Don Armstrong <don@donarmstrong.com>.
7 package Debbugs::Version;
11 Debbugs::Version -- OO interface to Version
15 This package provides a convenient interface to refer to package versions and
16 potentially make calculations based upon them
19 my $v = Debbugs::Version->new(schema => $s,binaries => [qw(foo)],sources => [qw(bar)]);
30 use namespace::autoclean;
32 use Debbugs::Config qw(:config);
33 use Debbugs::Collection::Package;
37 extends 'Debbugs::OOBase';
39 =head1 Object Creation
41 =head2 my $version = Debbugs::Version::Source->new(%params|$param)
43 or C<Debbugs::Version::Binary->new(%params|$param)> for a binary version
49 L<Debbugs::DB> schema which can be used to look up versions
53 String representation of the package
57 L<Debbugs::Package> which refers to the package given.
59 Only one of C<package> or C<pkg> should be given
61 =item package_collection
63 L<Debbugs::Collection::Package> which is used to generate a L<Debbugs::Package>
64 object from the package name
70 around BUILDARGS => sub {
73 if ($class eq __PACKAGE__) {
74 confess("You should not be instantiating Debbugs::Version. ".
75 "Use Debbugs::Version::Source or ::Binary");
78 if (@_==1 and ref($_[0]) eq 'HASH') {
83 return $class->$orig(%args);
88 state $strong_severities =
89 {map {($_,1)} @{$config{strong_severities}}};
97 Returns the source or binary package version
101 has version => (is => 'ro', isa => 'Str',
103 builder => '_build_version',
104 predicate => '_has_version',
109 Returns 'source' if this is a source version, or 'binary' if this is a binary
114 =head2 source_version
116 Returns the source version for this version; if this is a source version,
123 Returns the fully qualified source_package/version string for this version.
129 Returns the name of the package that this version is in
133 has package => (is => 'ro',
135 builder => '_build_package',
136 predicate => '_has_package',
142 if ($self->_has_pkg) {
143 return $self->pkg->name;
150 Returns a L<Debbugs::Package> object corresponding to C<package>.
155 has pkg => (is => 'ro',
156 isa => 'Debbugs::Package',
158 builder => '_build_pkg',
160 predicate => '_has_pkg',
165 return Debbugs::Package->new(package => $self->package,
168 package_collection => $self->package_collection,
169 $self->schema_argument,
176 Returns 1 if this package is valid, 0 otherwise.
180 has valid => (is => 'ro',
182 reader => 'is_valid',
184 builder => '_build_valid',
193 =head2 package_collection
195 Returns the L<Debugs::Collection::Package> which is in use by this version
200 has 'package_collection' => (is => 'ro',
201 isa => 'Debbugs::Collection::Package',
202 builder => '_build_package_collection',
205 sub _build_package_collection {
207 return Debbugs::Collection::Package->new($self->schema_arg)
211 __PACKAGE__->meta->make_immutable;
218 # indent-tabs-mode: nil
219 # cperl-indent-level: 4