File Coverage

blib/lib/Language/Befunge/lib/PERL.pm
Criterion Covered Total %
statement 6 21 28.5
branch n/a
condition n/a
subroutine 2 6 33.3
pod 4 4 100.0
total 12 31 38.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Language::Befunge.
3             # Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
4             #
5             # This program is free software; you can redistribute it and/or modify
6             # it under the same terms as Perl itself.
7             #
8             #
9              
10             package Language::Befunge::lib::PERL;
11              
12 1     1   6741 use strict;
  1         3  
  1         41  
13 1     1   6 use warnings;
  1         2  
  1         249  
14              
15              
16 0     0 1   sub new { return bless {}, shift; }
17              
18              
19             # -- Perl embedding
20              
21             #
22             # 0gnirts = E( 0gnirts )
23             #
24             # 'Eval' pops a 0gnirts string and performs a Perl eval() on it. The
25             # result of the call is pushed as a 0gnirts string back onto the stack.
26             #
27             sub E {
28 0     0 1   my ($self, $interp) = @_;
29 0           my $ip = $interp->get_curip();
30              
31             # pop the perl string
32 0           my $perl = $ip->spop_gnirts();
33 0           my $return = eval $perl;
34            
35 0           $ip->spush( 0 ); # finish the string
36 0           $ip->spush( map{ ord($_) } reverse split(//, $return) );
  0            
37             }
38              
39              
40             #
41             # val = I( 0gnirts )
42             #
43             # 'Int Eval' acts the same as 'E', except that the result of the call
44             # is converted to an integer and pushed as a single cell onto the stack.
45             #
46             sub I {
47 0     0 1   my ($self, $interp) = @_;
48 0           my $ip = $interp->get_curip();
49              
50             # pop the perl string
51 0           my $perl = $ip->spop_gnirts();
52 0           my $return = eval $perl;
53            
54 0           $ip->spush( int $return );
55             }
56              
57              
58             # -- Module information
59              
60             #
61             # S
62             # 'Shelled' pushes a 0 on the stack, meaning that the Perl language is already
63             # loaded (e.g. the interpreter is written in Perl).
64             #
65             sub S {
66 0     0 1   my ($self, $interp) = @_;
67 0           $interp->get_curip->spush(0);
68             }
69              
70             1;
71              
72             __END__