Config::Apple::Profile::Payload::Types::Validation - Validation of common payload types.
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.
:all
my $validated_value = validate($type, $value);
Validates $value as a valid $type. If valid, returns the de-tainted $value. If invalid, returns undef.
$value
$type
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.
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.
my $number = validate_number($value)
Returns a de-tained $value if it is an integer. A leading + is OK. Any other input returns undef.
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.
+
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.
1
0
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.
DateTime
Unparseable strings, infinite DateTime objects, and any other input will return undef.
# 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.
IO::
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.
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.
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.
Data::GUID
Data::UUID
If $value is a string that can be parsed as a GUID, an equivalent Data::GUID object is returned. Otherwise, undef is returned.
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.
Config::Apple::Profile::Payload::Common
Refer to Config::Apple::Profile for acknowledgements.
A. Karl Kornel, <karl at kornel.us>
<karl at kornel.us>
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.
To install Config::Apple::Profile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Apple::Profile
CPAN shell
perl -MCPAN -e shell install Config::Apple::Profile
For more information on module installation, please visit the detailed CPAN module installation guide.