舞者独特的请求ID

时间:2016-05-08 09:45:20

标签: perl dancer plack psgi

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

但是我错过了Dancer中有什么本地人吗?

1 个答案:

答案 0 :(得分:1)

如果我需要使用唯一ID与Mojolicious一起使用,我已使用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";