AI-Gene-Sequence

 view release on metacpan or  search on metacpan

demo/Regexgene.pm  view on Meta::CPAN

package Regexgene;
use strict;
use warnings;

=head1 NAME

  Regexgene - An example of a AI::Gene::Sequence

=head1 SYNOPSIS

This is a short module which illustrates the way to use the
AI::Gene::Sequence module.

 use Regexgene;
 $regex = Regexgene->new(5);
 print $regex->regex, "\n";
 $regex->mutate;
 print $regex->regex, "\n";
 $copy = $regex->clone;
 $copy->mutate;
 print $regex->regex, "\n", $copy->regex, "\n";

=head1 DESCRIPTION

The following is a code / pod mix, use the source.  A programme
using this module is available as C<spamscan.pl>.

=head1 The module code

=cut

=head2

First we need to be nice, do our exporting and versions, we
also need to tell perl that we want objects in this class
to inherit from AI::Gene::Sequence by placing it in
our @ISA array.

=cut

BEGIN {
  use Exporter   ();
  use AI::Gene::Sequence;
  our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
  $VERSION     = 0.01;
  @ISA         = qw(Exporter AI::Gene::Sequence);
  @EXPORT      = ();
  %EXPORT_TAGS = ();
  @EXPORT_OK   = qw();
}
our @EXPORT_OK;

=head2 Globals

We have a load of globals, these form the basis of our token types, anything
from the same array, is the same type eg.

 @modifiers = qw( * *? + +? ?? ); # are of type 'm' for modifier

=cut

our @modifiers  = qw( * *? + +? ?? );
our @char_types = qw( \w \W \d \D \s \S .);
our @ranges     = qw( [A-Z] [a-z] [0-9] );
our @chars      = ((0..9,'a'..'z','A'..'Z','_'),
                  (map '\\'.chr, 32..47, 58..64, 91..94, 96, 123..126));


=head2 Constructor

As we want to be able to fill our regular expression at the same
time as we create it and because we will want to nest sequences
we will need some way to know how deep we are, then a different
B<new> method is needed.

If called as an object method (C<$obj->new>), this decreases the depth
count by one from the invoking object.  It also adds tokens to the regular
expression and uses the B<valid_gene> method to ensure we stay sane 
from the start.

As can be seen, we use array offsets above $self->[1] to store information



( run in 1.178 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )