Exd/lib/Exd.pm
2024-10-29 19:11:29 +01:00

73 lines
1.5 KiB
Perl

package Exd;
use v5.40.0;
use strict;
use warnings;
use utf8;
use Moo;
use JSON;
use Path::Tiny;
use UUID::URandom qw/create_uuid_string/;
has config => ( is => 'lazy' );
sub _build_config($self) {
return JSON::from_json( $self->_config_file_name->slurp_utf8 );
}
sub _config_file_name($self) {
return path(__FILE__)->parent->parent->child('app_config.json');
}
sub licenser_server($self) {
return $self->config->{'licenser-server'};
}
sub debug($self) {
return $self->config->{debug};
}
sub uuid($self) {
require Exd::DB;
my $dbh = Exd::DB->connect;
my $key = 'licenser-uuid';
my $option =
$dbh->selectrow_hashref( 'SELECT value FROM options WHERE name = ?;',
{}, $key );
my $uuid;
if (defined $option) {
$uuid = $option->{value};
}
if ( !defined $uuid ) {
$uuid = create_uuid_string();
$dbh->do( 'INSERT OR IGNORE INTO options (name, value) VALUES (?, ?);',
{}, $key, $uuid );
}
return $uuid;
}
{
my $key = 'activated';
sub is_activated_license($self) {
require Exd::DB;
my $dbh = Exd::DB->connect;
my $option =
$dbh->selectrow_hashref( 'SELECT value FROM options WHERE name = ?;',
{}, $key );
if (!defined $option) {
return 0;
}
return $option->{value};
}
sub activate_license($self) {
require Exd::DB;
my $dbh = Exd::DB->connect;
$dbh->do( 'INSERT OR IGNORE INTO options (name, value) VALUES (?, ?);',
{}, $key, 1 );
}
}
1;