Dancer中是否有唯一的请求ID?
Apache具有mod_unique_id:http://httpd.apache.org/docs/current/mod/mod_unique_id.html
PSGI/Plack有一个中间件模块:http://search.cpan.org/~bayashi/Plack-Middleware-RequestId-0.02/lib/Plack/Middleware/RequestId.pm
但我错过了《舞者》中的本土元素吗?
当我需要与Mojolicus一起使用的唯一ID时,我使用了Data::UUID
,它根据RFC 4122 生成长(128位)数字
如果没有对您的用例有一个更清晰的想法,我就不能再具体了,但这似乎很好:
#!/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";
您可以选择输出格式。如果它对您的应用程序有用,您可以直接创建,例如:
my $gen = Data::UUID -> new();
my $uuid = $gen -> create_str ;
print $uuid, "n";
#reformat output
print $gen -> to_hexstring ( $uuid ),"n";