From 14ffd7c769e3645c623832dd084b7e00bce25c4f Mon Sep 17 00:00:00 2001 From: darthgandalf Date: Mon, 27 Sep 2010 14:29:40 +0000 Subject: [PATCH] Improve portability of modperl by trying several UUID generators. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2146 726aef4b-f618-498e-8847-2d620e286838 --- modules/modperl/startup.pl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index d00662e7..70329902 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -9,21 +9,45 @@ use strict; use warnings; use ZNC; -use Data::UUID; use IO::File; -use feature 'switch'; +use feature 'switch', 'say'; package ZNC::Core; +my $uuidtype; my $uuidgen; our %pmods; sub Init { - $uuidgen = new Data::UUID; + if (eval { require Data::UUID }) { + $uuidtype = 'Data::UUID'; + $uuidgen = new Data::UUID; + } elsif (eval { require UUID }) { + $uuidtype = 'UUID'; + } else { + $uuidtype = 'int'; + $uuidgen = 0; + } } sub CreateUUID { - $uuidgen->create_str; + my $res; + given ($uuidtype) { + when ('Data::UUID') { + $res = $uuidgen->create_str; + } + when ('UUID') { + my ($uuid, $str); + UUID::generate($uuid); + UUID::unparse($uuid, $res); + } + when ('int') { + $uuidgen++; + $res = "$uuidgen"; + } + } + say "Created new UUID for modperl with '$uuidtype': $res"; + return $res; } sub unloadByIDUser {