Adding Release Model and multiple doc improvements.

This commit is contained in:
sergiotarxz 2022-03-24 18:52:35 +01:00
parent 8ad9fcb01f
commit 436edcef00
8 changed files with 409 additions and 4 deletions

View File

@ -32,6 +32,9 @@
<li>
<a href="lib/Peace/Model/Developer.pm.html">Peace::Model::Developer</a>
</li>
<li>
<a href="lib/Peace/Model/Release.pm.html">Peace::Model::Release</a>
</li>
</ul>
</body>
</html>

View File

@ -56,7 +56,7 @@
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>Describes a application from Peace for sale.</p>
<p>Describes an application from Peace for sale.</p>
<h1 id="INSTANCE-METHODS">INSTANCE METHODS</h1>

View File

@ -0,0 +1,120 @@
<?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::Release - The release object representation.</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="#application">application</a></li>
<li><a href="#tag">tag</a></li>
<li><a href="#name">name</a></li>
</ul>
</li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>Peace::Model::Release - The release object representation.</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code>my $release = Peace::Model::Release-&gt;new(
application =&gt; $application,
tag =&gt; $tag,
name =&gt; $name,
);</code></pre>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>Describes a release from an application from Peace.</p>
<h1 id="INSTANCE-METHODS">INSTANCE METHODS</h1>
<p>Peace::Model::Release implements the following instance methods:</p>
<h2 id="new">new</h2>
<pre><code>my $release = Peace::Model::Release-&gt;new(
uuid =&gt; $uuid, # optional
date_creation =&gt; $date_creation, # optional
application =&gt; $application, # required or application_uuid should be passed.
application_uuid =&gt; $application_uuid, # required or application should be passed
dbh =&gt; $dbh, # needed if application_uuid is passed
tag =&gt; $tag,
name =&gt; $name,
);</code></pre>
<h1 id="METHODS">METHODS</h1>
<p>Peace::Model::Release implements the following methods:</p>
<h2 id="uuid">uuid</h2>
<pre><code>my $uuid = $release-&gt;uuid;
$release-&gt;uuid($uuid);</code></pre>
<p>Allows to retrieve and set the release uuid.</p>
<h2 id="date_creation">date_creation</h2>
<pre><code>my $date_creation = $release-&gt;date_creation;
$release-&gt;date_creation($date_creation);</code></pre>
<p>Allows to retrieve and set the release date creation as a <a href="https://metacpan.org/pod/DateTime">DateTime</a>.</p>
<h2 id="application">application</h2>
<pre><code>my $application = $release-&gt;application;
$release-&gt;application($application);</code></pre>
<p>Allows to retrieve and set the release application as a <a href="Application.pm.html">Peace::Model::Application</a>.</p>
<h2 id="tag">tag</h2>
<pre><code>my $tag = $release-&gt;tag;
$release-&gt;tag($tag);</code></pre>
<p>Allows to retrieve and set the release tag.</p>
<h2 id="name">name</h2>
<pre><code>my $name = $release-&gt;name
$release-&gt;name($name);</code></pre>
<p>Allows to retrieve and set the release name.</p>
<h1 id="SEE-ALSO">SEE ALSO</h1>
<p><a href="Application.pm.html">Peace::Model::Application</a>, <a href="https://metacpan.org/pod/Peace::DAO::Release">Peace::DAO::Release</a></p>
</body>
</html>

View File

@ -52,8 +52,8 @@ my @migrations = (
);',
'CREATE TABLE releases (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
application UUID NOT NULL,
date timestamp DEFAULT NOW(),
application UUID NOT NULL,
tag TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (uuid),

View File

@ -218,7 +218,7 @@ Peace::Model::Application - The application object representation.
=head1 DESCRIPTION
Describes a application from Peace for sale.
Describes an application from Peace for sale.
=head1 INSTANCE METHODS

212
lib/Peace/Model/Release.pm Normal file
View File

