Skip to content
Snippets Groups Projects
Commit 28217836 authored by Gerhard Gonter's avatar Gerhard Gonter :speech_balloon:
Browse files

playing with UUID generation

parent 5e95f1a2
No related branches found
No related tags found
No related merge requests found
...@@ -23,10 +23,35 @@ package Tomboy; ...@@ -23,10 +23,35 @@ package Tomboy;
use strict; use strict;
# use UUID;
use Data::UUID;
use POSIX; use POSIX;
eval {
require UUID;
sub get_uuid
{
my ($uuid, $uuid_str);
UUID::generate ($uuid);
UUID::unparse ($uuid, $uuid_str);
$uuid_str;
}
};
if ($@)
{
eval { require Data::UUID; };
if ($@) { die "install either UUID or Data::UUID"; }
sub get_uuid
{
my $uc= new Data::UUID;
my $str= $uc->create_str();
$str =~ tr/A-F/a-f/;
$str;
}
}
my %options_passed= map { $_ => 1 } qw(--note-path); # used by start_tb() function my %options_passed= map { $_ => 1 } qw(--note-path); # used by start_tb() function
sub link sub link
...@@ -56,25 +81,6 @@ sub ts_ISO ...@@ -56,25 +81,6 @@ sub ts_ISO
strftime ('%FT%T.000000%z', @ts); strftime ('%FT%T.000000%z', @ts);
} }
sub get_uuid
{
=begin comment
my ($uuid, $uuid_str);
UUID::generate ($uuid);
UUID::unparse ($uuid, $uuid_str);
$uuid_str;
=end comment
=cut
my $uc= new Data::UUID;
my $str= $uc->create_str();
$str =~ tr/A-F/a-f/;
$str;
}
sub start_tb sub start_tb
{ {
my %par= @_; my %par= @_;
... ...
......
...@@ -51,6 +51,7 @@ use Tomboy::TOC; ...@@ -51,6 +51,7 @@ use Tomboy::TOC;
my $toc_file; my $toc_file;
my $note_dir= $ENV{'HOME'} . '/.local/share/tomboy'; my $note_dir= $ENV{'HOME'} . '/.local/share/tomboy';
# TODO: does not work on cygwin!
my $note_dir_changed= 0; my $note_dir_changed= 0;
my $start_tb= 0; my $start_tb= 0;
...@@ -71,7 +72,7 @@ while (my $arg= shift (@ARGV)) ...@@ -71,7 +72,7 @@ while (my $arg= shift (@ARGV))
} }
elsif ($arg =~ /^--(.+)/) elsif ($arg =~ /^--(.+)/)
{ {
my ($op, $val)= split ('=', $1); my ($op, $val)= split ('=', $1, 2);
print "op=[$op] val=[$val]\n"; print "op=[$op] val=[$val]\n";
if ($op eq 'note-path') { $note_dir= $val || shift(@ARGV); $note_dir_changed= 1; } if ($op eq 'note-path') { $note_dir= $val || shift(@ARGV); $note_dir_changed= 1; }
... ...
......
...@@ -2,10 +2,32 @@ ...@@ -2,10 +2,32 @@
use strict; use strict;
use UUID;
use Data::UUID;
use POSIX; use POSIX;
eval {
require UUID;
sub get_uuid_1
{
my ($uuid, $uuid_str);
UUID::generate ($uuid);
UUID::unparse ($uuid, $uuid_str);
$uuid_str;
}
};
if ($@)
{
print "no UUID package\n";
require Data::UUID;
sub get_uuid_1
{
get_uuid_2();
}
}
my $max= shift (@ARGV) || 10; my $max= shift (@ARGV) || 10;
for (my $i= 0; $i< $max; $i++) for (my $i= 0; $i< $max; $i++)
...@@ -16,13 +38,7 @@ for (my $i= 0; $i< $max; $i++) ...@@ -16,13 +38,7 @@ for (my $i= 0; $i< $max; $i++)
printf ("%5d %s %s %s\n", $i, $ts, $u1, $u2); printf ("%5d %s %s %s\n", $i, $ts, $u1, $u2);
} }
sub get_uuid_1 =begin junk
{
my ($uuid, $uuid_str);
UUID::generate ($uuid);
UUID::unparse ($uuid, $uuid_str);
$uuid_str;
}
sub get_uuid_2b sub get_uuid_2b
{ {
...@@ -34,6 +50,9 @@ sub get_uuid_2b ...@@ -34,6 +50,9 @@ sub get_uuid_2b
$str; $str;
} }
=end junk
=cut
sub get_uuid_2 sub get_uuid_2
{ {
my $uc= new Data::UUID; my $uc= new Data::UUID;
...@@ -48,3 +67,4 @@ sub ts_iso ...@@ -48,3 +67,4 @@ sub ts_iso
# print "ts_iso=[$ts_iso]\n"; # print "ts_iso=[$ts_iso]\n";
$ts_iso; $ts_iso;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment