4.8. Program Class

Program objects allow Qore programs to support subprograms with restricted capabilities, for example, to support user-defined logic for application actions.

Parsing in Qore happens in two steps; first all code is parsed to pending data structures, and then in the second stage, all references are resolved, and, if there are no errors, then all changes are committed to the Program object. Note that all parse actions (Program::parse(), Program::parsePending(), Program::parseCommit(), and Program::parseRollback()) are atomic; there is a thread lock on each Program object to ensure atomicity, and if any parse errors occur in any stage of parsing, any pending changes to the Program object are automatically rolled back. However parse actions that affect only one stage of the two stages of parsing (Program::parsePending(), Program::parseCommit() and Program::parseRollback()) are atomic within themselves, but not between calls, so one thread may inadvertently commit changes to a Program object if two or more threads are trying to perform transaction-safe two-stage parsing on a Program object without explicit user locking.

The constants in the following table can be used to limit the capabilities of a Program object. These options should be binary-OR'ed together and passed to the Program object's constructor. Also see Command-Line Parsing for equivalent command-line options, and Parse Directives for equivalent parse directives.

Note that a program can provide controlled access to functionality otherwise restricted by parse options by exporting a custom API into the child program object using either the Program::importFunction() or Program::importGlobalVariable() method. This is possible because code (functions or object methods) imported into and called from a subprogram will run in the parent's space and therefore with the parent's capabilities.

The following constants are all in the Qore namespace.

Table 4.290. Parse Options

Constant

Details

Description

PO_ALLOW_BARE_REFS

%allow-bare-refs

Prohibits the use of the '$' character in variable names, method calls, and object member references.

PO_ASSUME_LOCAL

%assume-local

Assume local variable scope when variables are first referenced if no my or our is present.

PO_DEFAULT

no parse options

This option is the empty option, meaning no options are set.

PO_NEW_STYLE

%new-style

Sets both PO_ALLOW_BARE_REFS and PO_ASSUME_LOCAL

PO_NO_GLOBAL_VARS

%no-global-vars

Disallows the use of global variables.

PO_NO_SUBROUTINE_DEFS

%no-subroutine-defs

Disallows subroutine (function) definitions.

PO_NO_THREADS

%no-threads

Disallows any thread operations (the background operator and the thread_exit statement, for example) and the use of thread-relevant classes and functions (equivalent to PO_NO_THREAD_CLASSES | PO_NO_THREAD_CONTROL).

PO_NO_THREAD_CLASSES

%no-thread-classes

Disallows access to any thread classes.

PO_NO_THREAD_CONTROL

%no-thread-control

Disallows access to any thread-control functions and thread-relevant statements and operators (for example the background operator and the thread_exit statement).

PO_NO_TOP_LEVEL_STATEMENTS

%no-top-level

Disallows top level code.

PO_NO_CLASS_DEFS

%no-class-defs

Disallows class definitions.

PO_NO_NAMESPACE_DEFS

%no-namespace-defs

Disallows new namespace definitions.

PO_NO_CONSTANT_DEFS

%no-constant-defs

Disallows constant definitions.

PO_NO_NEW

%no-new

Disallows use of the new operator.

PO_NO_SYSTEM_CLASSES

n/a

Prohibits system classes from being imported into the new Program object.

PO_NO_USER_CLASSES

n/a

Prohibits user classes from being imported into the new Program object.

PO_NO_CHILD_PO_RESTRICTIONS

%no-child-restrictions

Allows child program objects to have fewer parse restrictions than the parent object.

PO_NO_EXTERNAL_INFO

%no-external-info

Disallows access to functionality that provides information about the computing environment.

PO_NO_EXTERNAL_PROCESS

%no-external-process

Disallows any access to external processes (with system(), backquote(), exec(), etc).

PO_REQUIRE_OUR

%require-our

Requires global variables to be declared with our before use.

PO_NO_PROCESS_CONTROL

%no-process-control

Disallows access to functions that would affect the current process (exit(), exec(), fork(), etc).

PO_LOCK_WARNINGS

%lock-warnings

Prohibits the warning mask from being changed.

PO_NO_NETWORK

%no-network

Disallows access to network functions.

PO_NO_FILESYSTEM

