From 00e57331b1c7ef2b1f402f41e1223308e0d8ce61 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 3 Apr 2017 15:04:15 +0200 Subject: initial commit --- lib/FLAT/Transition.pm | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/FLAT/Transition.pm (limited to 'lib/FLAT/Transition.pm') diff --git a/lib/FLAT/Transition.pm b/lib/FLAT/Transition.pm new file mode 100644 index 0000000..fc385f3 --- /dev/null +++ b/lib/FLAT/Transition.pm @@ -0,0 +1,66 @@ +package FLAT::Transition; +use strict; +use Carp; + +sub new { + my ($pkg, @things) = @_; + bless { map { $_ => 1 } @things }, $pkg; +} + +sub does { + my ($self, @things) = @_; + return 1 if @things == 0; + return !! grep $self->{$_}, @things; +} + +sub add { + my ($self, @things) = @_; + @$self{@things} = (1) x @things; +} + +sub delete { + my ($self, @things) = @_; + delete $self->{$_} for @things; +} + +sub alphabet { + my $self = shift; + sort { $a cmp $b } keys %$self; +} + +sub as_string { + my $self = shift; + join ",", map { length $_ ? $_ : "epsilon" } $self->alphabet; +} + +1; + +__END__ + +=head1 NAME + +FLAT::Transition - a transition base class. + +=head1 SYNOPSIS + +Default implementation of the Transition class, used to manage transitions +from one state to others. This class is meant for internal use. + +=head1 USAGE + +used internally; + +=head1 AUTHORS & ACKNOWLEDGEMENTS + +FLAT is written by Mike Rosulek Emike at mikero dot comE and +Brett Estrade Eestradb at gmail dot comE. + +The initial version (FLAT::Legacy) by Brett Estrade was work towards an +MS thesis at the University of Southern Mississippi. + +Please visit the Wiki at http://www.0x743.com/flat + +=head1 LICENSE + +This module is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. -- cgit v1.2.3