Acme-Aheui
view release on metacpan or search on metacpan
This method will create and return `Acme::Aheui' object.
execute
$interpreter->execute();
This method will execute the aheui program and return the exit code. It
may use `STDIN' and/or `STDOUT' if the aheui program uses I/O.
INSTALLATION
To install this module, run the following commands:
perl Build.PL
./Build
./Build test
./Build install
AUTHOR
Rakjin Hwang, `<rakjin@cpan.org>'
LICENSE
my $source;
if ($filename) {
open(FH, $filename) or die "cannot open $filename\n";
$source = join '', <FH>;
close(FH);
$source = decode('utf-8', $source); # expect utf8 by aheui spec
}
elsif (-t STDIN and -z STDIN) {
print "Acme::Aheui $Acme::Aheui::VERSION ($encoding)\n";
print "Type aheui commands or empty line for EOF.\n";
my @lines = ();
while (1) {
print '>>> ';
my $line = <>;
last if !$line or $line =~ /^\r?\n$/;
push @lines, $line;
}
$source = join '', @lines;
}
else {
lib/Acme/Aheui.pm view on Meta::CPAN
$interpreter->execute();
This method will execute the aheui program and return the exit code.
It may use C<STDIN> and/or C<STDOUT> if the aheui program uses I/O.
=cut
sub execute {
my ($self) = @_;
return 0 unless $self->_has_initial_command();
return $self->_loop_steps();
}
sub _has_initial_command {
my ($self) = @_;
for my $row (@{ $self->{_codespace} }) {
my $first_command = @$row[0];
if ($first_command && $$first_command{cho} != -1) {
return 1;
}
}
return 0;
}
sub _loop_steps {
my ($self) = @_;
while (1) {
lib/Acme/Aheui.pm view on Meta::CPAN
}
sub _get_input_number {
my ($self) = @_;
return int(ReadLine(0));
}
=head1 INSTALLATION
To install this module, run the following commands:
perl Build.PL
./Build
./Build test
./Build install
=head1 AUTHOR
Rakjin Hwang, C<< <rakjin@cpan.org> >>
t/01_aheui.t view on Meta::CPAN
{ # exit without infinite loop in case of null program
my ($stdout, $stderr, @result) = capture {
my $interpreter = Acme::Aheui->new( source => '' );
$interpreter->execute();
};
is( $stdout, '' );
is( $stderr, '' );
}
{ # exit without infinite loop in case of no initial command
my $source = "abc\ndef\nghi\n\n\n_ë°ë°§ëë§í\n";
my ($stdout, $stderr, @result) = capture {
my $interpreter = Acme::Aheui->new( source => $source );
$interpreter->execute();
};
is( $stdout, '' );
is( $stderr, '' );
}
{ # input number
( run in 2.608 seconds using v1.01-cache-2.11-cpan-d8267643d1d )