%no-filesystem

Disallows access to the filesystem.

PO_LOCK_WARNINGS

%lock-warnings

Disallows changes to the warning mask.

PO_NO_DATABASE

%no-database

Disallows access to database functionality.

PO_NO_GUI

%no-gui

Disallows access to functionality that draws graphics to the display.

PO_NO_TERMINAL_IO

%no-terminal-io

Disallows access to reading from and/or writing to the terminal.

PO_NO_THREAD_INFO

%no-thread-info

Disallows access to functionality that provides information about threading.

PO_NO_LOCALE_CONTROL

%no-locale-control

Disallows access to functionality that can change locale parameters.

PO_REQUIRE_PROTOTYPES

%require-prototypes

Requires all function and method parameters and return types to have type declarations. Variables and object members are not required to have type declarations.

PO_REQUIRE_TYPES

%require-types

Requires all function and method parameters, return types, variables, and object members to have type declarations. Additionally, this option implies PO_STRICT_ARGS.

PO_STRICT_ARGS

%strict-args

Prohibits access to builtin functions and methods flagged with RT_NOOP and also causes errors to be raised if excess arguments are given to functions that do not access excess arguments.


Table 4.291. Program Method Overview

Method

Except?

Description

Program::constructor(softint $options = PO_DEFAULT)

N

Creates the program object and optionally sets program capabilities (parse options)

Program::destructor()

N

Destroys the object. Blocks until all threads have terminated.

Program::copy()

Y

Throws an exception to prevent objects of this class from being copied.

any Program::callFunction(string $func, ...)

Y

Calls a function in the program object and returns the return value.

any Program::callFunctionArgs(string $func, list $args)

any Program::callFunctionArgs(string $func, any $args)

Y

Calls a function in the program object with the arguments given as a list

nothing Program::define(string $def, any $val)

Y

Sets a parse define for the current Program.

nothing Program::disableParseOptions(int $options = PO_DEFAULT)

Y

Removes the given parse options to the current parse option mask.

bool Program::existsFunction(string $func)

nothing Program::existsFunction() (RT_NOOP)

N

Checks if a user function exists in the program object

any Program::getDefine(string $def)

N

Retrieves the value of the given parse define in the current Program.

any Program::getGlobalVariable(string $name)

any Program::getGlobalVariable(string $name, reference $found)

N

Returns a the value of the global variable identified by the first string argument.

int Program::getParseOptions()

N

Returns a code of parse options set in the object.

*string Program::getScriptDir()

N

Returns the current script directory as a string or NOTHING if not set.

*string Program::getScriptName()

N

Returns the current script name as a string or NOTHING if not set.

*string Program::getScriptPath()

N

Returns the current script directory and filename as a string or NOTHING if not set.

TimeZone Program::getTimeZone()

N

Returns the default local time zone for the object.

list Program::getUserFunctionList()

N

Returns a list of strings of all user functions defined in the program object.

nothing Program::importFunction(string $name)

nothing Program::importFunction(string $name, string $new_name)

Y

Imports a user function into the program object's space; any calls to the function will run in the parent's space.

nothing Program::importGlobalVariable(string $name, bool $readonly = False)

Y

Imports a global variable into the Program object's space. If the variable is an object, then any methods called will run in the parent's space.

bool Program::isDefined(string $def)

N

Returns True if the given parse define is defined in the current Program (does not have to have a value defined to return True).

nothing Program::lockOptions()

N

Locks parse options so that they cannot be changed.

nothing Program::parse(string $code, string $label)

*hash Program::parse(string $code, string $label, softint $warn_mask)

Y

Performs a complete parse and commit of the string passed; if a warning mask is given and warnings are raised, then the method returns an exception hash.

nothing Program::parseCommit()

*hash Program::parseCommit(softint $warn_mask)

Y

Commits all pending changes to the program object; if a warning mask is given and warnings are raised, then the method returns an exception hash.

nothing Program::parsePending(string $code, string $label)

*hash Program::parsePending(string $code, string $label, softint $warn_mask)

Y

Performs a 1st stage parse of the string passed; if a warning mask is given and warnings are raised, then the method returns an exception hash.

nothing Program::parseRollback()

N

Rolls back all pending changes to the program object