@ -0,0 +1,212 @@
package Peace::Model::Release;
use v5.30.0;
use strict;
use warnings;
use Params::ValidationCompiler qw/validation_for/;
use Types::Standard qw/InstanceOf Str HasMethods/;
{
my $validator = validation_for(
params => {
uuid => { type => Str, optional => 1 },
date_creation => { type => InstanceOf ['DateTime'], optional => 1 },
application => {
type => InstanceOf ['Peace::Model::Application'],
optional => 1
},
application_uuid => { type => Str, optional => 1 },
dbh => { type => HasMethods ['selectrow_hashref'], optional => 1 },
tag => { type => Str },
name => { type => Str },
}
);
sub new {
my $class = shift;
my %params = $validator->(@_);
die
'application or application_uuid with dbh should be passed on construct'
unless exists $params{application}
|| ( exists $params{application_uuid} && exists $params{dbh} );
return bless {%params}, $class;
}
}
{
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::Application'], optional => 1 }
]
);
sub application {
my $self = shift;
if (@_) {
my ($new_application) = $validator->(@_);
$self->{application} = $new_application;
}
unless ( exists $self->{developer} ) {
my $application_uuid = $self->{application_uuid};
my $application_dao =
Peace::DAO::Application->new( dbh => $self->_dbh );
$self->{application} =
$application_dao->recover_by_uuid( uuid => $application_uuid );
}
return $self->{application};
}
}
{
my $validator = validation_for(
params => [
{
type => Str, optional => 1,
}
]
);
sub tag {
my $self = shift;
if (@_) {
my $new_tag = $validator->(@_);
$self->{tag} = $new_tag;
}
return $self->{tag};
}
}
{
my $validator = validation_for(
params => [
{ type => Str, optional => 1 },
]
);
sub name {
my $self = shift;
if (@_) {
my ($new_name) = $validator->(@_);
$self->{name} = $new_name;
}
return $self->{name};
}
}
1;
=encoding utf8
=head1 NAME
Peace::Model::Release - The release object representation.
=head1 SYNOPSIS
my $release = Peace::Model::Release->new(
application => $application,
tag => $tag,
name => $name,
);
=head1 DESCRIPTION
Describes a release from an application from Peace.
=head1 INSTANCE METHODS
Peace::Model::Release implements the following instance
methods:
=head2 new
my $release = Peace::Model::Release->new(
uuid => $uuid, # optional
date_creation => $date_creation, # optional
application => $application, # required or application_uuid should be passed.
application_uuid => $application_uuid, # required or application should be passed
dbh => $dbh, # needed if application_uuid is passed
tag => $tag,
name => $name,
);
=head1 METHODS
Peace::Model::Release implements the following methods:
=head2 uuid
my $uuid = $release->uuid;
$release->uuid($uuid);
Allows to retrieve and set the release uuid.
=head2 date_creation
my $date_creation = $release->date_creation;
$release->date_creation($date_creation);
Allows to retrieve and set the release date creation as a L<DateTime>.
=head2 application
my $application = $release->application;
$release->application($application);
Allows to retrieve and set the release application as a L<Peace::Model::Application>.
=head2 tag
my $tag = $release->tag;
$release->tag($tag);
Allows to retrieve and set the release tag.
=head2 name
my $name = $release->name
$release->name($name);
Allows to retrieve and set the release name.
=head1 SEE ALSO
L<Peace::Model::Application>, L<Peace::DAO::Release>
=cut

View File

@ -5,7 +5,7 @@ use v5.30.0;
use strict;
use warnings;
use Test::Most tests => 9;
use Test::Most;
use Test::Pod::Coverage;
{
@ -14,3 +14,5 @@ use Test::Pod::Coverage;
pod_coverage_ok($module);
}
}
done_testing;

68
t/00009-release-model.t Normal file
View File

@ -0,0 +1,68 @@
use v5.30.0;
use strict;
use warnings;
use Test::Most tests => 4;
use Peace::Model::Application;
use Peace::Model::Developer;
BEGIN {
use_ok 'Peace::Model::Release';
}
{
## GIVEN
### Developer data.
my $developer_secret_bcrypt = 'hola';
my $developer_name = 'Larry';
my $developer_surname = 'Wall';
my $developer_email = 'larry@perl.org';
my $developer_country = 'US';
my $developer_verified = 0;
### Application data.
my $app_name = 'Desfronificator';
my $app_description = 'Desfronifies the files.';
my $app_url = 'https://desfronificator.example.com';
my $app_price = '4.20';
my $app_git_repo =
'https://git.desfronificator.example.com/larry/desfronificator.git';
my $app_flatpak_builder_file =
'./resources/com.example.desfronificator.yml';
my $app_verified = 0;
my $app_developer = Peace::Model::Developer->new(
secret_bcrypt => $developer_secret_bcrypt,
name => $developer_name,
surname => $developer_surname,
email => $developer_email,
country => $developer_country,
verified => $developer_verified,
);
### Release data.
my $release_application = Peace::Model::Application->new(
developer => $app_developer,
name => $app_name,
description => $app_description,
url => $app_url,
price => $app_price,
flatpak_builder_file => $app_flatpak_builder_file,
verified => $app_verified,
git_repo => $app_git_repo,
);
my $release_name = '0.0.1';
my $release_tag = 'v0.0.1';
## WHEN
my $release = Peace::Model::Release->new(
name => $release_name,
application => $release_application,
tag => $release_tag
);
## THEN
ok $release->isa('Peace::Model::Release'),
'Instanced release is made of Peace::Model::Release.';
is $release->name, $release_name, 'Name is correctly setup';
is $release->uuid, undef, 'Uuid is undef.';
}