Perl User's Guide for STAF Version 3

Last Updated: August 20, 2015


Table of Contents

1.0 Introduction

2.0 Supported Platforms and Perl Versions

2.1 Windows (Intel 32-bit)
2.2 Windows (AMD64, aka x64)
2.3 Linux (Intel 32-bit, aka i386 or x86-32)
2.4 Linux (AMD64, aka x86-64)
2.6 AIX (32-bit)
2.7 Solaris 10+ (Sparc 32-bit)
2.8 Solaris 10+ (Sparc 64-bit)
2.9 Mac OS X 10.10+ (Universal binary with support for i386 and x86_64)

3.0 Installation

4.0 Package PLSTAF

4.1 Primary STAF APIs 4.1.1 Procedural Style 4.1.1.1 STAF::Register
4.1.1.2 STAF::Submit
4.1.1.3 STAF::Submit2
4.1.1.4 STAF::UnRegister
4.1.2 Object-Oriented Style 4.1.2.1 STAF::STAFHandle::new
4.1.2.2 STAF::STAFHandle::submit
4.1.2.3 STAF::STAFHandle::submit2
4.1.2.4 STAF::STAFHandle::unRegister
4.1.2.5 STAF::STAFHandle::setDoUnmarshallResult
4.1.2.6 STAF::STAFHandle::getDoUnmarshallResult
4.1.3 Class STAF::STAFResult
4.1.4 Function STAF::WrapData (or STAF::STAFUtil::WrapData)

4.2 Marshalling APIs 4.2.1 Class STAF::STAFMapClassDefinition
4.2.2 Class STAF::STAFMarshallingContext
4.2.3 Function STAF::STAFIsMarshalledData
4.2.4 Function STAF::STAFMarshall
4.2.5 Function STAF::STAFUnmarshall
4.2.6 Function STAF::STAFFormatObject

4.3 Private Data Manipulation APIs 4.3.1 Function STAF::AddPrivacyDelimiters
4.3.2 Function STAF::EscapePrivacyDelimiters
4.3.3 Function STAF::RemovePrivacyDelimiters
4.3.4 Function STAF::MaskPrivateData

4.4 STAF Return Codes
4.5 STAF Constants
5.0 Package STAFMon 5.1 Monitor Service Variables
5.2 Procedural Style 5.2.1 STAF::Monitor::Log 5.3 Object-Oriented Style 5.3.1 STAF::STAFMonitor::new
5.3.2 STAF::STAFMonitor::log
5.3.3 STAF::STAFMonitor::getSystemName
5.3.4 STAF::STAFMonitor::getServiceName
6.0 Package STAFLog 6.1 Log Service Return Codes
6.2 Procedural Style 6.2.1 STAF::Log::Init
6.2.2 STAF::Log::Log
6.3 Object-Oriented Style 6.3.1 STAF::STAFLog::new
6.3.2 STAF::STAFLog::log
6.3.3 STAF::STAFLog::getName
6.3.4 STAF::STAFLog::getLogType
6.3.5 STAF::STAFLog::getMonitorMask
6.3.6 STAF::STAFLog::getSystemName
6.3.7 STAF::STAFLog::getServiceName
7.0 Perl Program Examples 7.1 Example 1
7.2 Example 2


1.0 Introduction

This document describes STAF's V3 support for the Perl language.  It includes information on the core STAF Perl APIs as well as the wrappers provided for the Monitor and Log services.

STAF Perl support must be installed in order to submit requests to STAF via a Perl program.

Note: All of STAF's Perl APIs are provided in the STAF namespace.

STAF Perl support is only provided in the STAF installer files for the platforms listed below. STAF Perl support is not provided in the STAF installer files for other operating systems.

The version of Perl used to build the STAF Perl libraries is usually the only Perl version that will work with those STAF Perl libraries. STAF currently provides STAF Perl support on the following platforms:

Section 2.0 provides details about the STAF Perl support by platform.

If you want to use a different version of Perl or if you want STAF Perl support for a different operating system, you can either:


2.0 Supported Platforms and Perl Versions

2.1 Windows (Intel 32-bit)

Supported Perl Version Built with PLSTAF library Perl Services
5.6.x 5.6.1 (ActiveState) bin/perl56/PLSTAF.dll Not supported
5.8.x (default) 5.8.3 (ActiveState) bin/perl58/PLSTAF.dll Supported
5.10.x 5.10.0 (ActiveState) bin/perl510/PLSTAF.dll Supported
5.12.x 5.12.4 (ActiveState) bin/perl512/PLSTAF.dll Supported
5.14.x 5.14.2 (ActiveState) bin/perl514/PLSTAF.dll Supported

2.2 Windows (AMD64, aka x64)

Supported Perl Version Built with PLSTAF library Perl Services
5.8.x (default) 5.8.8 (ActiveState) bin/perl58/PLSTAF.dll Supported
5.10.x 5.10.0 (ActiveState) bin/perl510/PLSTAF.dll Supported
5.12.x 5.12.4 (ActiveState) bin/perl512/PLSTAF.dll Supported
5.14.x 5.14.2 (ActiveState) bin/perl514/PLSTAF.dll Supported

2.3 Linux (Intel 32-bit, aka i386 or x86-32)

