--- nfo/perl/libs/shortcuts.pm 2003/03/29 07:24:10 1.7 +++ nfo/perl/libs/shortcuts.pm 2003/04/04 17:31:59 1.8 @@ -1,7 +1,10 @@ ## --------------------------------------------------------------------------- -## $Id: shortcuts.pm,v 1.7 2003/03/29 07:24:10 joko Exp $ +## $Id: shortcuts.pm,v 1.8 2003/04/04 17:31:59 joko Exp $ ## --------------------------------------------------------------------------- ## $Log: shortcuts.pm,v $ +## Revision 1.8 2003/04/04 17:31:59 joko +## + sub make_guid +## ## Revision 1.7 2003/03/29 07:24:10 joko ## enhanced 'run_cmd': now tries to execute program with appropriate application (e.g. 'cmd.exe' or 'perl') ## @@ -39,19 +42,20 @@ run_cmd run_cmds get_chomped bool2status + make_guid ); -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main - use Data::Dumper; use POSIX qw( strftime ); #use IPC::Run qw( run timeout ); use IPC::Run qw( start pump finish timeout ) ; +use Carp; + + # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; # see "perldoc -f localtime" - sub now { my $options = shift; my $pattern = "%Y-%m-%d %H:%M:%S"; @@ -153,5 +157,31 @@ sub RUNNING_IN_HELL () { $^O eq 'MSWin32' } +# create global unique identifers using Data::UUID +# if updating this code, please also modify Tangram::Storage::make_guid +sub make_guid + { + my $self = shift; + + my $guid; + + # try to use Data::UUID first ... + eval("use Data::UUID;"); + if (!$@) { + my $ug = Data::UUID->new(); + $guid = $ug->create_str(); + + # ... if this fails, try to fallback to Data::UUID::PurePerl instead ... + } else { + eval("use Data::UUID::PurePerl;"); + if (!$@) { + $guid = Data::UUID::PurePerl::generate_id(); + } else { + croak "couldn't create globally unique identifier"; + } + } + + return $guid; + } 1;