any Program::run()

Y

Runs the top-level code of the program object

nothing Program::replaceParseOptions(int $options)

Y

Replaces the current parse option mask with the parse options given as an argument; an exception is thrown if the calling Program object does not have PO_NO_CHILD_PO_RESTRICTIONS set.

nothing Program::setParseOptions(int $options = PO_DEFAULT)

Y

Adds the given parse options to the current parse option mask.

nothing Program::setScriptPath(string $path)

nothing Program::setScriptPath()

N

Sets (or clears) the script path (directory and filename) for the object.

nothing Program::setTimeZone(TimeZone $zone)

N

Sets the default local time zone for the object.

nothing Program::setTimeZoneRegion(string $region)

Y

Sets the default local time zone for the object from a path to a zoneinfo time zone region file.

nothing Program::setTimeZoneUTCOffset(softint $secs_east)

N

Sets the default local time zone for the object from a UTC offset in seconds east of UTC; for zones west of UTC, use negative numbers.

nothing Program::undefine(string $def)

Y

Undefines the given parse define in the current Program.


4.8.1. Program::constructor()

Synopsis

Creates the Program object. It accepts one optional argument that will set the program capabilities for the program object.

Note that if PO_NO_CHILD_PO_RESTRICTIONS is not set in the parent Program when the new Program object is created, then the created Program object will have the parent's parse options added to its parse options as given by the argument to the constructor; in other words, if PO_NO_CHILD_PO_RESTRICTIONS is not set, it's not possible to create a child Program object with fewer restrictions than the parent Program object (any attempt to do so will be silently ignored). However, if PO_NO_CHILD_PO_RESTRICTIONS is set in the parent Program object, then the parse option argument to the constructor will be applied literally to the child object.

Prototype

Program::constructor(softint $options = PO_DEFAULT)

Example
my Program $pgm();

Table 4.292. Arguments for Program::constructor()

Argument

Description

softint $options = PO_DEFAULT

A binary OR'ed product of parse options.


4.8.2. Program::destructor()

Synopsis

Destroys the object. If any threads are running in the program, the destructor will block until the threads terminate.

Example
delete $pgm;

4.8.3. Program::copy()

Synopsis

Throws an exception; objects of this class cannot be copied.

Table 4.293. Exceptions Thrown by Program::copy()

err

desc

PROGRAM-COPY-ERROR

Objects of this class cannot be copied.


4.8.4. Program::callFunction()

Synopsis

Calls a function in the program object and returns the return value. The function runs with the permissions of the Program object containing the function.

Prototype

any Program::callFunction(string $func, ...)

Example
$result = $pgm.callFunction("func_name", $arg1, $arg2);

Table 4.294. Arguments for Program::callFunction()

Argument

Description

string $func

The name of the function to call.

[...]

The remaining arguments passed to the method are passed to the function to be called.


Table 4.295. Return Values for Program::callFunction()

Return Type

Description

any

Depends on the function being called.


Table 4.296. Exceptions Thrown by Program::callFunction()

err

desc

INVALID-FUNCTION-ACCESS

Parse options do not allow this builtin function to be called.

NO-FUNCTION

The function does not exist.


4.8.5. Program::callFunctionArgs()

Synopsis

Calls a function in the program object and returns the return value, using the second argument as the argument list for the function call. The function runs with the permissions of the Program object containing the function.

Prototype

any Program::callFunctionArgs(string $func, list $args)

any Program::callFunctionArgs(string $func, any $args)

Example
$result = $pgm.callFunctionArgs("func_name", $arg_list);

Table 4.297. Arguments for Program::callFunctionArgs()

Argument

Description

string $func

The name of the function to call.

list or any $args

Argument list to be passed to the function; is a single non-list argument is passed, it will be treated as if it were the sole argument to the function.


Table 4.298. Return Values for Program::callFunctionArgs()

Return Type

Description

any

Depends on the function being called.


Table 4.299. Exceptions Thrown by Program::callFunctionArgs()

err

desc

INVALID-FUNCTION-ACCESS

Parse options do not allow this builtin function to be called.

NO-FUNCTION

The function does not exist.


4.8.6. Program::define()

Synopsis

Sets a parse define for the current Program.