Supported Perl Version Built with PLSTAF library Perl Services
5.6.x 5.6.1 (ActiveState) lib/perl56/libPLSTAF.so Not supported
5.8.x (default) 5.8.7 (ActiveState) lib/perl58/libPLSTAF.so Supported
5.10.x 5.10.0 (ActiveState) lib/perl510/libPLSTAF.so Supported
5.12.x 5.12.4 (ActiveState) lib/perl512/libPLSTAF.so Supported
5.14.x 5.14.2 (ActiveState) lib/perl514/libPLSTAF.so Supported
5.18.x 5.18.4 (ActiveState) lib/perl518/libPLSTAF.so Supported
Notes:
  1. When using the STAF Perl library, if you get an error such as "libperl.so: cannot open shared object file", then you need to make sure the operating system can find the "libperl.so" file for the version of Perl you are using. There are two ways to resolve the problem (select which one is more suitable for your environment):

    • Update environment variable LD_LIBRARY_PATH to include the directory containing "libperl.so" file for the version of Perl you are using (i.e. export LD_LIBRARY_PATH=/opt/ActivePerl-5.8/lib/CORE:$LD_LIBRARY_PATH)

    • Create a /usr/lib/libperl.so link to the libperl.so file for the version of Perl you are using (i.e ln -s /opt/ActivePerl-5.8/lib/CORE/libperl.so /usr/lib/libperl.so)

  2. When using the STAF Perl library, if you get an error such as "Can't locate strict.pm in @INC", you need to make sure the operating system can find the "strict.pm" file for the version of Perl you are using. You can resolve the problem by updating environment variable PERLLIB to include the directory containing the "strict.pm" file for the version of Perl you are using (i.e. export PERLLIB=/opt/ActivePerl-5.12/lib:$PERLLIB).

  3. When loading Perl services, if you get an error such as "/opt/ActivePerl-5.8/lib/auto/threads/threads.so: undefined symbol: PL_no_mem at /opt/ActivePerl-5.8/lib/XSLoader.pm", you need to set environment variable LD_PRELOAD to the libperl.so file prior to starting STAFProc (i.e. export LD_PRELOAD=/opt/ActivePerl-5.8/lib/CORE/libperl.so).
    This will force the linker to pre-load libperl.so before loading anything else at start up time.
    If you do not want to set LD_PRELOAD before starting STAFProc (as this can cause incompatibility issues for processes started via STAFProc), you can load your Perl service via STAFEXECPROXY, and use OPTION PROXYENV to specify the LD_PRELOAD environment variable for the STAFEXECPROXY executable, without having it set for STAFProc's environment. See the STAF Users's Guide "STAFEXECPROXY service proxy library" section for more information on using STAFEXECPROXY.

2.4 Linux (AMD64, aka x86-64)

Supported Perl Version Built with PLSTAF library Perl Services
5.8.x (default) 5.8.8 (ActiveState) lib/perl58/libPLSTAF.so Supported
5.10.x 5.10.0 (ActiveState) lib/perl510/libPLSTAF.so Supported
5.12.x 5.12.4 (ActiveState) lib/perl512/libPLSTAF.so Supported
5.14.x 5.14.2 (ActiveState) lib/perl514/libPLSTAF.so Supported
5.18.x 5.18.4 (ActiveState) lib/perl518/libPLSTAF.so Supported
Notes:
  1. When using the STAF Perl library, if you get an error such as "libperl.so: cannot open shared object file", then you need to make sure the operating system can find the "libperl.so" file for the version of Perl you are using. There are two ways to resolve the problem (select which one is more suitable for your environment):

    • Update environment variable LD_LIBRARY_PATH to include the directory containing "libperl.so" file for the version of Perl you are using (i.e. export LD_LIBRARY_PATH=/opt/ActivePerl-5.10/lib/CORE:$LD_LIBRARY_PATH)

    • Create a /usr/lib/libperl.so link to the libperl.so file for the version of Perl you are using (i.e ln -s /opt/ActivePerl-5.10/lib/CORE/libperl.so /usr/lib/libperl.so)

  2. When using the STAF Perl library, if you get an error such as "Can't locate strict.pm in @INC", you need to make sure the operating system can find the "strict.pm" file for the version of Perl you are using. You can resolve the problem by updating environment variable PERLLIB to include the directory containing the "strict.pm" file for the version of Perl you are using (i.e. export PERLLIB=/opt/ActivePerl-5.12/lib:$PERLLIB).

  3. When loading Perl services, if you get an error such as "/opt/ActivePerl-5.10/lib/auto/threads/threads.so: undefined symbol: PL_no_mem at /opt/ActivePerl-5.10/lib/XSLoader.pm", you need to set environment variable LD_PRELOAD to the libperl.so file prior to starting STAFProc (i.e. export LD_PRELOAD=/opt/ActivePerl-5.10/lib/CORE/libperl.so).
    This will force the linker to pre-load libperl.so before loading anything else at start up time.
    If you do not want to set LD_PRELOAD before starting STAFProc (as this can cause incompatibility issues for processes started via STAFProc), you can load your Perl service via STAFEXECPROXY, and use OPTION PROXYENV to specify the LD_PRELOAD environment variable for the STAFEXECPROXY executable, without having it set for STAFProc's environment. See the STAF Users's Guide "STAFEXECPROXY service proxy library" section for more information on using STAFEXECPROXY.

2.6 AIX (32-bit)

Supported Perl Version Built with PLSTAF library Perl Services
5.8.x (default) 5.8.8 (ActiveState) lib/perl58/libPLSTAF.so Not supported
5.10.x 5.10.0 (ActiveState) lib/perl510/libPLSTAF.so Not supported
Notes:
  1. Attempting to load STAF Perl services will result in the following error: Error: Can't load '/opt/ActivePerl-5.8/lib/auto/threads/threads.so' for module t hreads: rtld: 0712-001 Symbol Perl_Tstack_sp_ptr was referenced There is no workaround.

