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

NAME

WGmeta::Parser::Conf - Parser for Wireguard configurations

SYNOPSIS

    use Wireguard::WGmeta::Parser::Conf;
    use Wireguard::WGmeta::Util;

    # Parse a wireguard configuration file
    my $config_contents = read_file('/path/to/config.conf', 'interface_name');

    # Define callbacks
    my $on_every_value_callback = sub($attribute, $value, $is_wg_meta){
        # do you magic
        return $attribute, $value;
    };
    my $on_every_section_callback = sub($identifier, $section_type, $is_disabled){
        # do you magic
        return $identifier;
    };

    # And finally parse the configuration
    my $parsed_config = parse_raw_wg_config($config_contents, $on_every_value_callback, $on_every_section_callback);

DESCRIPTION

Parser for Wireguard .conf files with support for custom attributes. A possible implementation is present in Wireguard::WGmeta::Parser::Middleware.

METHODS

parse_raw_wg_config($file_content, $on_every_value, $on_new_section [, $skip, $wg_meta_prefix, $wg_disabled_prefix])

Parses a Wireguard configuration

  • $file_content Content of Wireguard configuration. Warning, if have to ensure that its a valid file!

  • $on_every_value A reference to a callback function, fired at every key/value pair. Expected signature:

        my $on_every_value_callback = sub($attribute, $value, $is_wg_meta){
            # do you magic
            return $attribute, $value;
        };
  • $on_new_section Callback for every section. Expected signature:

        my $on_every_section_callback = sub($identifier, $section_type, $is_disabled){
            # do you magic
            return $identifier;
        };
  • [$skip = 0] When you want to skip some lines at the beginning

  • [$wg_meta_prefix = '#+'] wg-meta prefix. Must start with '#' or ';'

  • [$disabled_prefix = '#-'] disabled prefix. Must start with '#' or ';'

Returns

A reference to a hash similar as described in Wireguard::WGmeta::Parser::Middleware.