Lines 11-18
use Koha::DateUtils qw( dt_from_string );
Link Here
|
11 |
use Bytes::Random::Secure; |
11 |
use Bytes::Random::Secure; |
12 |
use Carp qw( carp ); |
12 |
use Carp qw( carp ); |
13 |
use Module::Load qw( load ); |
13 |
use Module::Load qw( load ); |
14 |
use String::Random; |
|
|
15 |
use Array::Utils qw( array_minus ); |
14 |
use Array::Utils qw( array_minus ); |
|
|
15 |
use Text::Lorem; |
16 |
|
16 |
|
17 |
use constant { |
17 |
use constant { |
18 |
SIZE_BARCODE => 20, # Not perfect but avoid to fetch the value when creating a new item |
18 |
SIZE_BARCODE => 20, # Not perfect but avoid to fetch the value when creating a new item |
Lines 538-559
sub _gen_datetime {
Link Here
|
538 |
|
538 |
|
539 |
sub _gen_text { |
539 |
sub _gen_text { |
540 |
my ($self, $params) = @_; |
540 |
my ($self, $params) = @_; |
541 |
# From perldoc String::Random |
541 |
my $text = Text::Lorem->new(); |
|
|
542 |
my $words = $text->words(int(rand(10))); |
542 |
my $size = $params->{info}{size} // 10; |
543 |
my $size = $params->{info}{size} // 10; |
543 |
$size -= alt_rand(0.5 * $size); |
544 |
return length($words) > $size ? substr( $words, 1, $size ) : $words; |
544 |
my $regex = $size > 1 |
|
|
545 |
? '[A-Za-z][A-Za-z0-9_]{'.($size-1).'}' |
546 |
: '[A-Za-z]'; |
547 |
my $random = String::Random->new( rand_gen => \&alt_rand ); |
548 |
# rand_gen is only supported from 0.27 onward |
549 |
return $random->randregex($regex); |
550 |
} |
551 |
|
552 |
sub alt_rand { #Alternative randomizer |
553 |
my ($max) = @_; |
554 |
my $random = Bytes::Random::Secure->new( NonBlocking => 1 ); |
555 |
my $r = $random->irand / 2**32; |
556 |
return int( $r * $max ); |
557 |
} |
545 |
} |
558 |
|
546 |
|
559 |
sub _gen_set_enum { |
547 |
sub _gen_set_enum { |
560 |
- |
|
|