Adding Peace::Model::Build with a simple compilation test

to be extended.
This commit is contained in:
sergiotarxz 2022-03-27 20:22:26 +02:00
parent a4dfabde09
commit 9f5d36fa89
5 changed files with 309 additions and 2 deletions

View File

@ -29,6 +29,9 @@
<li> <li>
<a href="lib/Peace/Model/Application.pm.html">Peace::Model::Application</a> <a href="lib/Peace/Model/Application.pm.html">Peace::Model::Application</a>
</li> </li>
<li>
<a href="lib/Peace/Model/Build.pm.html">Peace::Model::Build</a>
</li>
<li> <li>
<a href="lib/Peace/Model/Customer.pm.html">Peace::Model::Customer</a> <a href="lib/Peace/Model/Customer.pm.html">Peace::Model::Customer</a>
</li> </li>

View File

@ -0,0 +1,111 @@
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Peace::Model::Build - An object representing a release build for an architecture.</title>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<link href="mailto:Alpine@build-edge-aarch64.nonet" rev="made" />
</head>
<body>
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li><a href="#INSTANCE-METHODS">INSTANCE METHODS</a>
<ul>
<li><a href="#new">new</a></li>
</ul>
</li>
<li><a href="#METHODS">METHODS</a>
<ul>
<li><a href="#uuid">uuid</a></li>
<li><a href="#date_creation">date_creation</a></li>
<li><a href="#release">release</a></li>
<li><a href="#arch">arch</a></li>
</ul>
</li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>Peace::Model::Build - An object representing a release build for an architecture.</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code>my $build = Peace::Model::Build-&gt;new(
release =&gt; $release,
arch =&gt; $arch,
);</code></pre>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>Peace::Model::Build represents a successful build for an architecture of <a href="Release.pm.html">Peace::Model::Release</a>.</p>
<h1 id="INSTANCE-METHODS">INSTANCE METHODS</h1>
<p>Peace::Model::Build implements the following instance methods:</p>
<h2 id="new">new</h2>
<pre><code>my $build = Peace::Model::Build-&gt;new(
uuid =&gt; $uuid, # optional
date_creation =&gt; $date_creation, # optional
release =&gt; $release, # required or release_uuid should be passed.
release_uuid =&gt; $release_uuid, # required or release should be passed,
dbh =&gt; $dbh, # needed if release_uuid is passed.
arch =&gt; $arch,
);</code></pre>
<p>Instances a Peace::Model::Build.</p>
<h1 id="METHODS">METHODS</h1>
<p>Peace::Model::Build implements the following methods:</p>
<h2 id="uuid">uuid</h2>
<pre><code>my $uuid = $build-&gt;uuid;
$build-&gt;uuid($uuid);</code></pre>
<p>Allows to set and retrieve the uuid attribute.</p>
<h2 id="date_creation">date_creation</h2>
<pre><code>my $date_creation = $build-&gt;date_creation;
$build-&gt;date_creation($date_creation);</code></pre>
<p>Allows to set and retrieve the date_creation attribute as a <a href="https://metacpan.org/pod/DateTime">DateTime</a>.</p>
<h2 id="release">release</h2>
<pre><code>my $release = $build-&gt;release;
$build-&gt;release($release);</code></pre>
<p>Allows to set and retrieve the release attribute as a <a href="Release.pm.html">Peace::Model::Release</a>.</p>
<h2 id="arch">arch</h2>
<pre><code>my $arch = $build-&gt;arch;
$build-&gt;arch($arch);</code></pre>
<p>Allows to set and retrieve the architecture attribute.</p>
<h1 id="SEE-ALSO">SEE ALSO</h1>
<p><a href="Release.pm.html">Peace::Model::Release</a>, <a href="https://metacpan.org/pod/Peace::DAO::Build">Peace::DAO::Build</a></p>
</body>
</html>

View File

