Acme-Cow-Interpreter
view release on metacpan or search on metacpan
lib/Acme/Cow/Interpreter.pm view on Meta::CPAN
package Acme::Cow::Interpreter;
use strict; # restrict unsafe constructs
use warnings; # control optional warnings
use Carp;
our $VERSION = '0.02';
# This hash maps each of the 12 command (used in the source code) to the
# corresponding numerical code, from 0 to 11.
my $cmd2code =
{
moo => 0,
mOo => 1,
moO => 2,
mOO => 3,
Moo => 4,
MOo => 5,
MoO => 6,
MOO => 7,
OOO => 8,
MMM => 9,
OOM => 10,
oom => 11,
};
# This array maps each of the 12 numerical codes to the corresponding
# command (used in source code).
my $code2cmd =
[
'moo',
'mOo',
'moO',
'mOO',
'Moo',
'MOo',
lib/Acme/Cow/Interpreter.pm view on Meta::CPAN
my $string = shift; croak "$name(): Input argument is undefined"
unless defined $string;
# Reset, i.e., initialize, the invocand object.
$self -> init();
# Find the string commands, and convert them to numerical codes.
$self -> {prog} = [
map { $cmd2code -> {$_} }
$string =~ /($cmd_regex)/go
];
return $self;
}
=pod
=item parse_file( FILENAME )
lib/Acme/Cow/Interpreter.pm view on Meta::CPAN
my $file = shift;
open FILE, $file or croak "$file: can't open file for reading: $!";
# Iterate over each line, find the string commands, and convert them to
# numerical codes.
while (<FILE>) {
push @{ $self -> {prog} },
map { $cmd2code -> {$_} }
/($cmd_regex)/go;
}
close FILE or croak "$file: can't close file after reading: $!";
return $self;
}
=pod
( run in 0.226 second using v1.01-cache-2.11-cpan-26ccb49234f )