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

NAME

Config::Apple::Profile::Payload::Types::Validation - Validation of common payload types.

DESCRIPTION

Apple Configuration Profiles contain one or more payloads. Each payload contains a dictionary, which can be thought of like a Perl hash. Within a payload's dictionary, each key's value is restricted to a specific type. One key might require a number; a different key might require a string, or some binary data.

Provided in this module are a number of Readonly scalars that will be used (instead of strings) to identify the data types for configuration profile keys. The scalars are all OK for import into your local namespace, or you can simply import :all to get all of them at once.

FUNCTIONS

validate

    my $validated_value = validate($type, $value);

Validates $value as a valid $type. If valid, returns the de-tainted $value. If invalid, returns undef.

$type is one of the values from Config::Apple::Profile::Payload::Types. $value is the value to be validated.

IF $type is not valid, or $value is undef, then undef is returned.

validate_string

    my $valid_string = validate_string($value);

Returns a de-tained $value if it is a defined, non-empty scalar, and can be encoded as UTF-8 by Encode.

validate_number

    my $number = validate_number($value)

Returns a de-tained $value if it is an integer. A leading + is OK. Any other input returns undef.

validate_real

    my $number = validate_real($value)

Returns a de-tainted $value if it is an integer or a floating-point number. A loading + is OK. An exponent, positive or negative, is also OK. Any other input returns undef.

validate_boolean

    my $boolean = validate_boolean($value);

If $value can be evaluated as true or false, returns a 1 or a 0, respectively. Will return undef if a reference is passed.

validate_date

    my $date_object = validate_date($value);

If $value is already a finite DateTime object, it is returned immediately. If $value is a string, and can be parsed by DateTime::Format::Flexible, the resulting DateTime object will be returned.

Unparseable strings, infinite DateTime objects, and any other input will return undef.

validate_data

    # With a file handle
    my $handle = validate_data($handle);

    # With binary data
    my $handle = validate_data($bytes);

If passed an already-open file handle, or any object that represents a file (such as an IO:: object), the handle (without the object tie) will be returned.

If passed a scalar, it will be checked to make sure it is not empty, and that is not a utf8 string. The contents of the string will be placed into an anonymous in-memory file, and the filehandle will be returned.

validate_identifier

    my $valid_identifier = validate_identifier($value);

Returns a de-tained $value if it is a single-line string that matches the format of a domain name (without spaces). Otherwise, returns undef.

validate_uuid

    my $guid = validate_uuid($value);

If $value is a Data::GUID object, it is returned immediately. If $value is a Data::UUID object, an equivalent Data::GUID object is returned. Objects of other types return undef.

If $value is a string that can be parsed as a GUID, an equivalent Data::GUID object is returned. Otherwise, undef is returned.

validate_class

    my $object = validate_class($value)

If $value is an object, and is also an instance of Config::Apple::Profile::Payload::Common (or something that is a subclass), then $value is returned. Otherwise, undef is returned.

ACKNOWLEDGEMENTS

Refer to Config::Apple::Profile for acknowledgements.

AUTHOR

A. Karl Kornel, <karl at kornel.us>

COPYRIGHT AND LICENSE

Copyright © 2014 A. Karl Kornel.

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.