Use Linux uuid facility instead of an external library if possible
authorSimon McVittie <smcv@debian.org>
Tue, 1 Jul 2014 07:29:20 +0000 (08:29 +0100)
committerSimon McVittie <smcv@debian.org>
Mon, 1 Sep 2014 07:54:37 +0000 (08:54 +0100)
IkiWiki/Plugin/edittemplate.pm
doc/ikiwiki/directive/edittemplate.mdwn

index b408dfcac1faf5af44bd03c1c0e4ced5b832107e..571accf1f5c442eb1d0bb1096a79eeb187a6a51d 100644 (file)
@@ -140,13 +140,19 @@ sub filltemplate ($$) {
        $template->param(name => $page);
 
        if ($template->query(name => 'uuid')) {
-               eval {
-                       require UUID::Tiny;
-                       UUID::Tiny->import(':std');
-                       my $uuid;
-                       $uuid = create_uuid_as_string(UUID_V4());
-                       $template->param(uuid => $uuid);
-               };
+               my $uuid;
+               if (open(my $fh, "<", "/proc/sys/kernel/random/uuid")) {
+                       $uuid = <$fh>;
+                       chomp $uuid;
+                       close $fh;
+               }
+               else {
+                       eval {
+                               require UUID::Tiny;
+                               $uuid = UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V4());
+                       };
+               }
+               $template->param(uuid => $uuid);
        }
 
        return $template->output;
index 151fd203ac4e124ccc42fdaf36eca8ee08aab13a..63df23914f721b6c6ebf7c1e64216595aa6eb12d 100644 (file)
@@ -35,6 +35,6 @@ Two variables might be set:
   created.
   
 * `<TMPL_VAR uuid>` is replaced with a version 4 (random) UUID.
-  (Requires the `UUID::Tiny` Perl module.)
+  (Requires the `UUID::Tiny` Perl module if not running on Linux.)
 
 [[!meta robots="noindex, follow"]]