Prototype

nothing Program::define(string $def, any $val)

Example
$pgm.define("PRODUCTION", True);

Table 4.300. Arguments for Program::define()

Argument

Description

string $def

The name of the define to set.

any $val

The value to assign to the define.


This method will only throw an exception if the old value of the define was an object, and this call causes the object to go out of scope, and the object's destructor throws an exception.

4.8.7. Program::disableParseOptions()

Synopsis

Disables parse options in the parse option mask for the Program object. An exception is thrown if parse options have been locked (for example with Program::lockOptions()). For a reciprocal method that sets parse options, see Program::setParseOptions().

See also Program::replaceParseOptions().

Prototype

nothing Program::disableParseOptions(int $options = PO_DEFAULT)

Example
# allow threading and GUI operations
$pgm.disableParseOptions(PO_NO_THREADS | PO_NO_GUI);

Table 4.301. Arguments for Program::disableParseOptions()

Argument

Description

int $options = PO_DEFAULT

A single parse option or binary-or combination of parse options to disable in the parse option mask for the current object.


Table 4.302. Exceptions Thrown by Program::disableParseOptions()

err

desc

OPTIONS-LOCKED

Parse options have been locked and cannot be changed.


4.8.8. Program::existsFunction()

Synopsis

Checks if a user function exists in the program object.

Prototype
Program::existsFunction(function_name)
Example

bool Program::existsFunction(string $func)

nothing Program::existsFunction() (RT_NOOP)

Table 4.303. Arguments for Program::existsFunction()

Argument

Description

string $func

The name of the function to check.


Table 4.304. Return Values for Program::existsFunction()

Return Type

Description

bool

Returns True if the function exists, False if not.


4.8.9. Program::getDefine()

Synopsis

Retrieves the value of the given parse define in the current Program.

Prototype

any Program::getDefine(string $def)

Example
my any $val = $pgm.getDefine("PRODUCTION");

Table 4.305. Arguments for Program::getDefine()

Argument

Description

string $def

The name of the define to retrieve.


Table 4.306. Return Values for Program::getDefine()

Return Type

Description

any

The value of the given parse define; note that a parse define may be defined with no value; use Program::isDefined to check if a parse define is actually defined or not.


4.8.10. Program::getGlobalVariable()

Synopsis

