Import Perl Modules and Declare Constants in Junos XML Protocol Perl Client Applications
When creating a Junos XML protocol Perl client application,
include the following statements at the start of the application.
The use JUNOS::Device;
statement imports
the functions provided by the JUNOS::Device
object, which the application uses to connect to the Junos XML protocol
server on a device running Junos OS. The use strict
statement provides error checking and enforces Perl coding practices
such as declaration of variables before use.
use JUNOS::Device; use strict;
Include statements to import other Perl modules as appropriate for your application. For example, several of the sample scripts included in the Junos XML protocol Perl distribution import the following standard Perl modules, which include functions that handle input from the command line:
File::Basename
—Includes functions for processing filenames.Getopt::Std
—Includes functions for reading in keyed options from the command line.Term::ReadKey
—Includes functions for controlling terminal modes, for example suppressing onscreen echo of a typed string such as a password.
If the application uses constants, declare their values at this point. For example, the sample diagnose_bgp.pl script includes the following statements to declare constants for formatting output:
use constant OUTPUT_FORMAT => "%-20s%-8s%-8s%-11s%-14s%s\n"; use constant OUTPUT_TITLE => "\n=============== BGP PROBLEM SUMMARY ===============\n\n"; use constant OUTPUT_ENDING => "\n===================================================\n\n";
The load_configuration.pl sample script includes the following statements to declare constants for reporting return codes and the status of the configuration database:
use constant REPORT_SUCCESS => 1; use constant REPORT_FAILURE => 0; use constant STATE_CONNECTED => 1; use constant STATE_LOCKED => 2; use constant STATE_CONFIG_LOADED => 3;