NAME

WebService::OPNsense::Normalize - Normalization and validation utilities

VERSION

version 0.001

SYNOPSIS

use WebService::OPNsense::Normalize qw( normalize_ip optional_segment validate_uuid );

# IP normalization
use NetAddr::IP;
my $cidr = normalize_ip(NetAddr::IP->new('192.0.2.0/24'));
# $cidr eq '192.0.2.0/24'

# UUID validation
validate_uuid('550e8400-e29b-41d4-a716-446655440000');
validate_uuid('invalid-uuid');  # croaks

DESCRIPTION

Provides shared normalization and validation functions used across the OPNsense API controllers.

NAME

WebService::OPNsense::Normalize - Normalization and validation utilities

FUNCTIONS

normalize_ip

my $cidr = normalize_ip($ip_object);

Accepts a blessed IP object and returns the canonical CIDR string.

Supported classes:

Net::CIDR::Lite -- via ->list (croaks if more than one range)
Net::Netmask -- via ->desc
NetAddr::IP -- via ->cidr

validate_uuid

validate_uuid($uuid);

Validates that $uuid is a well-formed UUID string (any version). Croaks with Carp if the UUID is undefined or invalid.

optional_segment

my $segment = optional_segment($value);

Returns /$value if $value is defined, or an empty string otherwise. Used to build API paths with optional trailing segments.

my $path = "/api/endpoint/toggle/$uuid" . optional_segment($enabled);
# $path eq "/api/endpoint/toggle/$uuid" if $enabled is undef
# $path eq "/api/endpoint/toggle/$uuid/1" if $enabled is 1

AUTHOR

Dean Hamstead <dean@fragfest.com.au>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2026 by Dean Hamstead.

This is free software, licensed under:

The MIT (X11) License