View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Junos Development > junoscript-perl-6.4I0 > JUNOS::Access



Annotate this POD


New  4
Open  0
View/Report Bugs


JUNOS::Access - Implement the Access Method superclass. All Access Method classes must subclass from JUNOS::Access.


This example is extracted from It creates an Access object based on the access method type specified in $self (a reference to a hash table containing information such as login, password, access method type and destination hostname). Then it starts a session with the JUNOScript server at the destination host by calling the connect method in the access object. After the session is established, it goes on to perform the initial handshake with the JUNOScript server.

    my $conn = new JUNOS::Access($self);

    # Need better error handling here....
    ref($conn) || die "Could not open connection";

    # Record the connection; connect it, mark it
    $self->{JUNOS_Conn} = $conn;
    $conn->connect() || die "Could not connect";
    $self->{JUNOS_Connected} = 1;

    # Kick off the XML parser
    trace("Trace", "starting connect::\n");

    # We need to receive the server side of the initial handshake first
    # (at least the <?xml?> part), so that we can avoid sending our
    # handshake to the ssh processes initial prompts (password/etc).

    # So we wait til we see the start of the real XML data flow....
    until ($self->{JUNOS_Active}) {
        my $in = $conn->recv();
        my $waiting = 'waiting for xml';
        if( $conn->{seen_xml} ) { $waiting = 'found xml'; }
        trace("IO", "during connect - ($waiting) input:\n\t$in\n" );

        if ($conn->{seen_xml}) {
            # After we've seen xml, parse anything
        } elsif ($in =~ /<\s*\?/) {
            $in =~ s/^[\d\D]*(<\s*\?)/$1/;
            $conn->{seen_xml} = 1;
        } else {
            if (not $conn->incoming($in) or $conn->eof) {
                return undef;

        if ($conn->eof) {
        } else {

    # Send our half of the initial handshake
    my $xml_decl = '<?xml version="1.0" encoding="us-ascii"?>';
    my $junoscript = '<junoscript version="1.0" os="perl-api">';

    $conn->send($xml_decl . "\n" . $junoscript . "\n");


This is an internal class used by JUNOS::Device only. Its constructor returns an access method class based on the access method specified by JUNOS::Device. If the access method 'telnet' is selected, an object of class JUNOS::Access::telnet will be returned. Once JUNOS::Device has the reference to the new access method object, it uses it to make connection, and exchange information with the destination.

All access method classes (e.g. JUNOS::Access::telnet) must subclass from JUNOS::Access.



The constructor of JUNOS::Access simply looks at the access method type and creates and returns an object of class JUNOS::Access::<access_method> (e.g. JUNOS::Access::telnet). $CLASS is the prefix for the access method class, "$CLASS::$access". $ARGS is the reference to a hash table containing the type of the access method, this hash table is supplied by the application while calling the constructor of JUNOS::Device.



This method is called to start a session with the destination host. Internally, this method simplies calls the start method which is always overloaded by the subclass.

ARGS is a hash table containing additional input parameters to establish the session. See the individual access method subclass to see if additional iput parameters are accepted.


shutdown the underlying mechanics and free/destory them. This method should be overloaded by the subclass. If not overloaded, it simplies kill the process that it started for the current session, which works for telnet and rsh.


Has the end-of-file been seen?


Feed data back to the access method when JUNOS::Device finds something that it doesn't understand. This is to have the access method object parse the connection specific messages, such as 'Host not found'. These messages are specific to the access method type so the incoming method is always overridden by the subclass. If the underlying code used by the subclass already deals with errors in connect(), recv() or send(), then this can be a NOP method.


read the next chunk of data.


send data to the JUNOScript server.


To be overloaded by subclass to start the underlaying mechanics to open a session with the JUNOScript server at the destination.

ARGS is a hash table containing additional input parameters to establish the session. See the individual access method subclass to see if additional iput parameters are accepted.

start_command($ACCESS, @FLAGS, $WHO, $EXEC)

This method is called by the subclass of JUNOS::Access to start a telnet or rsh session.


This method is called by the subclass to start a command using unix-domain socket pairs; it is currently not used.

The following hash keys are used by JUNOS::Device.


Whether the <xml> element has been received.


Whether eof has been received.




Juniper Junoscript Perl Team, send bug reports, hints, tips, and suggestions to


Copyright (c) 2001 Juniper Networks, Inc. All rights reserved.

syntax highlighting: