Device::Network::ConfigParser - harness for parsing network configurations.
version 0.006
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.
app()
ncp
perldoc ncp
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.
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.
Device::Network::ConfigParser::
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. All modules must export the following subroutines:
my $module_parser = get_parser();
This sub receives no arguments, and must return a reference to an object or subroutine that parses the configuration. This is most likely going to be a Parse::RecDescent object, but you're not limited to this.
my $parsed_config = parse_config($module_parser, $device_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.
get_parser
my $processed_config = post_process($parsed_config);
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 @_; }.
parse_config
sub post_process { return @_; }
open($fh, ">>:encoding(UTF-8)", $output_filename); my $output_drivers = get_output_drivers(); $output_drivers->{csv}->($fh, $output_filename, $processed_config);
This sub takes 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, }
The drivers themselves take a filehandle to write the output to (this may be STDOUT), the output filename, and the post-processed configuration.
The driver called is based on the --output csv as a command line argument
--output csv
There are two default drivers:
the 'raw' driver, which uses Data::Dumper to serialise the structure, and
the 'json' driver, which encodes the data structure as JSON.
A module may return their own 'raw' or 'json' drivers which override these defaults.
The app subroutine in general takes @ARGV (although it could be any list) and runs the harness.
app
@ARGV
Greg Foletta, <greg at foletta.org>
<greg at foletta.org>
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.
bug-device-network-configparser at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Device::Network::ConfigParser
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Device-Network-ConfigParser
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Device-Network-ConfigParser
CPAN Ratings
http://cpanratings.perl.org/d/Device-Network-ConfigParser
Search CPAN
http://search.cpan.org/dist/Device-Network-ConfigParser/
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.
To install Device::Network::ConfigParser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Network::ConfigParser
CPAN shell
perl -MCPAN -e shell install Device::Network::ConfigParser
For more information on module installation, please visit the detailed CPAN module installation guide.