Skip to content

Commit 5d69942

Browse files
committed
Fix documentatin of create_random_string
1 parent ec49eea commit 5d69942

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Data::Random::String::Matches - Generate random strings matching a regex
2525
my $gen4 = Data::Random::String::Matches->new(qr/(ha){2,4}/);
2626
my $laugh = $gen4->generate_smart(); # "haha", "hahaha", or "hahahaha"
2727

28+
# Consistency with Legacy software
29+
print Data::Random::String::Matches->create_random_string(length => 3, regex => '\d{3}'), "\n";
30+
2831
# DESCRIPTION
2932

3033
This module generates random strings that match a given regular expression pattern.
@@ -115,7 +118,7 @@ than brute force, but may not handle all edge cases.
115118

116119
For consistency with [Data::Random::String](https://metacpan.org/pod/Data%3A%3ARandom%3A%3AString).
117120

118-
print Data::Random::String->create_random_string(length => 3, regex => '\d{3}'), "\n";
121+
print Data::Random::String::Matches->create_random_string(length => 3, regex => '\d{3}'), "\n";
119122

120123
# AUTHOR
121124

lib/Data/Random/String/Matches.pm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Data::Random::String::Matches - Generate random strings matching a regex
3535
my $gen4 = Data::Random::String::Matches->new(qr/(ha){2,4}/);
3636
my $laugh = $gen4->generate_smart(); # "haha", "hahaha", or "hahahaha"
3737
38+
# Consistency with Legacy software
39+
print Data::Random::String::Matches->create_random_string(length => 3, regex => '\d{3}'), "\n";
40+
3841
=head1 DESCRIPTION
3942
4043
This module generates random strings that match a given regular expression pattern.
@@ -161,7 +164,7 @@ C<$length> is optional and defaults to 10 (used for fallback generation).
161164
sub new {
162165
my ($class, $regex, $length) = @_;
163166

164-
croak "Regex pattern is required" unless defined $regex;
167+
croak 'Regex pattern is required' unless defined $regex;
165168

166169
# Convert string to regex if needed
167170
my $regex_obj = ref($regex) eq 'Regexp' ? $regex : qr/$regex/;
@@ -199,7 +202,7 @@ sub generate {
199202

200203
# If smart approach failed, show warning in debug mode
201204
if ($ENV{DEBUG_REGEX_GEN} && $@) {
202-
warn "Smart generation failed: $@\n";
205+
warn "Smart generation failed: $@";
203206
}
204207

205208
# Fall back to brute force with character set matching
@@ -335,7 +338,7 @@ sub _parse_sequence {
335338
} elsif ($char eq '[') {
336339
# Character class
337340
my $end = $self->_find_matching_bracket($pattern, $i);
338-
croak "Unmatched [" if $end == -1;
341+
croak 'Unmatched [' if $end == -1;
339342

340343
my $class = substr($pattern, $i+1, $end-$i-1);
341344
my ($generated, $new_i) = $self->_handle_quantifier($pattern, $end, sub {
@@ -346,7 +349,7 @@ sub _parse_sequence {
346349
} elsif ($char eq '(') {
347350
# Group
348351
my $end = $self->_find_matching_paren($pattern, $i);
349-
croak "Unmatched (" if $end == -1;
352+
croak 'Unmatched (' if $end == -1;
350353

351354
my $group_content = substr($pattern, $i+1, $end-$i-1);
352355

@@ -565,7 +568,7 @@ sub _random_from_class {
565568
566569
For consistency with L<Data::Random::String>.
567570
568-
print Data::Random::String->create_random_string(length => 3, regex => '\d{3}'), "\n";
571+
print Data::Random::String::Matches->create_random_string(length => 3, regex => '\d{3}'), "\n";
569572
570573
=cut
571574

t/30-basics.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ subtest 'Max attempts parameter' => sub {
9494

9595
# Temporarily break smart parser by making it return wrong result
9696
no warnings 'redefine';
97-
local *Data::Random::String::Matches::_build_from_pattern = sub { return "WRONG" };
97+
local *Data::Random::String::Matches::_build_from_pattern = sub { return 'WRONG' };
9898

9999
throws_ok {
100100
$gen->generate(10)

0 commit comments

Comments
 (0)