ABNF-Grammar
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/ABNF/Generator.pm view on Meta::CPAN
package ABNF::Generator;
=pod
=head1 NAME
B<ABNF::Generator> - abstract base class for ABNF-based generators
=head1 INHERITANCE
B<ABNF::Generator> is the root of the Honest and Liar generators
=head1 DESCRIPTION
B<ABNF::Generator> is the abstract base class for ABNF-based generators.
Also it provides function B<asStrings> to stringified generated sequences
=head1 METHODS
=cut
use 5.014;
use strict;
use warnings;
no warnings "recursion";
use Carp;
use Readonly;
use Method::Signatures;
use Data::Dumper;
use Parse::ABNF;
use List::Util qw(shuffle);
use ABNF::Grammar qw($BASIC_RULES splitRule);
use ABNF::Validator;
use base qw(Exporter);
our @EXPORT_OK = qw($CONVERTERS $BASIC_RULES $RECURSION_LIMIT);
Readonly our $CHOICE_LIMIT => 128;
Readonly our $CONVERTERS => {
"hex" => sub { hex($_[0]) },
"bin" => sub { oct($_[0]) },
"decimal" => sub { int($_[0]) },
};
=pod
=head1 ABNF::Generator->C<new>($grammar, $validator?)
Creates a new B<ABNF::Generator> object.
$grammar isa B<ABNF::Grammar>.
$validator isa B<ABNF::Validator>.
Children classes can get acces for them by $self->{_grammar} and $self->{_validator}
=cut
method new(ABNF::Grammar $grammar, ABNF::Validator $validator?) {
my $class = ref($self) || $self;
croak "Cant create instance of abstract class" if $class eq 'ABNF::Generator';
$self = {
_cache => {},
_grammar => $grammar,
_validator => $validator || ABNF::Validator->new($grammar)
};
bless($self, $class);
$self->_init();
return $self;
}
method _init() {
$self->{handlers} = {
Range => $self->can("_range"),
String => $self->can("_string"),
Literal => $self->can("_literal"),
Repetition => $self->can("_repetition"),
ProseValue => $self->can("_proseValue"),
Reference => $self->can("_reference"),
Group => $self->can("_group"),
Choice => $self->can("_choice"),
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.758 second using v1.00-cache-2.02-grep-82fe00e-cpan-c30982ac1bc3 )