3 CPerlBase - a base class encapsulating a Perl interpreter
8 USERINCLUDE \symbian\perl\x.y.z\include
12 #include "PerlBase.h" // includes also EXTERN.h and perl.h
13 CPerlBase* perl = CPerlBase::NewInterpreterLC();
19 CPerlBase is a simple Symbian C++ class that wraps a Perl
20 interpreter; its creation, use, and destroying. To understand
21 what this is doing, and how to use the interpreter, a fair knowledge
22 of L<perlapi>, L<perlguts>, and L<perlembed> is recommended.
24 One useful thing CPerlBase does compared with just using the raw
25 Perl C API is that it redirects the "std streams" (STDOUT et alia)
26 to a text console implementation which while being very basic
27 is marginally more usable than the Symbian basic text console.
35 CPerlBase* NewInterpreterL();
37 The constructor that does not keep the object in the Symbian "cleanup stack".
38 perl_alloc() and perl_construct() are called behind the curtains.
40 Accepts the same arguments as NewInterpreterLC().
44 CPerlBase* NewInterpreterLC();
46 The constructor that keeps the object in the Symbian "cleanup stack".
47 perl_alloc() and perl_construct() are called behind the curtains.
49 Can have three arguments:
55 TBool aCloseStdlib = ETrue
57 Should a CPerlBase close the Symbian POSIX STDLIB when closing down.
58 Good for one-shot script execution, probably less good for longer term
63 void (*aStdioInitFunc)(void*) = NULL
65 If set, called with aStdioInitCookie, and the default console is
66 not created. You may want to set the iReadFunc() and iWriteFunc().
70 void *aStdioInitCookie = NULL
72 Used as the argument for aStdioInitFunc().
80 The destructor of the interpreter. The class destructor calls
81 first this and then the Symbian CloseSTDLIB().
83 perl_destruct(), perl_free(), and PERL_SYS_TERM() are called
88 =head2 Utility functions
94 int Parse(int argc = 0, char *argv[] = 0, char *envp[] = 0);
96 Prepare an interpreter for executing by parsing input as if a C main()
97 had been called. For example to parse a script, use argc of 2 and argv
98 of { "perl", script_name }.
100 All arguments are optional: in case either argc or argv are zero,
101 argc of 3 and argv of { "perl", "-e", "0" } is assumed.
103 PERL_SYS_INIT() and perl_parse() are called behind the curtains.
105 Note that a call to Parse() is required before Run().
107 Returns zero if parsing was successful, non-zero if not (and the stderr
114 Start executing an interpeter. A Parse() must have been called before
115 a Run(): use 3 and { "", "-e", 0 } if you do not have an argv.
117 Note that a call to Parse() is required before Run().
119 perl_run() is called behind the curtains.
121 Returns zero if execution was successful, non-zero if not (and the stderr
126 int ParseAndRun(int argc, char *argv[], char *envp[]);
128 Combined Parse() and Run(). The Run() is not run if the Parse() fails.
130 Returns zero if parsing and execution were successful, non-zero if not.
134 TInt RunScriptL(TDesC& aFileName, int argc, char **argv, char *envp[])
136 Like ParseAndRun() but works for Symbian filenames (UTF-16LE).
137 The UTF-8 version of aFileName is always argv[argc-1], and argv[0]
148 Set up my_perl from the current object (like dTHX).
154 Set up my_vars from the current object (like dVAR).
158 =head2 Extending CPerlBase (subclassing, deriving from)
160 Note that it probably isn't worth the trouble to try to wrap the
161 whole, rather large, Perl C API into a C++ API. Just use the C API.
163 The protected members of the class are:
169 PerlInterpreter* iPerl
171 The Perl interpreter.
175 struct perl_vars* iVars
177 The global variables of the interpreter.
183 The state of the Perl interpreter. TPerlState is one of EPerlNone,
184 EPerlAllocated, EPerlConstructed, EPerlParsed, EPerlRunning,
185 EPerlTerminated, EPerlPaused (these two are currently unused
186 but in the future they might be used to indicate that the interpreter
187 was stopped either non-resumably or resumably for some reason),
188 EPerlSuccess (perl_run() succeeded), EPerlFailure (perl_run() failed),
195 Copyright (c) 2004-2005 Nokia. All rights reserved.
199 The CPerlBase class is licensed under the same terms as Perl itself.