NAME
Poz::Types::string - A module for validating and transforming strings.
SYNOPSIS
use Poz qw/z/;
my $string = z->string;
# Validate a string
$string->rule($value);
# Coerce a value to a string
my $coerced_value = $string->coerce($value);
# Add validation rules
$string->max($max_length, \%opts);
$string->min($min_length, \%opts);
$string->email(\%opts);
$string->url(\%opts);
$string->emoji(\%opts);
$string->uuid(\%opts);
$string->nanoid(\%opts);
$string->cuid(\%opts);
$string->cuid2(\%opts);
$string->ulid(\%opts);
$string->regex($regex, \%opts);
$string->includes($substring, \%opts);
$string->startsWith($prefix, \%opts);
$string->endsWith($suffix, \%opts);
$string->ip(\%opts);
$string->date(\%opts);
$string->time(\%opts);
$string->datetime(\%opts);
$string->duration(\%opts);
$string->base64(\%opts);
# Add transformations
$string->trim;
$string->toLowerCase;
$string->toUpperCase;
DESCRIPTION
This module provides a set of methods for validating and transforming strings. It includes rules for checking string length, format, and content, as well as transformations for modifying the string.
METHODS
- rule
-
$string->rule($value); Validates that the value is a defined, non-reference string.
- coerce
-
my $coerced_value = $string->coerce($value); Coerces the value to a string.
- max
-
$string->max($max_length, \%opts); Adds a rule to ensure the string does not exceed the specified maximum length.
- min
-
$string->min($min_length, \%opts); Adds a rule to ensure the string is at least the specified minimum length.
-
$string->email(\%opts); Adds a rule to validate that the string is a valid email address.
- url
-
$string->url(\%opts); Adds a rule to validate that the string is a valid URL.
- emoji
-
$string->emoji(\%opts); Adds a rule to validate that the string contains an emoji.
- uuid
-
$string->uuid(\%opts); Adds a rule to validate that the string is a valid UUID.
- nanoid
-
$string->nanoid(\%opts); Adds a rule to validate that the string is a valid NanoID.
- cuid
-
$string->cuid(\%opts); Adds a rule to validate that the string is a valid CUID.
- cuid2
-
$string->cuid2(\%opts); Adds a rule to validate that the string is a valid CUID2.
- ulid
-
$string->ulid(\%opts); Adds a rule to validate that the string is a valid ULID.
- regex
-
$string->regex($regex, \%opts); Adds a rule to validate that the string matches the specified regular expression.
- includes
-
$string->includes($substring, \%opts); Adds a rule to validate that the string includes the specified substring.
- startsWith
-
$string->startsWith($prefix, \%opts); Adds a rule to validate that the string starts with the specified prefix.
- endsWith
-
$string->endsWith($suffix, \%opts); Adds a rule to validate that the string ends with the specified suffix.
- ip
-
$string->ip(\%opts); Adds a rule to validate that the string is a valid IP address (IPv4 or IPv6).
- trim
-
$string->trim; Adds a transformation to trim whitespace from the string.
- toLowerCase
-
$string->toLowerCase; Adds a transformation to convert the string to lowercase.
- toUpperCase
-
$string->toUpperCase; Adds a transformation to convert the string to uppercase.
- date
-
$string->date(\%opts); Adds a rule to validate that the string is a valid date (YYYY-MM-DD).
- time
-
$string->time(\%opts); Adds a rule to validate that the string is a valid time (HH:MM:SS).
- datetime
-
$string->datetime(\%opts); Adds a rule to validate that the string is a valid ISO8601 datetime.
- duration
-
$string->duration(\%opts); Adds a rule to validate that the string is a valid ISO8601 duration.
- base64
-
$string->base64(\%opts); Adds a rule to validate that the string is a valid base64 encoded string.
LICENSE
Copyright (C) ytnobody.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
ytnobody <ytnobody@gmail.com>