ABNF-Grammar
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/ABNF/Generator/Honest.pm view on Meta::CPAN
package ABNF::Generator::Honest;
=pod
=head1 NAME
B<ABNF::Generator::Honest> - class to generate valid messages for ABNF-based generators
It have $RECURSION_LIMIT = 16. You can change it to increase lower alarm bound on choices and repetition recursion.
but use it carefully!
=head1 INHERITANCE
B<ABNF::Generator::Honest>
isa B<ABNF::Generator>
=head1 DESCRIPTION
=head1 METHODS
=cut
use 5.014;
use strict;
use warnings;
no warnings "recursion";
use Data::Dumper;
use Readonly;
use List::Util qw(reduce);
use POSIX;
use base qw(ABNF::Generator Exporter);
use Method::Signatures; #some bug in B<Devel::Declare>...
use ABNF::Generator qw($CONVERTERS);
our @EXPORT_OK = qw(Honest);
our $RECURSION_LIMIT = 16;
=pod
=head1 ABNF::Generator::Honest->C<new>($grammar, $validator?)
Creates a new B<ABNF::Generator::Honest> object.
$grammar isa B<ABNF::Grammar>.
$validator isa B<ABNF::Validator>.
=cut
method new(ABNF::Grammar $grammar, ABNF::Validator $validator?) {
$self->SUPER::new($grammar, $validator ? $validator : ());
}
=pod
=head1 $honest->C<generate>($rule, $tail="")
Generates one valid sequence string for command $rule.
Using cache $self->{_cache}->{$rule} for this rule, that speeds up this call.
$rule is a command name.
$tail is a string added to result if it absent.
dies if there is no command like $rule.
=cut
method _range($rule, $recursion) {
my $converter = $CONVERTERS->{$rule->{type}};
my $min = $converter->($rule->{min});
my $max = $converter->($rule->{max});
return {class => "Atom", value => chr($min + int(rand($max - $min + 1)))};
}
method _string($rule, $recursion) {
my $converter = $CONVERTERS->{$rule->{type}};
return {
class => "Atom",
value => join("", map { chr($converter->($_)) } @{$rule->{value}})
};
}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.555 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )