The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::PABX::ParseLex - Parse output of /lex a e/ command for the iSDC PABX

Synopsis

        #!/usr/bin/env perl

        use strict;
        use warnings;

        use Data::Dumper;
        use Data::PABX::ParseLex;

        # -----------------------------------------------

        sub process
        {
                my($parser, $input_file_name) = @_;
                my($hash)                     = $parser -> parse($input_file_name);

                print Data::Dumper -> Dump([$hash], ['PABX']);

        }       # End of process.

        # -----------------------------------------------

        $Data::Dumper::Indent = 1;
        my($parser)           = Data::PABX::ParseLex -> new();

        process($parser, 'pabx-a.txt');
        process($parser, 'pabx-b.txt');

See examples/test-parse.pl for this test program, and the same directory for 2 test data files. The output is in examples/test-parse.log.

Note: My real data has of course been replaced in these files with random numbers.

Description

Data::PABX::ParseLex is a pure Perl module.

This module reads the output file from the 'lex a e' (List Extensions, All Extensions) command given to a PABX of type iSDC.

It returns a hash ref keyed by extension.

Distributions

This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro.

Constructor and initialization

new(...) returns an object of type Data::PABX::ParseLex.

This is the class's contructor.

Usage: Data::PABX::ParseLex -> new().

This method takes no parameters.

Method: parse($input_file_name)

Returns: A hash ref of the data read from the file.

The file is assumed to be the output of the 'lex a e' command issued to a PABX of type iSDC.

The 'lex a e' command may have been run several times, and the output of all runs concatenated into the file. This module checks for multiple copies of the output, and discards all but the last. It does this by looking for the string /lex a e/i, and deleting all data from the start of the file down to the record containing this string.

Typical lines in the input file look like:

        EN22433   EC141702    KSGM  CS11  TA07 MOH 000  BE BI RE RI 54103
        Ron S
        DN58903   BC0123      A04  D  TP02    CS31  TA31 MOH 000

where '22433' and '58903' are the extensions.

The other fields on the line are attributes of this extension.

Fields are generated from such lines by splitting the lines on spaces, except for lines such as 'Ron S'.

The line 'Ron S' needs a bit of an explanation. This field is known in this module as the KSGM id. You see, some lines don't contain extensions. They contain the names people choose to have appear on the caller's display. 'Ron S' is such an id. The KSGM id may be blank.

The keys of the returned hash are the 4 or 5 digit extensions.

Each of these keys points to another hash ref with the following keys (listed in alphabetical order):

o ksgm_id

This would be 'Ron S' above.

o number_type

This comes from the first 2 characters of each line containing an extension.

This would be 'EN' in the first line above, and 'DN' in the third line.

o pabx_card_type

This would be 'EC' from the field 'EC141702' above.

Typical values: AC, BC, DI, EC, IE, OC.

o pabx_port

When the pabx_card_type is AC, EC, IE or OC, this field consists of three sub-fields of 2 digits each:

o Shelf
o Slot
o Access

This would be '141702' from the field 'EC141702' above.

When the pabx_card_type is BC or DI, this field consists of one field of 4 digits.

This would be '0123' from the field 'BC0123' above.

If the pabx_card_type is none of the above, then both the pabx_card_type and the pabx_port are set to '-'.

The remaining fields on each line are options, and are stored thus:

o *

Store as key '*' and value '1'.

o $

Store as key '$' and value '1'.

o /A\s+(0\d)/

Store as key 'A' and value $1.

o ACD

Store as key 'ACD' and value 'QUEUE'.

o AGENT

Store as key 'AGENT' and value 'GROUP'.

o /(BE|BI|DG|HG|IE|KSGM?|MULT|RE|SPARE)/

Store as key $1 and value '1'.

o /CS\s+(\d{2})/

Store as key 'CS' and value $1.

This is the Class of Service attribute.

o /D\s+(00(1|2))/

Store as key 'D' and value $1.

o /II\s+(\d+)/

Store as key 'II' and value $1.

o /MLG\s+(\d+)/

Store as key 'MLG' and value $1.

o /MOH\s+000/

Store as key 'MOH' and value '000' (Zeros).

o /OG\s+(\d+)/

Store as key 'OG' and value $1.

o /RI\s+(\d+)/

Store as key 'RI' and value $1.

With RI and some other options, the parsing is a little bit slack, in that several options can be combined and followed by a single extension, which is what the \d+ is with RI. Since I did not need to process such data, I have not bothered to combine such options with the single trailing extension.

o /TA\s+(\d{2})/

Store as key 'TA' and value $1.

o /TP\s+(\d{2})/

Store as key 'TP' and value $1.

o /V\s+(00(1|2))/

Store as key 'V' and value $1.

Where 'V' is not followed by '00\d', the value used is '001'.

o /(\d+)/

Store as key '#' and value $1.

o Any other string

Store the string as the key in another internal hash, together with the value 0.

The keys in this hash can be returned, sorted, by calling the method unexpected().

Method: parse($input_file_name)

Parse the given file and return a hash ref as documented in the previous section.

Method: unexpected()

Return, sorted, the keys of the hash holding extension attributes not recognized by any of the above patterns.

Author

Data::PABX::ParseLex was written by Ron Savage <ron@savage.net.au> in 2005.

Home page: http://savage.net.au/index.html

Copyright

Australian copyright (c) 2005, Ron Savage. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html