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/; require XSLoader; XSLoader::load(); has config => ( is => 'lazy' ); sub _build_config($self) { return JSON::from_json( $self->_config_file_name->slurp_utf8 ); } sub _config_file_name($self) { $self->root->child('app_config.json'); } sub root($class) { return path(__FILE__)->parent->parent->parent; } 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;