When I have needed unique IDs for use with Mojolicious, I've used Data::UUID
which generates long (128bit) numbers in line with RFC 4122
I can't be any more specific without a clearer idea of your use case, but this seems to work nicely:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::UUID;
my $gen = Data::UUID -> new();
my $binary_uuid = $gen -> create ;
print $gen -> to_string ( $binary_uuid ),"\n";
print $gen -> to_hexstring ( $binary_uuid ),"\n";
print $gen -> to_b64string ( $binary_uuid ),"\n";
You have a choice of output formats. You can, if it's useful to your application, create directly, e.g.:
my $gen = Data::UUID -> new();
my $uuid = $gen -> create_str ;
print $uuid, "\n";
#reformat output
print $gen -> to_hexstring ( $uuid ),"\n";
stealborrow the [idea from Plack::Middleware::RequestId](https://metacpan.org/source/BAYASHI/Plack-Middleware-RequestId-0.02/lib/Plack/Middleware/RequestId.pm#L27) and go with that. But as that is just a UUID that seems to use a random string, I would not rely on it to be honest. Furthermore, in case you are running your Dancer on CGI (you said not via Plack), all those stateful approaches are not going to work anyway. – simbabque May 08 '16 at 11:11