Module: Perl::Common

Included in:
Perl, Interpreter, Shell
Defined in:
lib/perl/common.rb

Constant Summary collapse

PERL_EXIT_EXPECTED =
0x01
PERL_EXIT_DESTRUCT_END =
0x02

Instance Method Summary collapse

Instance Method Details

#argv_to_ffiObject

Returns a C-style tuple of <argc,argv> corresponding to the real arguments the application was invoked with.



31
32
33
# File 'lib/perl/common.rb', line 31

def argv_to_ffi
  array_to_ffi(ARGV)
end

#embedded_argv_to_ffiObject

Returns a C-style tuple of <argc,argv> suitable for running an embedded Perl interpreter.



39
40
41
# File 'lib/perl/common.rb', line 39

def embedded_argv_to_ffi
  array_to_ffi(%w[-e 0])
end

#startObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/perl/common.rb', line 6

def start
  Perl.setup
  argc, argv = embedded_argv_to_ffi

  @my_perl = Perl.perl_alloc
  Perl.perl_construct(@my_perl)

  Perl.curinterp[:Iexit_flags] |= PERL_EXIT_DESTRUCT_END

  Perl.perl_parse(@my_perl, nil, argc, argv, nil)
  Perl.perl_run(@my_perl)
end

#stopObject



19
20
21
22
23
24
25
# File 'lib/perl/common.rb', line 19

def stop
  Perl.perl_destruct(@my_perl)
  Perl.perl_free(@my_perl)

  @my_perl = nil
  Perl.PL_curinterp = nil
end