2.7 Solaris 10+ (Sparc 32-bit)

Supported Perl Version Built with PLSTAF library Perl Services
5.8.x (default) 5.8.8 (ActiveState) lib/perl58/libPLSTAF.so Supported
5.10.x 5.10.0 (ActiveState) lib/perl510/libPLSTAF.so Supported
Notes:
  1. When using the STAF Perl library, if you get an error such as "libperl.so: cannot open shared object file", then you need to make sure the operating system can find the "libperl.so" file for the version of Perl you are using. There are two ways to resolve the problem (select which one is more suitable for your environment):

    • Update environment variable LD_LIBRARY_PATH to include the directory containing "libperl.so" file for the version of Perl you are using (i.e. export LD_LIBRARY_PATH=/opt/ActivePerl-5.8/lib/CORE:$LD_LIBRARY_PATH)

    • Create a /usr/lib/libperl.so link to the libperl.so file for the version of Perl you are using (i.e ln -s /opt/ActivePerl-5.8/lib/CORE/libperl.so /usr/lib/libperl.so)

  2. When loading Perl services, if you get an error such as "/opt/ActivePerl-5.8/lib/auto/threads/threads.so: undefined symbol: PL_no_mem at /opt/ActivePerl-5.8/lib/XSLoader.pm", you need to set environment variable LD_PRELOAD to the libperl.so file prior to starting STAFProc (i.e. export LD_PRELOAD=/opt/ActivePerl-5.8/lib/CORE/libperl.so).
    This will force the linker to pre-load libperl.so before loading anything else at start up time.
    If you do not want to set LD_PRELOAD before starting STAFProc (as this can cause incompatibility issues for processes started via STAFProc), you can load your Perl service via STAFEXECPROXY, and use OPTION PROXYENV to specify the LD_PRELOAD environment variable for the STAFEXECPROXY executable, without having it set for STAFProc's environment. See the STAF Users's Guide "STAFEXECPROXY service proxy library" section for more information on using STAFEXECPROXY.

2.8 Solaris 10+ (Sparc 64-bit)

Supported Perl Version Built with PLSTAF library Perl Services
5.8.x (default) 5.8.8 (ActiveState) lib/perl58/libPLSTAF.so Supported
5.10.x 5.10.0 (ActiveState) lib/perl510/libPLSTAF.so Supported
Notes:
  1. When using the STAF Perl library, if you get an error such as "libperl.so: cannot open shared object file", then you need to make sure the operating system can find the "libperl.so" file for the version of Perl you are using. There are two ways to resolve the problem (select which one is more suitable for your environment):

    • Update environment variable LD_LIBRARY_PATH to include the directory containing "libperl.so" file for the version of Perl you are using (i.e. export LD_LIBRARY_PATH=/opt/ActivePerl-5.8/lib/CORE:$LD_LIBRARY_PATH)

    • Create a /usr/lib/libperl.so link to the libperl.so file for the version of Perl you are using (i.e ln -s /opt/ActivePerl-5.8/lib/CORE/libperl.so /usr/lib/libperl.so)

  2. When loading Perl services, if you get an error such as "/opt/ActivePerl-5.8/lib/auto/threads/threads.so: undefined symbol: PL_no_mem at /opt/ActivePerl-5.8/lib/XSLoader.pm", you need to set environment variable LD_PRELOAD to the libperl.so file prior to starting STAFProc (i.e. export LD_PRELOAD=/opt/ActivePerl-5.8/lib/CORE/libperl.so).
    This will force the linker to pre-load libperl.so before loading anything else at start up time.
    If you do not want to set LD_PRELOAD before starting STAFProc (as this can cause incompatibility issues for processes started via STAFProc), you can load your Perl service via STAFEXECPROXY, and use OPTION PROXYENV to specify the LD_PRELOAD environment variable for the STAFEXECPROXY executable, without having it set for STAFProc's environment. See the STAF Users's Guide "STAFEXECPROXY service proxy library" section for more information on using STAFEXECPROXY.

2.9 Mac OS X 10.10+ (Universal binary with support for i386 and x86_64)

Supported Perl Version Built with PLSTAF library Perl Services
5.18.x (default) 5.18.2 lib/perl518/libPLSTAF.dylib Supported
5.16.x 5.16.3 lib/perl516/libPLSTAF.dylib Supported


3.0 Installation

To install and configure STAF Perl support, perform the following steps:

  1. Install STAF's Perl support by selecting to install "Perl support" during the install. It is installed by default for a "typical" install of STAF if using a STAF installer for Windows (Intel 32-bit), Windows (AMD64, aka x64), Linux (Intel 32-bit, aka i386 or x86-32), Linux (AMD64, aka x86-64), AIX (32-bit), Solaris 10+ (Sparc 32-bit), Solaris 10+ (Sparc 64-bit), or Mac OS X (Universal). Currently, STAF Perl support is not provided in the STAF installer files for other operating systems (though you can build STAF Perl support yourself). See section 1.0 Introduction above for more information on how to build STAF Perl support yourself.

    Once STAF Perl support is installed, verify that the following STAF Perl files exist:

    The library file for the version of Perl that was selected as the default Perl version during the STAF installation (when using the Installshield installer) will either have a link in {STAF/Config/STAFRoot}/lib (on Linux) or a copy in {STAF/Config/STAFRoot}/bin on Windows.

  2. In order to have your Perl script find the specified module, you may need to follow one, and only one, of these steps:

  3. Finally, you need to add a "use" or "require" statement in your Perl scripts for any of the STAF packages (e.g. PLSTAF, STAFMon, STAFLog) that your Perl script uses. For example, if you want to use the PLSTAF package in your Perl script, add the following line at the beginning:
      use PLSTAF;
    
    Note that use loads modules at compile time whereas require loads modules at run time.


