2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-08 07:24:21 +00:00

CTZ.pm: check required Perl modules

git-svn-id: https://svn.fhem.de/fhem/trunk@25816 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2022-03-12 21:10:51 +00:00
parent 144372f3c2
commit 13c2539908

View File

@ -26,6 +26,7 @@
######################################################################################################################### #########################################################################################################################
# Version History # Version History
# 0.0.2 12.03.2022 check required Perl modules
# 0.0.1 10.03.2022 initial # 0.0.1 10.03.2022 initial
package FHEM::Utility::CTZ; package FHEM::Utility::CTZ;
@ -34,11 +35,12 @@ use strict;
use warnings; use warnings;
use utf8; use utf8;
use lib qw(/opt/fhem/FHEM /opt/fhem/lib); # für Syntaxcheck mit: perl -c /opt/fhem/lib/FHEM/Utility/CTZ.pm # use lib qw(/opt/fhem/FHEM /opt/fhem/lib); # für Syntaxcheck mit: perl -c /opt/fhem/lib/FHEM/Utility/CTZ.pm
use GPUtils qw( GP_Import GP_Export ); use GPUtils qw( GP_Import GP_Export );
use DateTime;
use DateTime::Format::Strptime; eval "use DateTime;1" or my $abs0 = 'DateTime';
eval "use DateTime::Format::Strptime;1" or my $abs1 = 'DateTime::Format::Strptime';
use version 0.77; our $VERSION = version->declare('0.0.1'); use version 0.77; our $VERSION = version->declare('0.0.1');
@ -82,6 +84,9 @@ sub convertTimeZone {
return $err; return $err;
} }
my $abs = modabsent();
return $abs if($abs);
my $name = $paref->{name} // $pkg; my $name = $paref->{name} // $pkg;
my $dtstring = $paref->{dtstring} // q{}; my $dtstring = $paref->{dtstring} // q{};
my $tzcurrent = $paref->{tzcurrent} // 'local'; my $tzcurrent = $paref->{tzcurrent} // 'local';
@ -127,9 +132,32 @@ return $valid;
# returns an array reference list of all possible time zone names # returns an array reference list of all possible time zone names
############################################################################### ###############################################################################
sub getTZNames { sub getTZNames {
if(modabsent()) {
return [qw()];
}
my $atz = DateTime::TimeZone->all_names; my $atz = DateTime::TimeZone->all_names;
return $atz; return $atz;
} }
###############################################################################
# Check required Perl modules
###############################################################################
sub modabsent {
if ($abs0 || $abs1) {
$abs0 //= q{};
$abs1 //= q{};
my $err = qq{the perl module "$abs0" and/or "$abs1" is not installed};
Log (1, "$pkg - ERROR - $err");
return $err;
}
return;
}
1; 1;