Peace/lib/Peace/Model/Application.pm

334 lines
7.9 KiB
Perl

package Peace::Model::Application;
use v5.30.0;
use strict;
use warnings;
use Data::Dumper;
use Params::ValidationCompiler qw/validation_for/;
use Types::Standard qw/Str InstanceOf Bool Num HasMethods/;
use DateTime;
{
my $validator = validation_for(
params => {
uuid => { type => Str, optional => 1 },
date_creation => { type => InstanceOf ['DateTime'], optional => 1 },
name => { type => Str },
description => { type => Str },
url => { type => Str },
developer =>
{ type => InstanceOf ['Peace::Model::Developer'], optional => 1 },
developer_uuid => { type => Str, optional => 1 },
dbh => { type => HasMethods ['selectrow_hashref'], optional => 1 },
price => { type => Num },
git_repo => { type => Str },
flatpak_builder_file => { type => Str },
verified => { type => Bool },
}
);
sub new {
my $class = shift;
my %params = $validator->(@_);
die 'developer or developer_uuid should be passed on construct'
unless exists $params{developer}
|| ( exists $params{developer_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 => Str, optional => 1 } ] );
sub name {
my $self = shift;
if (@_) {
my ($new_name) = $validator->(@_);
$self->{name} = $new_name;
}
return $self->{name};
}
}
{
my $validator =
validation_for( params => [ { type => Str, optional => 1 } ] );
sub description {
my $self = shift;
if (@_) {
my ($new_description) = $validator->(@_);
$self->{description} = $new_description;
}
return $self->{description};
}
}
{
my $validator =
validation_for( params => [ { type => Str, optional => 1 } ] );
sub url {
my $self = shift;
if (@_) {
my ($new_url) = $validator->(@_);
$self->{url} = $new_url;
}
return $self->{url};
}
}
{
my $validator =
validation_for( params =>
[ { type => InstanceOf ['Peace::Model::Developer'], optional => 1 } ]
);
sub developer {
my $self = shift;
if (@_) {
my ($new_developer) = $validator->(@_);
$self->{developer} = $new_developer;
}
unless ( exists $self->{developer} ) {
my $developer_uuid = $self->{developer_uuid};
my $developer_dao =
Peace::DAO::Developer->new( dbh => $self->_dbh );
$self->{developer} =
$developer_dao->recover_by_uuid( uuid => $developer_uuid );
}
return $self->{developer};
}
}
{
my $validator =
validation_for( params => [ { type => Num, optional => 1 } ] );
sub price {
my $self = shift;
if (@_) {
my ($new_price) = $validator->(@_);
$self->{price} = $new_price;
}
return $self->{price};
}
}
{
my $validator =
validation_for( params => [ { type => Str, optional => 1 } ] );
sub flatpak_builder_file {
my $self = shift;
if (@_) {
my ($new_flatpak_builder_file) = $validator->(@_);
$self->{flatpak_builder_file} = $new_flatpak_builder_file;
}
return $self->{flatpak_builder_file};
}
}
{
my $validator =
validation_for( params => [ { type => Bool, optional => 1 } ] );
sub verified {
my $self = shift;
if (@_) {
my ($new_verified) = $validator->(@_);
$self->{verified} = $new_verified;
}
return $self->{verified};
}
}
{
my $validator =
validation_for( params => [ { type => Str, optional => 1 } ] );
sub git_repo {
my $self = shift;
if (@_) {
my ($new_git_repo) = $validator->(@_);
$self->{git_repo} = $new_git_repo;
}
return $self->{git_repo};
}
}
sub _dbh {
my $self = shift;
return $self->{dbh};
}
1;
=encoding utf8
=head1 NAME
Peace::Model::Application - The application object representation.
=head1 SYNOPSIS
my $application = Peace::Model::Application->new(
name => $name,
description => $description,
url => $url,
developer => $developer,
price => $price,
git_repo => $git_repo,
flatpak_builder_file => $flatpak_builder_file,
verified => $verified,
);
=head1 DESCRIPTION
Describes an application from Peace for sale.
=head1 INSTANCE METHODS
Peace::Model::Application implements the following instance methods:
=head2 new
my $application = Peace::Model::Application->new(
uuid => $uuid, # optional
date_creation => $date_creation, # optional
name => $name,
description => $description,
url => $url,
developer => $developer, # required or developer_uuid should be passed.
developer_uuid => $developer_uuid, # required or developer should be passed.
dbh => $dbh, # needed if developer_uuid is passed.
price => $price,
git_repo => $git_repo,
flatpak_builder_file => $flatpak_builder_file,
verified => $verified,
);
=head1 METHODS
Peace::Model::Application implements the following methods:
=head2 uuid
my $uuid = $application->uuid;
$application->uuid($uuid);
Allows to retrieve and set the application's uuid.
=head2 date_creation
my $date_creation = $application->date_creation;
$application->date_creation($date_creation);
Allows to retrieve and set the application's date_creation.
=head2 name
my $name = $application->name;
$application->name($name);
Allows to retrieve and set the application's name.
=head2 description
my $description = $application->description;
$application->description($description);
Allows to retrieve and set the application's description.
=head2 url
my $url = $application->url;
$application->url($url);
Allows to retrieve and set the application's url.
=head2 developer
my $developer = $application->developer;
$application->developer($developer);
Allows to retrieve and set the application's developer which
is a L<Peace::Model::Developer>.
=head2 price
my $price = $application->price;
$application->price($price);
Allows to retrieve and set the application's price.
=head2 git_repo
my $git_repo = $application->git_repo;
$application->git_repo($git_repo);
Allows to retrieve and set the application's git_repo.
=head2 flatpak_builder_file
my $flatpak_builder_file = $application->flatpak_builder_file;
$application->flatpak_builder_file($flatpak_builder_file);
Allows to retrieve and set the application's flatpak_builder_file.
=head2 verified
my $verified = $application->verified;
$application->verified($verified);
Allows to retrieve and set the application's verified status.
=head1 SEE ALSO
L<Peace::Model::Developer>, L<Peace::DAO::Application>
=cut