NAME
YAML::yq::Helper - Wrapper for yq for various common tasks so YAML files can be manipulated in a manner to preserve comments and version header.
VERSION
Version 0.0.1
SYNOPSIS
use YAML::yq::Helper;
my $yq = YAML::yq::Helper->new(file='/etc/suricata/suricata-ids.yaml');
$yq->set_array(var=>'rule-files', vals=>['suricata.rules','custom.rules'])
METHODS
new
Inits the object and check if a version header is present for use with the ensure method.
Will make sure the file specified exists, is a file, is readable, and is writable. Otherwise it will die.
Will also die if yq is not in the path.
- file :: The YAML file to operate on.
clear_array
Clears the entries in a array, but does not delete the array.
Will die if called on a item that is not a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
$yq->clear_array(var=>'rule-files');
clear_hash
Clears the entries in a hash, but does not delete the hash.
Will die if called on a item that is not a hash.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
$yq->clear_hash(var=>'rule-files');
create_array
Creates a empty array. Unlike set_array, vals is optional.
Will die if it already exists.
- var :: Variable to operate on. If not matching /^\./,
a period will be prepended.
- vals :: Array of values to set the array to.
$yq->clear_array(var=>'rule-files');
create_array
Creates a empty array.
Will die if it already exists.
- var :: Variable to operate on. If not matching /^\./,
a period will be prepended.
$yq->clear_array(var=>'rule-files');
delete
Deletes an variable. If it is already undef, it will just return.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
$yq->delete_array(var=>'rule-files');
delete_array
Deletes an array. If it is already undef, it will just return.
Will die if called on a item that is not a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
$yq->delete_array(var=>'rule-files');
delete_hash
Deletes an hash. If it is already undef, it will just return.
Will die if called on a item that is not a hash.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
$yq->delete_hash(var=>'vars');
ensure
Makes sure that the YAML file has the version at the top.
$yq->ensure;
is_array
Checks if the specified variable in a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
if ( $yq->is_array(var=>'rule-files') ){
print "array...\n:";
}
is_array_clear
Checks if a array is clear or not.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
if ( $yq->is_array_clear(var=>'rule-files') ){
print "clear...\n:";
}
is_defined
Checks if the specified variable is defined or not.
Will die if called on a item that is not a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
if ( $yq->is_defined('vars.address-groups') ){
print "defined...\n:";
}
is_hash
Checks if the specified variable in a hash.
Will die if called on a item that is not a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
if ( $yq->is_hash('vars.address-groups') ){
print "hash...\n:";
}
is_hash_clear
Checks if a hash is clear or not.
Will die if called on a item that is not a hash.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
if ( ! $yq->is_hash_clear(var=>'vars') ){
print "not clear...\n:";
}
set_array
Creates an array and sets it to the values.
If the array is already defined, it will clear it and set the values to those specified.
Will die if called on a item that is not a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
- vals :: Array of values to set the array to.
$yq->set_array(var=>'rule-files',vals=>\@vals);
set_hash
Creates an hash and sets it to the values.
If the hash is already defined, it will clear it and set the values to those specified.
Will die if called on a item that is not a array.
- var :: Variable to check. If not matching /^\./,
a period will be prepended.
- hash :: A hash to use for generating the hash to be
added. Any undef value will be set to null.
$yq->set_array(var=>'vars',hash=>{a=>33,bar=>undef});
AUTHOR
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
BUGS
Please report any bugs or feature requests to bug-yaml-yq-helper at rt.cpan.org
, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=YAML-yq-Helper. 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 YAML::yq::Helper
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2022 by Zane C. Bowers-Hadley.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)