The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Device::Network::ConfigParser - A harness for parsing network device configuration.

VERSION

version 0.004

SYNOPSIS

Device::Network::ConfigParser is a harness for parsing network device configuration. It exports a single subroutine - app() - which takes command line arguments and runs the harness. This module is used by the ncp command line utility. For information on how to use the command line utility, refer to the ncp, or following installation type perldoc ncp at the command line.

The harness supports specific parsing modules by:

  • Dynamically loading a specific parsing module based on command line arguments.

  • Slurping in the device configuration from STDIN or from a number of files.

  • Opening the required output filehandles.

DEVELOPING MODULES

Parsing modules exist within the Device::Network::ConfigParser:: namespace. For a vendor and type of device, the module is defined as Device::Network::ConfigParser::vendor::type.

The harness takes care of parsing the command line arguments, opening files (or STDIN/STDOUT) and slurping in their contents. It calls specified subroutines exported by the specified parsing module. Any module must export the following subroutines:

  • get_parser

    This sub receives no arguments, and must return a reference to an object or another subroutine that parses the configuration. This is most likely going to be a Parse::RecDescent object, but you're not limited to this.

  • parse_config

    This sub receives the reference returned by the get_parser sub, and the full contents of a file specified on the command line. It should return a reference a data structure that represents the parsed configuration.

  • post_process

    This sub receives the reference to the data structure returned by parse_config. It allows for some post-processing of the data structure. If no processing is required, it can be defined as sub post_process { return @_; }.

  • get_output_drivers

    This sub receives no arguments, and must return a HASHREF of subroutines used to output the parsed configurationm keyed on the command line argument. For example the sub may return:

        {
            csv => \&csv_output_driver,
        }  

    If the user specified --output csv as a command line argument, the csv_output_driver would be called. When called, each output driver receives a filehandle to write the output to, the name of the file, and the post-processed data structure.

    There is a default 'raw' driver always present, which uses Data::Dumper to serialise the structure. The module may return its own 'raw' driver which will override this default.

SUBROUTINES

app

The app subroutine in general takes @ARGV (although it could be any list) and runs the harness.

AUTHOR

Greg Foletta, <greg at foletta.org>

BUGS

Please report any bugs or feature requests to bug-device-network-configparser at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-Network-ConfigParser. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Device::Network::ConfigParser

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2017 Greg Foletta.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

AUTHOR

Greg Foletta <greg@foletta.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Greg Foletta.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.