ABNF-Grammar

 view release on metacpan or  search on metacpan

lib/ABNF/Generator/Liar.pm  view on Meta::CPAN

package ABNF::Generator::Liar;

=pod

=head1 NAME

B<ABNF::Generator::Liar> - class to generate invalid messages for ABNF-based generators

=head1 INHERITANCE

B<ABNF::Generator::Liar>
isa B<BNF::Generator>

=head1 DESCRIPTION

=head1 METHODS

=cut

use 5.014;

use strict;
use warnings;

use Readonly;
use Data::Dumper;
use Carp;

use POSIX;

use base qw(ABNF::Generator Exporter);

use Method::Signatures; #some bug in B<Devel::Declare>...

use ABNF::Grammar qw(splitRule $BASIC_RULES);

Readonly my $STRING_LEN => 20;
Readonly my $CHARS => [map { chr($_) } (0 .. 0x0D - 1), (0x0D + 1 .. 255)];
Readonly my $ACHARS => [('A'..'Z', 'a'..'z')];
Readonly our $ENDLESS => 513 * 1024 / 4; # 513 kB of chars

our @EXPORT_OK = qw(Liar);

=pod

=head1 ABNF::Generator::Liar->C<new>($grammar, $validator?)

Creates a new B<ABNF::Generator::Liar> 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 $liar->C<generate>($rule, $tail="")

Generates one invalid 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 _rule($rule, $recursion) {
	my $result = "";

	if ( my $prefix = splitRule($rule) ) {
		do {
			$result = _stringRand($ACHARS);
		} while $self->{_validator}->validateArguments($rule->{name}, $result);
		$result = $prefix . $result;
	} else {
		do {
			$result = _stringRand($ACHARS);

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.562 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )