From 4bf24d9313872d80485a393e4c478a82d88a7db5 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sat, 28 Dec 2024 12:41:46 +0100 Subject: [PATCH] initialize prng late --- lib/MetaCPAN/CSP.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/MetaCPAN/CSP.pm b/lib/MetaCPAN/CSP.pm index 43fc74e..525e3ab 100644 --- a/lib/MetaCPAN/CSP.pm +++ b/lib/MetaCPAN/CSP.pm @@ -31,15 +31,16 @@ has _directives => ( }, ); -my $rng = Math::Random::ISAAC::XS->new( unpack( "C*", urandom_ub(16) ) ); - -sub _nonce_generator { - sprintf( '%x', $rng->irand ); +sub _build_nonce_generator { + my $rng = Math::Random::ISAAC::XS->new( unpack( "C*", urandom_ub(16) ) ); + sub { + sprintf( '%x', $rng->irand ); + }; } has nonce_gen => ( - is => 'ro', - default => sub { \&_nonce_generator }, + is => 'lazy', + builder => 1, ); has nonce => (