@ -63,7 +63,7 @@ my @migrations = (
'CREATE TABLE builds ( 'CREATE TABLE builds (
uuid UUID NOT NULL DEFAULT gen_random_uuid(), uuid UUID NOT NULL DEFAULT gen_random_uuid(),
release UUID NOT NULL, release UUID NOT NULL,
date timestamp DEFAULT NOW(), date_creation timestamp DEFAULT NOW(),
arch TEXT NOT NULL, arch TEXT NOT NULL,
PRIMARY KEY (uuid), PRIMARY KEY (uuid),
FOREIGN KEY (release) REFERENCES releases (uuid) FOREIGN KEY (release) REFERENCES releases (uuid)
@ -71,7 +71,7 @@ my @migrations = (
'CREATE TABLE purchases ( 'CREATE TABLE purchases (
customer UUID NOT NULL, customer UUID NOT NULL,
application UUID NOT NULL, application UUID NOT NULL,
date timestamp DEFAULT NOW(), date_purchase timestamp DEFAULT NOW(),
PRIMARY KEY (customer, application), PRIMARY KEY (customer, application),
FOREIGN KEY (application) REFERENCES applications (uuid), FOREIGN KEY (application) REFERENCES applications (uuid),
FOREIGN KEY (customer) REFERENCES customers (uuid) FOREIGN KEY (customer) REFERENCES customers (uuid)

182
lib/Peace/Model/Build.pm Normal file
View File

@ -0,0 +1,182 @@
package Peace::Model::Build;
use v5.30.0;
use strict;
use warnings;
use Params::ValidationCompiler qw/validation_for/;
use Types::Standard qw/Str InstanceOf Bool HasMethods/;
use DateTime;
use Peace::DAO::Release;
{
my $validator = validation_for(
params => {
uuid => { type => Str, optional => 1 },
date_creation => { type => InstanceOf ['DateTime'], optional => 1 },
release =>
{ type => InstanceOf ['Peace::Model::Release'], optional => 1 },
release_uuid => { type => Str, optional => 1, },
dbh => { type => HasMethods ['selectall_arrayref'], optional => 1 },
arch => { type => Str, },
}
);
sub new {
my $class = shift;
my %params = $validator->(@_);
die 'release or release_uuid should be passed on construct'
unless exists $params{release}
|| ( exists $params{release_uuid} && exists $params{dbh} );
my $self = bless {%params}, $class;
return $self;
}
}
{
my $validator =
validation_for( params => [ { type => Str, optional => 1 }, ] );
sub uuid {
my $self = shift;
if (@_) {
my ($new_uuid) = $validator->(@_);
$self->{uuid} = $new_uuid;
}
return $self->{uuid};
}
}
{
my $validator = validation_for(
params => [ { type => InstanceOf ['DateTime'], optional => 1 } ] );
sub date_creation {
my $self = shift;
if (@_) {
my ($new_date_creation) = $validator->(@_);
$self->{date_creation} = $new_date_creation;
}
return $self->{date_creation};
}
}
{
my $validator = validation_for( params =>
{ { type => InstanceOf ['Peace::Model::Release'], optional => 1 } } );
sub release {
my $self = shift;
if (@_) {
my ($new_release) = $validator->(@_);
$self->{release} = $new_release;
}
if ( !defined $self->{release} ) {
my $release_dao = Peace::DAO::Release->new( dbh => $self->_dbh );
$self->{release} =
$release_dao->recover_by_uuid( uuid => $self->{release_uuid} );
}
return $self->{release};
}
}
{
my $validator =
validation_for( params => [ { type => Str, optional => 1, } ] );
sub arch {
my $self = shift;
if (@_) {
my ($new_arch) = $validator->(@_);
$self->{arch} = $new_arch;
}
return $self->{arch};
}
}
sub _dbh {
my $self = shift;
return $self->{dbh};
}
1;
=encoding utf8
=head1 NAME
Peace::Model::Build - An object representing a release build for an
architecture.
=head1 SYNOPSIS
my $build = Peace::Model::Build->new(
release => $release,
arch => $arch,
);
=head1 DESCRIPTION
Peace::Model::Build represents a successful build for an
architecture of L<Peace::Model::Release>.
=head1 INSTANCE METHODS
Peace::Model::Build implements the following instance methods:
=head2 new
my $build = Peace::Model::Build->new(
uuid => $uuid, # optional
date_creation => $date_creation, # optional
release => $release, # required or release_uuid should be passed.
release_uuid => $release_uuid, # required or release should be passed,
dbh => $dbh, # needed if release_uuid is passed.
arch => $arch,
);
Instances a Peace::Model::Build.
=head1 METHODS
Peace::Model::Build implements the following methods:
=head2 uuid
my $uuid = $build->uuid;
$build->uuid($uuid);
Allows to set and retrieve the uuid attribute.
=head2 date_creation
my $date_creation = $build->date_creation;
$build->date_creation($date_creation);
Allows to set and retrieve the date_creation attribute as a L<DateTime>.
=head2 release
my $release = $build->release;
$build->release($release);
Allows to set and retrieve the release attribute as a L<Peace::Model::Release>.
=head2 arch
my $arch = $build->arch;
$build->arch($arch);
Allows to set and retrieve the architecture attribute.
=head1 SEE ALSO
L<Peace::Model::Release>, L<Peace::DAO::Build>
=cut

11
t/00011-build-model.t Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env perl
use v5.30.0;
use strict;
use warnings;
use Test::Most tests => 1;
BEGIN {
use_ok('Peace::Model::Build');
}