4.0 Package PLSTAF

The PLSTAF package provides the based level of support for Perl scripts to call into STAF in two different programming styles, procedural or object-oriented. This package externalizes the following classes, functions, and constants.

The procedural style of communicating with STAF uses the following methods:

The object-oriented style of communicating with STAF uses the following class:

Other STAF Perl classes that it externalizes are:

Other STAF Perl functions that it externalizes are:

4.1 Primary STAF APIs

These APIs allow you to register/unregister with STAF, submit STAF service requests, and to wrap the values of options used in STAF service requests.

4.1.1 Procedural Style

4.1.1.1 STAF::Register

Description

This function allows you to register with STAF.  You must register with STAF before you can use any of the other STAF related APIs. After calling this function, 2 magic variables, $STAF::Handle and $STAF::RC are created and set. These variables should not be modified directly. $STAF::Handle contains the handle that will allow your program to interact with STAF. $STAF::RC is equivalent to the value returned by the API itself.

Syntax

STAF::Register(PROCESSNAME)

where,

PROCESSNAME is the name by which your Perl program will be known

Result

The function returns a numeric return code.  Zero indicates that you registered successfully.  Non-zero return codes are documented in the STAF User's Guide.

Examples

4.1.1.2 STAF::Submit

Description

This function allows you to submit requests to STAF.  This is the primary API that you will use when working with STAF. After calling this function, 2 magic variables, $STAF::Result and $STAF::RC are created and set. These variables should not be modified directly. $STAF::Result contains the string-based result for this request. $STAF::RC is equivalent to the value returned by the API itself.

Syntax

STAF::Submit(LOCATION, SERVICE, REQUEST)

where,

LOCATION is the system to which the request should be submitted.  "Local" may be used to represent the local system, i.e., the system on which the Perl program is running.

SERVICE is the name of the service to which the request should be submitted.

REQUEST is the actual request string itself.

Result

The function returns a numeric return code.  Return codes are documented in the STAF User's Guide.