Returns the value of the global variable identified by the first string argument giving the name of the variable (without any leading "$" symbol. An lvalue reference can be passed as the second argument in order to determine if the global variable exists (because this method could return NOTHING when the variable exists as well as when it does not).

Prototype

any Program::getGlobalVariable(string $name)

any Program::getGlobalVariable(string $name, reference $found)

Example
$val = $pgm.getGlobalVariable("error_count", \$exists);

Table 4.307. Arguments for Program::getGlobalVariable()

Argument

Description

string $name

The string name of the variable to find, not including the leading "$" character.

reference $found

If a reference is passed in this position, it will contain a boolean value after the method exits: if this value is True, that means that the variable exists in the Program object, False means that the variable does not exist.


Table 4.308. Return Values for Program::getParseOptions()

Return Type

Description

any

The value of the global variable (or NOTHING if it does not exist; note that also the variable could exist and return NOTHING as well; use a reference as the second argument to the method to determine if the variable exists or not).


This method does not throw any exceptions.

4.8.11. Program::getParseOptions()

Synopsis

Returns the current binary-or parse option mask for the Program object.

Prototype

int Program::getParseOptions()

Example
$mask = $pgm.getParseOptions();

Table 4.309. Return Values for Program::getParseOptions()

Return Type

Description

int

A mask of all parse options set (combined with binary or) for the current object.


4.8.12. Program::getScriptDir()

Synopsis

Gets the script directory set with Program::setScriptPath(). This is the same value that will be returned in the Qore program code with the get_script_dir() function if called from within the Program. The value returned should normally include the trailing '/' character.

Prototype

*string Program::getScriptDir()

Example
my *string $dir = $pgm.getScriptDir();

Table 4.310. Return Values for Program::getScriptDir()

Return Type

Description

*string

The current script directory or NOTHING if not set.


This method does not throw any exceptions.

4.8.13. Program::getScriptName()

Synopsis

Gets the script filename set with Program::setScriptPath(). This is the same value that will be returned in the Qore program code with the get_script_path() function if called from within the Program.

Prototype

*string Program::getScriptName()

Example
my *string $name = $pgm.getScriptName();

Table 4.311. Return Values for Program::getScriptName()

Return Type

Description

*string

The current script name if known, otherwise returns NOTHING.


This method does not throw any exceptions.

4.8.14. Program::getScriptPath()

Synopsis

Gets the script directory and filename set with Program::setScriptPath(). This is the same value that will be returned in the Qore program code with the get_script_path() function if called from within the Program.

Prototype

*string Program::getScriptPath()

Example
my *string $path = $pgm.getScriptPath();

Table 4.312. Return Values for Program::getScriptPath()

Return Type

Description

*string

The current script directory and filename if known, otherwise returns NOTHING.


This method does not throw any exceptions.

4.8.15. Program::getTimeZone()

Synopsis

Returns the default local time zone for the object.

See also TimeZone::get()

Prototype

TimeZone Program::getTimeZone()

Example
my TimeZone $zone = $pgm.getTimeZone();

Table 4.313. Return Values for Program::getTimeZone()

Return Type

Description

TimeZone

Returns the default local time zone for the object.


This method does not throw any exceptions.

4.8.16. Program::getUserFunctionList()

Synopsis

Returns a list of all user functions defined in the Program object.

Prototype

list Program::getUserFunctionList()

Example
my list $l = $pgm.getUserFunctionList();

Table 4.314. Return Values for Program::getUserFunctionList()

Return Type

Description

list

A list of strings giving the names of all functions implemented in the program object.


4.8.17. Program::importFunction()

Synopsis

Imports a user function into the program object's space; any calls to the imported function will run in the parent's space. This allows a user-defined API with greater capabilities than the embedded Program object to be imported into the embedded code.

Prototype

nothing Program::importFunction(string $name)

nothing Program::importFunction(string $name, string $new_name)

Example
$pgm.importFunction("function");

Table 4.315. Arguments for Program::importFunction()

Argument

Description

string $name, [string $new_name]

The name of the function to import and an optional new name for it to be registered under in the target Program.


Table 4.316. Exceptions Thrown by Program::importFunction()

err

desc

FUNCTION-IMPORT-ERROR

Cannot import a function into the same Program object; function with this name already exists.

PROGRAM-IMPORTFUNCTION-NO-FUNCTION

The function does not exist.


4.8.18. Program::importGlobalVariable()

Synopsis

Imports a global variable into the program object's space. If the variable is an object, then any methods called from the subprogram will run in the parent's space.

Prototype

nothing Program::importGlobalVariable(string $name, bool $readonly = False)

Example
$pgm.importGlobalVariable("var");

Table 4.317. Arguments for Program::importGlobalVariable()

Argument

Description

string $name

The name of the global variable without the $

bool $readonly = False

If this argument is present and is True, then the variable will be imported read-only, and cannot be changed by the subprogram.


Table 4.318. Exceptions Thrown by Program::importGlobalVariable()

err

desc

PROGRAM-IMPORTGLOBALVARIABLE-EXCEPTION

The global variable does not exist.


4.8.19. Program::isDefined()

Synopsis

Returns True if the given parse define is defined in the current Program (does not have to have a value defined to return True).

Prototype

bool Program::isDefined(string $def)

Example
my bool $b = $pgm.isDefined("PRODUCTION");

Table 4.319. Arguments for Program::isDefined()

Argument

Description

string $def

The name of the define to check.


Table 4.320. Return Values for Program::isDefined()

Return Type

Description

bool

True if the given define exists in the current Program.


4.8.20. Program::lockOptions()

Synopsis

Locks parse options so they cannot be changed.

Prototype

nothing Program::lockOptions()

Example
$pgm.lockOptions();

This method does not throw any exceptions.

4.8.21. Program::parse()

Synopsis

Parses the string argument and adds the code to the program object.

If a warning mask is given and masked warnings are raised during parsing, this method will return a hash with warning information.

Prototype

nothing Program::parse(string $code, string $label)

*hash Program::parse(string $code, string $label, softint $warn_mask)

Example
$pgm.parse($code, "label");

Table 4.321. Arguments for Program::parse()

Argument

Description

string $code

The code to parse.

string $label

A label identifying the code.

[softint $warn_mask]

An optional warning mask of bitwise-ORed warning values; if this option is non-zero and any warnings are raised during parsing, then a hash is returned of warning information.


Table 4.322. Return Values for Program::parse()

Return Type

Description

*hash

If a warning mask is set and any masked warnings are raised during parsing, then an exception hash of warning information is returned (multiple warnings are linked in the hash through the "next" key, as with chained exceptions).


Table 4.323. Exceptions Thrown by Program::parse()

err

desc

PARSE-ERROR

An error occurred parsing the text.


4.8.22. Program::parseCommit()

Synopsis

Commits and pending code processed with Program::parsePending() to the Program object and resolves all outstanding references in the pending code. An exception in this method causes all pending code to be rolled back immediately.

If a warning mask is given and masked warnings are raised during parsing, this method will return a hash with warning information.

Prototype

nothing Program::parseCommit()

*hash Program::parseCommit(softint $warn_mask)

Example
$pgm.parseCommit();

Table 4.324. Arguments for Program::parseCommit()

Argument

Description

[softint $warn_mask]

An optional warning mask of bitwise-ORed warning values; if this option is non-zero and any warnings are raised during parsing, then a hash is returned of warning information.


Table 4.325. Return Values for Program::parseCommit()

Return Type

Description

*hash

If a warning mask is set and any masked warnings are raised during parsing, then an exception hash is returned of warning information (multiple warnings are linked in the hash through the "next" key, as with chained exceptions).


Table 4.326. Exceptions Thrown by Program::parseCommit()

err

desc

PARSE-ERROR

An error occurred parsing the text.


4.8.23. Program::parsePending()

Synopsis

Parses the text passed to pending lists in the Program object; does not resolve all references or commit the code to the Program object. References are resolved in the Program::parseCommit() method. If an exception occurs in this method, all pending code is backed out, not just code parsed by this method.

If a warning mask is given and masked warnings are raised during parsing, this method will return a hash with warning information.

Prototype

nothing Program::parsePending(string $code, string $label)

*hash Program::parsePending(string $code, string $label, softint $warn_mask)

Example
$pgm.parsePending($code, "label");

Table 4.327. Arguments for Program::parsePending()

Argument

Description

string $code

The code to parse.

string $label

A label identifying the code.

[softint $warn_mask]

An optional warning mask of bitwise-ORed warning values; if this option is non-zero and any warnings are raised during parsing, then a hash is returned of warning information.


Table 4.328. Return Values for Program::parsePending()

Return Type

Description

*hash

If a warning mask is set and any masked warnings are raised during parsing, then an exception hash is returned of warning information (multiple warnings are linked in the hash through the "next" key, as with chained exceptions).


Table 4.329. Exceptions Thrown by Program::parsePending()

err

desc

PARSE-ERROR

An error occurred parsing the text.


4.8.24. Program::parseRollback()

Synopsis

Rolls back any pending code processed with Program::parsePending() that has not yet been committed to the Program object with Program::parseCommit()

Prototype

nothing Program::parseRollback()

Example
$pgm.parseRollback();

4.8.25. Program::run()

Synopsis

Runs the program and optionally returns a value if the top-level code exits with a return statement.

Prototype

any Program::run()

Example
$pgm.run();

Table 4.330. Return Values for Program::run()

Return Type

Description

any

Depends on the program; any return statement at the top level of the program will return a value to this method.


4.8.26. Program::replaceParseOptions()

Synopsis

Replaces the parse options for the Program object; an exception is thrown if the calling Program object does not have PO_NO_CHILD_PO_RESTRICTIONS set.

See also Program::setParseOptions() and Program::disableParseOptions().

Prototype

nothing Program::replaceParseOptions(int $options)

Example
# disallow threading and GUI operations
$pgm.replaceParseOptions(PO_NO_THREADS | PO_NO_GUI);

Table 4.331. Arguments for Program::replaceParseOptions()

Argument

Description

int $options

A single parse option or binary-or combination of parse options to set in the parse option mask for the current object.


Table 4.332. Exceptions Thrown by Program::replaceParseOptions()

err

desc

OPTION-ERROR

the calling Program does not have the PO_NO_CHILD_PO_RESTRICTIONS option set, and therefore cannot call Program::replaceParseOptions().


4.8.27. Program::setParseOptions()

Synopsis

Sets parse options in the parse option mask for the Program object. An exception is thrown if parse options have been locked (for example with Program::lockOptions()). For a reciprocal method that disables parse options, see Program::disableParseOptions().

See also Program::replaceParseOptions().

Prototype

nothing Program::setParseOptions(int $options = PO_DEFAULT)

Example
# disallow threading and GUI operations
$pgm.setParseOptions(PO_NO_THREADS | PO_NO_GUI);

Table 4.333. Arguments for Program::setParseOptions()

Argument

Description

int $options = PO_DEFAULT

A single parse option or binary-or combination of parse options to set in the parse option mask for the current object.


Table 4.334. Exceptions Thrown by Program::setParseOptions()

err

desc

OPTIONS-LOCKED

Parse options have been locked and cannot be changed.


4.8.28. Program::setScriptPath()

Synopsis

Sets the script path (directory and filename) for later retrieval with Program::getScriptPath(), Program::getScriptDir(), or Program::getScriptName() calls, or from code within the Program object with the get_script_path(), get_script_dir(), or get_script_name() functions.

Prototype

nothing Program::setScriptPath(string $path)

nothing Program::setScriptPath()

Example
$pgm.setScriptPath("/users/test/test.q");

Table 4.335. Arguments for Program::setScriptPath()

Argument

Description

string $path

The path (directory and filename) for the current script. If the directory component is missing, then "./" is assumed.


This method does not throw any exceptions.

4.8.29. Program::setTimeZone()

Synopsis

Sets the default local time zone for the object.

See also TimeZone::set().

Prototype

nothing Program::setTimeZone(TimeZone $zone)

Example
$pgm.setTimeZone($zone);

Table 4.336. Arguments for Program::setTimeZone()

Argument

Description

TimeZone $zone

The time zone to set as the local time zone for the Program object.


This method does not throw any exceptions.

4.8.30. Program::setTimeZoneRegion()

Synopsis

Sets the default local time zone for the object from a path to a zoneinfo time zone region file; if there are errors reading or parsing the file, an exception is thrown.

See also TimeZone::setRegion().

Prototype

nothing Program::setTimeZoneRegion(string $region)

Example
$pgm.setTimeZoneRegion("Europe/Prague");

Table 4.337. Arguments for Program::setTimeZoneRegion()

Argument

Description

string $region

The path to the zoneinfo file for the time zone region to set as the local time zone for the Program object.


Table 4.338. Exceptions Thrown by Program::setTimeZoneRegion()

err

desc

TZINFO-ERROR

Unable to read zoneinfo file; invalid file magic; error parsing zoneinfo file, etc


4.8.31. Program::setTimeZoneUTCOffset()

Synopsis

Sets the default time zone for the Program object based on the number of seconds east of UTC; for zones west of UTC, use negative numbers.

Time zones set with this method cannot have any daylight savings time information; to set a zone with daylight savings time information, use Program::setTimeZoneRegion() instead.

See also TimeZone::setUTCOffset().

Prototype

nothing Program::setTimeZoneUTCOffset(softint $secs_east)

Example

The following examples are all equivalent, setting the time zone to +02 UTC:

$pgm.setTimeZoneUTCOffset(7200);
$pgm.setTimeZoneUTCOffset(2h);
$pgm.setTimeZoneUTCOffset(PT2H);

Table 4.339. Arguments for Program::setTimeZone()

Argument

Description

softint $secs_east

The number of seconds east of UTC; for zones west of UTC, use negative numbers


This method does not throw any exceptions.

4.8.32. Program::undefine()

Synopsis

Undefines the given parse define in the current Program.

Prototype

nothing Program::undefine(string $def)

Example
$pgm.undefine("PRODUCTION");

Table 4.340. Arguments for Program::undefine()

Argument

Description

string $def

The name of the define to remove.


This method will only throw an exception if the old value of the define was an object, and this call causes the object to go out of scope, and the object's destructor throws an exception.