From 282178366d16758e5918b90b5074c2fba774255e Mon Sep 17 00:00:00 2001 From: Gerhard Gonter <ggonter@gmail.com> Date: Sat, 11 Apr 2015 05:35:12 +0200 Subject: [PATCH] playing with UUID generation --- perl/Gnome-Tomboy/lib/Tomboy.pm | 48 ++++++++++++++++++--------------- perl/Gnome-Tomboy/tom | 3 ++- perl/Gnome-Tomboy/x_uuid.pl | 38 +++++++++++++++++++------- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/perl/Gnome-Tomboy/lib/Tomboy.pm b/perl/Gnome-Tomboy/lib/Tomboy.pm index d614e6a..5ef5143 100644 --- a/perl/Gnome-Tomboy/lib/Tomboy.pm +++ b/perl/Gnome-Tomboy/lib/Tomboy.pm @@ -23,10 +23,35 @@ package Tomboy; use strict; -# use UUID; -use Data::UUID; 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 sub link @@ -56,25 +81,6 @@ sub ts_ISO 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 { my %par= @_; diff --git a/perl/Gnome-Tomboy/tom b/perl/Gnome-Tomboy/tom index fe0cee2..069ae14 100755 --- a/perl/Gnome-Tomboy/tom +++ b/perl/Gnome-Tomboy/tom @@ -51,6 +51,7 @@ use Tomboy::TOC; my $toc_file; my $note_dir= $ENV{'HOME'} . '/.local/share/tomboy'; +# TODO: does not work on cygwin! my $note_dir_changed= 0; my $start_tb= 0; @@ -71,7 +72,7 @@ while (my $arg= shift (@ARGV)) } elsif ($arg =~ /^--(.+)/) { - my ($op, $val)= split ('=', $1); + my ($op, $val)= split ('=', $1, 2); print "op=[$op] val=[$val]\n"; if ($op eq 'note-path') { $note_dir= $val || shift(@ARGV); $note_dir_changed= 1; } diff --git a/perl/Gnome-Tomboy/x_uuid.pl b/perl/Gnome-Tomboy/x_uuid.pl index 30998ae..42e99f5 100755 --- a/perl/Gnome-Tomboy/x_uuid.pl +++ b/perl/Gnome-Tomboy/x_uuid.pl @@ -2,10 +2,32 @@ use strict; -use UUID; -use Data::UUID; 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; 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); } -sub get_uuid_1 -{ - my ($uuid, $uuid_str); - UUID::generate ($uuid); - UUID::unparse ($uuid, $uuid_str); - $uuid_str; -} +=begin junk sub get_uuid_2b { @@ -34,6 +50,9 @@ sub get_uuid_2b $str; } +=end junk +=cut + sub get_uuid_2 { my $uc= new Data::UUID; @@ -48,3 +67,4 @@ sub ts_iso # print "ts_iso=[$ts_iso]\n"; $ts_iso; } + -- GitLab