Examples

  1. The following example shows submitting a request to a STAF service that returns a single string result.

  2. This example submits a request to the FS service to query information about a file. The request returns a marshalled string so it needs to be unmarshalled in order to access the marshalling context's root object which is a map that contains keys like 'type', 'lowerSize', and 'lastModifiedTimestamp'. (Note that the STAF User's Guide defines the results for each request submitted to an internal STAF service.)

  3. This example submits a request to the FS service to list the names of the entries in a directory. The request returns a marshalled string so you need to unmarshall the result string in order to get the marshalling context whose root object is a list of strings, where each string in the list contains the name of an entry in the directory. (Note that the STAF User's Guide defines the results for each request submitted to an internal STAF service.)

    This example could print the following when run:

4.1.1.3 STAF::Submit2

Description

This function allows you to submit requests to STAF.  This is the primary API that you will use when working with STAF. After calling this function, 2 magic variables, $STAF::Result and $STAF::RC are created and set. These variables should not be modified directly. $STAF::Result contains the string-based result for this request. $STAF::RC is equivalent to the value returned by the API itself. The STAF::Submit2 method is identical to the STAF:Submit method except that it has an additional parameter, SYNCTOPTION, which allows submission of asynchronous requests.

Syntax

STAF::Submit2(SYNCOPTION, LOCATION, SERVICE, REQUEST)

where,

SYNCOPTION can be any of the following:

LOCATION is the system to which the request should be submitted.  "Local" may be used to represent the local system, i.e., the system on which the Perl program is running.

SERVICE is the name of the service to which the request should be submitted.

REQUEST is the actual request string itself.

Result

The function returns a numeric return code.  Return codes are documented in the STAF User's Guide.

Example

4.1.1.4 STAF::UnRegister

Description

This function allows you to unregister with STAF.  This allows STAF to free up the information associated with your handle.  This should be the last STAF related API that you call in your program.  After calling this function, 1 magic variable, $STAF::RC is created and set. This variables should not be modified directly. $STAF::RC is equivalent to the value returned by the API itself.

Syntax

STAF::UnRegister()

Result

This function returns a numeric return code.  Zero indicates that you unregistered successfully.  Non-zero return codes are documented in the STAF User's Guide.

Example

4.1.2 Object-Oriented Style

4.1.2.1 STAF::STAFHandle::new

Description

This method constructs a STAF::STAFHandle object that allows you to call into STAF. You must create a STAF::STAFHandle object before you can use any of its STAF related methods.

There are two ways to create a STAF::STAFHandle object:

Once you have a valid STAFHandle object, you can begin submitting requests to STAF services. To do this, you use the STAFHandle's submit() or submit2() method.

STAFHandle defines the following member variables. They are initialized by the constructor, and should not be modified directly.

Syntax

STAF::STAFHandle->new(HANDLENAMEORNUMBER, [HANDLETYPE])

where,

HANDLENAMEORNUMBER is a required argument that specifies a handle name or number. If you specify a standard handle type (the default), this argument must be a string containing a name for the STAF handle to be created. If you specify a static handle type for the second argument, this argument must be an integer containing the handle number for an existing static STAF handle.

HANDLETYPE is an optional argument that specifies the type of handle. The valid handle types are:

The HANDLETYPE argument was added in STAF V3.3.3.

Result

The method returns a STAF::STAFHandle object that contains a numeric return code, and a numeric handle, a numeric handle type, and a numeric doUnmarshallResult (all scalars). These fields should not not be manipulated directly. A return code of zero indicates that you registered successfully. Non-zero return codes are documented in the STAF User's Guide.

Example

The following is an example of Perl code which registers with STAF using a standard handle type and specifying handle name "My program". Then it uses the handle to submit a STAF ping request to the local machine, and unregisters the handle. The following is an example of Perl code which registers with STAF using a static STAF handle and then submits a STAF ping request to the local machine. Note that a static handle is a handle which can be shared by several processes on the same system. See the STAF User's Guide for more information on static handles. Generally, you don't need to use a static STAF handle. Then it uses the handle to submit a STAF ping request to the local machine.

4.1.2.2 STAF::STAFHandle::submit

Description

This method allows you to submit requests to STAF.  This is the primary method that you will use when working with STAF.

Syntax

STAF::STAFHandle->submit(LOCATION, SERVICE, REQUEST)

where,

LOCATION is the system to which the request should be submitted.  "Local" may be used to represent the local system, i.e., the system on which the Perl program is running.

SERVICE is the name of the service to which the request should be submitted.

REQUEST is the actual request string itself.

Result

The function returns a STAF::STAFResult object that contains a numeric return code and a string-based result. Return codes are documented in the STAF User's Guide. The string-based result will contain the textual result buffer from this request. See the individual service documentation for information on the contents of this buffer.

In addition, if auto-unmarshalling is enabled for the handle that called the submit() method (e.g. if the handle's doUnmarshallResult field is set to 1), the STAF::STAFResult object also contains the marshalling context for the result (e.g. the unmarshalled result) and the result object (e.g. the root object of the marshalling context) so that you don't have to call the handle's unmarshall method to unmarshall results. Otherwise, if auto-unmarshalling is disabled, the resultContext and resultObj fields in the STAF::STAFResult object will be set to undef.

Examples

  1. The following example shows submitting a request to a STAF service that returns a single string result.

  2. The following example shows the use of the STAFResult class when submitting a request to a STAF service (using a handle that has auto-unmarshalling results enabled) that returns a marshalled result string whose root object is a Map.

  3. This example submits a request to the PROCESS service to run a command on a machine and to wait for the command to complete. It shows the use of the STAFResult class when submitting a request to a STAF service using a handle that has auto-unmarshalling results enabled. The request returns marshalled data whose root object is a map that contains keys like 'rc' and 'fileList'. The value for 'fileList' is a list of the returned files. Each entry in the list consists of a map that contains keys 'rc' and 'data'. In our PROCESS START request, we returned one file, stdout, and returned stderr to this same file. (Note that the STAF User's Guide defines the results for each request submitted to an internal STAF service.)

    This example could print the following when run:

  4. This example submits a request to the FS service to list entries in a directory in the long format. The request returns marshalled data whose root object is a list of map class objects, where each map class object in the list contains keys like 'type', 'size', and 'name'. (Note that the STAF User's Guide defines the results for each request submitted to an internal STAF service.)

    This example shows the use of the STAFResult class when submitting a request to a STAF service using a handle that has auto-unmarshalling results enabled.

    This example could print the following when run:

4.1.2.3 STAF::STAFHandle::submit2

Description

This method allows you to submit requests to STAF.  This is the primary method that you will use when working with STAF. The STAF::STAFHandle::submit2 method is identical to the STAF::STAFHandle:submit method except that it has an additional parameter, SYNCTOPTION, which allows submission of asynchronous requests.

Syntax

STAF::STAFHandle->submit2(SYNCOPTION, LOCATION, SERVICE, REQUEST)

where,

SYNCOPTION can be any of the following:

LOCATION is the system to which the request should be submitted.  "Local" may be used to represent the local system, i.e., the system on which the Perl program is running.

SERVICE is the name of the service to which the request should be submitted.

REQUEST is the actual request string itself.

Result

The function returns a STAF::STAFResult object that contains a numeric return code and a string-based result. Return codes are documented in the STAF User's Guide. The string-based result will contain the textual result buffer from this request. See the individual service documentation for information on the contents of this buffer.

In addition, if auto-unmarshalling is enabled for the handle that called the submit() method (e.g. if the handle's doUnmarshallResult field is set to 1), the STAF::STAFResult object also contains the marshalling context for the result (e.g. the unmarshalled result) and the result object (e.g. the root object of the marshalling context) so that you don't have to call the handle's unmarshall method to unmarshall results. Otherwise, if auto-unmarshalling is disabled, the resultContext and resultObj fields in the STAF::STAFResult object will be set to undef.

Example

4.1.2.4 STAF::STAFHandle::unRegister

Description

This method allows you to unregister with STAF.  This allows STAF to free up the information associated with your handle.  This should be the last STAF related API that you call in your program.

Syntax

STAF::STAFHandle->unRegister()

Result

This method returns a numeric return code.  Zero indicates that you unregistered successfully.  Non-zero return codes are documented in the STAF User's Guide.

Example

3.1.2.5 STAF::STAFHandle::setDoUnmarshallResult

Description

This method allows you to set the doUnmarshallResult flag which indicates if auto-unmarshalling results will be performed when the handle submits a STAF service request.

Syntax

STAF::STAFHandle->setDoUnmarshallResult(doUnmarshallResult)

where,

doUnmarshallResult should be 0 to disable auto-unmarshalling results or 1 to enabling auto-unmarshalling results when the handle submits a STAF service request.

Since: STAF V3.3.1

Result

This method doesn't return anything.

Example

3.1.2.6 STAF::STAFHandle::getDoUnmarshallResult

Description

This method allows you to get the doUnmarshallResult flag which indicates if auto-unmarshalling results will be performed when the handle submits a STAF service request.

Syntax

STAF::STAFHandle->getDoUnmarshallResult()

Result

This method returns the doUnmarshallResult flag which indicates if auto-unmarshalling results will be performed when the handle submits a STAF service request.

Since: STAF V3.3.1

Example

4.1.3 Class STAF::STAFResult

Definition

class STAF::STAFResult
This class encapsulates the result of a STAF service request (made via the STAFHandle.submit() method). This class also contains a set of constants representing the various common STAF return codes.

Class STAF::STAFResult defines the following methods:

Class STAF::STAFResult defines the following member variables. They are initialized by the constructor, and should not be modified directly.

Examples

You can create a new STAF::STAFResult object with an RC of 0 and a result of "Successful" as follows:

The following example shows the use of the STAFResult class in calling a STAF service that returns a simple string result.

The following example shows the use of the STAFResult class in calling a STAF service that returns a marshalled map result.

4.1.4 Function STAF::WrapData (or STAF::STAFUtil::WrapData)

Definition

Result

Example

4.2 Marshalling APIs

These APIs allow you to define, manipulate, and (un)marshall data structures, and print marshalled data in human-readable ("pretty" print) format.

STAF supports the automatic marshalling and unmarshalling of structured data. The act of marshalling takes a data structure and converts it into a string-based representation. The act of unmarshalling reverses this and converts the string-based representation back into a data structure. See Section 6.1, "Marshalling Structured Data" in the STAF User's Guide for more information.

4.2.1 Class STAF::STAFMapClassDefinition

Definition

class STAF::STAFMapClassDefinition
A class which provides the metadata associated with a map class. In particular, it defines the keys associated with the map class. This class is used to create and/or access a STAF map class definition which can be useful if you want to generate a STAF marshalling context with map classes. The map class definition is used to reduce the size of a marshalling map class in comparison to a map containing the same data. It also contains information about how to display instances of the map class, such as the order in which to display the keys and the display names to use for the keys. You get and set map class definitions using the STAF::STAFMarshallingContext class setMapClassDefinition and getMapClassDefinition methods.

Class STAF::STAFMapClassDefinition defines the following methods:

Example

The following is an example of how to create a map class definition named 'Test/MyMap' containing four keys, each with a display name, and one with a short display name. This example prints the following:

4.2.2 Class STAF::STAFMarshallingContext

Definition

class STAF::STAFMarshallingContext
A class is used to create and/or access a STAF marshalling context which is used by STAF to help in marshalling and unmarshalling data. A marshalling context is simply a container for map class definitions and a data structure that uses (or is defined in terms of) them.

In order to use a map class when marshalling data, you must add the map class definition to the marshalling context, set the root object of the marshalling context to the object you want to marshall, and then marshall the marshalling context itself. When you unmarshall a data structure, you will always receive a marshalling context. Any map class definitions referenced by map classes within the data structure will be present in the marshalling context.

The primary use of this class is to represent multi-valued results that consist of a data structure (e.g. results from a QUERY/LIST service request, etc.) as a string that can also be converted back into the data structure. This string can be assigned to the string result buffer returned from the service request.

Class STAFMarshallingContext defines the following methods:

Examples

The following is an example of how to create a marshalling context containing one map class definition named 'Test/MyMap' and a root object which is a list of maps defined by the map class definition. Then it shows how to marshall and unmarshall and marshalling context. This example prints the following:

4.2.3 Function STAF::STAFIsMarshalledData

Definition

Example

4.2.4 Function STAF::STAFMarshall

Definition

Examples

  1. This example converts a Perl hash (aka map) into a string-based marshalled representation. It also shows how to convert this marshalled string back into the original Perl hash. This example could print the following:

  2. This example creates a marshalling context with one map class definition and a Perl array (aka list) where each entry is a hash (aka map). It then creates a string-based marshalled representation of it.

4.2.5 Function STAF::STAFUnmarshall

Definition

Example

This example shows how to unmarshall the result from a QUEUE GET request. The result is a marshalled string representing a marshalling context whose root object is a Perl hash (aka map) object.

4.2.6 Function STAF::STAFFormatObject

Definition

Examples

  1. This example that prints a Perl hash in a "pretty" verbose format: This could result in the following output printed:

  2. This example prints the result from a FS QUERY ENTRY request in a "pretty" verbose format: If successful, this could result in the following output printed: However, note that specifying instead of using the STAF::STAFFormatObject function to print the formatted output for the marshalled context, you could simply call the marshalling context's formatObject function to get the same output. For example:

4.3 Private Data Manipulation APIs

These APIs allow you to handle private data. See Section 7.3, "Private Data" in the STAF User's Guide for more information about handling private data.

4.3.1 Function STAF::AddPrivacyDelimiters

Definition

Result

Examples

This example adds privacy delimiters to "passw0rd" used in the PASSWORD option when starting a process as another user. This example adds privacy delimiters to password "secret" used in the COMMAND option when starting a process.

4.3.2 Function STAF::EscapePrivacyDelimiters

Definition

Result

Examples

This example escapes privacy delimiters in password "passw@!!d" before adding privacy delimiters to it and then uses the password in the PASSWORD option when starting a process as another user.

4.3.3 Function STAF::RemovePrivacyDelimiters

Definition

Result

Examples

This example removes privacy delimiters from protected password '!!@secret@!!' and assigns 'secret' as the password.

4.3.4 Function STAF::MaskPrivateData

Definition

Result

Examples

This example masks any private data indicated by privacy delimiters in a request string before displaying it. This example prints:
START COMMAND C:/tests/TestA.exe USERNAME Test1 PASSWORD **************

4.4 STAF Return Codes

In addition to the described APIs, the following variables are defined, which represent the numeric return codes generated by STAF. For a complete description of these return codes and their meaning, please see the STAF User's Guide.

4.5 STAF Constants

The following variables are defined which represent the sync options that can be specified for Submit2/submit2. These variables were added in STAF V3.2.1.

The following variables are defined which represent the handle types that can be specified for the STAF::STAFHandle->new() function. These variables were added in STAF V3.3.3.


5.0 Package STAFMon

The STAFMon package provides a function to ease the use of the Monitor service, as well as, variables which define the return codes from the Monitor service and variables which affect the operation of the utility function provided.

5.1 Monitor Service Variables

The following variables affect the behavior of the STAFMon package. These variable values may be changed to alter the behavior of the STAFMon package.

  • STAF::Monitor::SystemName - The system name to which Monitor service requests should be sent (default = local)
  • STAF::Monitor::ServiceName - The service name to which Monitor service requests should be sent (default = monitor)
  • 5.2 Procedural Style

    5.2.1 STAF::Monitor::Log

    Description

    This function logs a message to the Monitor service.

    Syntax

    STAF::Monitor::Log(MESSAGE, [OPTIONS])

    where,

    MESSAGE is the message to log.

    OPTIONS are any additional options that should be passed on the LOG request, e.g., RESOLVEMESSAGE. The default is "".

    Result

    This function returns a numeric return code. Return codes are documented in the STAF User's Guide.

    Example

    5.3 Object-Oriented Style

    5.3.1 STAF::STAFMonitor::new

    Description

    This method constructs a new STAF::STAFMonitor object to log messages to the Monitor service.

    Syntax

    STAF::STAFMonitor->new(HANDLE, [SYSTEMNAME], [SERVICENAME])

    where,

    HANDLE is a STAF::STAFHandle object obtained at registration time.

    SYSTEMNAME is the name of the system where the Monitor service is installed. The default is "LOCAL".

    SERVICENAME is the name by which the Monitor service is identified. The default is "MONITOR".

    Result

    This method returns STAF::Monitor object to log messages to the Monitor service.

    Example

    5.3.2 STAF::STAFMonitor::log

    Description

    This method logs a message to the Monitor service.

    Syntax

    STAF::STAFMonitor->log(MESSAGE, [OPTIONS])

    where,

    MESSAGE is the message to log.

    OPTIONS are any additional options that should be passed on the LOG request, e.g., RESOLVEMESSAGE. The default is "".

    Result

    This function returns a STAF::STAFResult object that contains a numeric return code and a string-based result.

    Example

    5.3.3 STAF::STAFMonitor::getSystemName

    Description

    This method returns the name of the system where the Monitor resides (defaults to "LOCAL"). This value can be changed at construction time. See 5.3.1 STAF::STAFMonitor::new.

    Syntax

    STAF::STAFMonitor->getSystemName()

    Result

    This function returns a string containing the name of the system where the Monitor service resides.

    Example

    5.3.4 STAF::STAFMonitor::getServiceName

    Description

    This method returns the name that the Monitor service used when it registered with STAF (defaults to "MONITOR"). This value can be changed at construction time. See 5.3.1 STAF::STAFMonitor::new.

    Syntax

    STAF::STAFMonitor->getServiceName()

    Result

    This function returns a string containing the name that the Monitor service used when it registered.

    Example


    6.0 Package STAFLog

    The STAFLog package provides a set of functions to ease the use of the Log service, as well as, variables which define the return codes from the Log service and variables which affect the operation of the utility functions provided. These functions also interface with the Monitor service to allow messages which are logged to also be monitored.

    6.1 Log Service Return Codes

    The following variables are defined, which represent the numeric return codes generated by the STAF Monitor service.
  • STAF::Log::kInvalidLevel
  • STAF::Log::kInvalidLogFileFormat
  • STAF::Log::kPurgeFailure
  • For a complete description of these return codes and their meaning, please see the STAF User's Guide.

    The following variables affect the behavior of the STAFLog package. These variable values may be changed to alter the behavior of the STAFLog package.

  • STAF::Log::SystemName - The system name to which Log service requests should be sent (default = local)
  • STAF::Log::ServiceName - The service name to which Log service requests should be sent (default = log)
  • 6.2 Procedural Style

    6.2.1 STAF::Log::Init

    Description

    This function initializes the utility functions for a specific log file.

    Syntax

    STAF::Log::Init(LOGNAME, [LOGTYPE], [MONITORMASK])

    where,

    LOGNAME is the name of the log.

    LOGTYPE is the type of log to be created, "GLOBAL", "MACHINE", or "HANDLE". The default is "MACHINE".

    MONITORMASK is the set of logging levels which will also be sent to the Monitor service. The default is "FATAL ERROR WARNING INFO STATUS".

    Result

    This function returns a numeric return code. Return codes are documented in the STAF User's Guide.

    Example

    6.2.2 STAF::Log::Log

    Description

    This function logs a message to the Log service. This function will also log the message to the Monitor service if the specified logging level is one of the levels defined in the Monitor Mask (set in STAF::Log::Init, above).

    Syntax

    STAF::Log::Log(LEVEL, MESSAGE, [OPTIONS])

    where,

    LEVEL is the level of the message to log, e.g., "WARNING" or "DEBUG".

    MESSAGE is the message to log.

    OPTIONS are any additional options that should be passed on the LOG request, e.g., "RESOLVEMESSAGE". The default is "".

    Result

    This function returns a numeric return code. Return codes are documented in the STAF User's Guide.

    Example

    6.3 Object-Oriented Style

    6.3.1 STAF::STAFLog::new

    Description

    This method constructs a STAF::STAFLog object to log messages to the Log service.

    Syntax

    STAF::STAFLog->new(HANDLE, LOGNAME, [LOGTYPE], [MONITORMASK], [SYSTEMNAME], [SERVICENAME])

    where,

    HANDLE is a STAF::STAFHandle object obtained at registration time.

    LOGNAME is the name of the log.

    LOGTYPE is the type of log to be created, "GLOBAL", "MACHINE", or "HANDLE". The default is "MACHINE".

    MONITORMASK is the set of logging levels which will also be sent to the Monitor service. The default is "FATAL ERROR WARNING INFO STATUS".

    SYSTEMNAME is the name of the system where the Log service is installed. The default is "LOCAL".

    SERVICENAME is the name by which the Log service is identified. The default is "LOG".

    Result

    This method returns STAF::Log object to log messages to the Log service.

    Example

    6.3.2 STAF::STAFLog::log

    Description

    This method logs a message to the Log service. This method will also log the message to the Monitor service if the specified logging level is one of the levels defined in the Monitor Mask (set in STAF::STAFLog::new, above).

    Syntax

    STAF::STAFLog->log(LEVEL, MESSAGE, [OPTIONS])

    where,

    LEVEL is the level of the message to log, e.g., "WARNING" or "DEBUG".

    MESSAGE is the message to log.

    OPTIONS are any additional options that should be passed on the LOG request, e.g., "RESOLVEMESSAGE". The default is "".

    Result

    This function returns a STAF::STAFResult object that contains a numeric return code and a string-based result.

    Example

    6.3.3 STAF::STAFLog::getName

    Description

    This method returns the name that uniquely identifies your constructed log.

    Syntax

    STAF::STAFLog->getName()

    Result

    This function returns a string containing the name of the log being used. This value is set at construction time. See 6.3.1 STAF::STAFLog::new.

    Example

    6.3.4 STAF::STAFLog::getLogType

    Description

    This method returns the log type (either "MACHINE", "HANDLE", or "GLOBAL").

    Syntax

    STAF::STAFLog->getLogType()

    Result

    This function returns a string representing the log type. This value is set at constructions time, and is one of "MACHINE", "GLOBAL", or "HANDLE". See 6.3.1 STAF::STAFLog::new.

    Example

    6.3.5 STAF::STAFLog::getMonitorMask

    Description

    This method returns the monitor mask.

    Syntax

    STAF::STAFLog->getMonitorMask()

    Result

    This function returns a string containing the monitor mask. This value is set at construction time. See 6.3.1 STAF::STAFLog::new.

    Example

    6.3.6 STAF::STAFLog::getSystemName

    Description

    This method returns the name of the system where the Log resides (defaults to "LOCAL"). This value can be changed at construction time. See 6.3.1 STAF::STAFLog::new.

    Syntax

    STAF::STAFLog->getSystemName()

    Result

    This function returns a string containing the name of the system where the Log service resides.

    Example

    6.3.7 STAF::STAFLog::getServiceName

    Description

    This method returns the name that the Log service used when it registered with STAF (defaults to "LOG"). This value can be changed at construction time. See 6.3.1 STAF::STAFLog::new.

    Syntax

    STAF::STAFLog->getServiceName()

    Result

    This function returns a string containing the name that the Log service used when it registered.

    Example


    7.0 Perl Program Examples

    7.1 Example 1

    This example demonstrates using the procedural-style APIs to register with STAF, submit requests to STAF, and unregister with STAF. This example submits several different requests to the DIAG service and demonstrates how to use the STAF::wrapData API to "wrap" an option value that may contain spaces, etc. This example also shows how to unmarshall the data in the result returned by a DIAG LIST request. The result buffer for a DIAG LIST request contains a marshalled <Map:STAF/Service/Diag/AllDiagInfo> representing all of the unique trigger/source combinations. The comboList field in this map contains a marshalled <List> of <Map:STAF/Service/Diag> and this example shows how to iterate through this list of trigger/source combinations. The STAF User's Guide defines the results for each request submitted to an internal STAF service, including definitions of maps returned in a result.

    The source code for this program is provided in the STAF source code directory tree at src/staf/lang/perl/TestDiagList.pl. See section "Obtaining the STAF Source Code" in the STAF Developer's Guide for instructions on how to download STAF source code.

    This example could print the following when run:

    7.2 Example 2

    This example shows a Perl program that tests most of the STAF Perl APIs.

    The source code for this program is provided in the STAF source code directory tree at src/staf/lang/perl/TestPerl.pl. See section "Obtaining the STAF Source Code" in the STAF Developer's Guide for instructions on how to download STAF source code.

    This example could print the following when run:

    *** End of Document ***