Poz

A simple, composable, and extensible data validation library for Perl.


License
Artistic-1.0-Perl

Documentation

Actions Status

NAME

Poz - A simple, composable, and extensible data validation library for Perl.

SYNOPSIS

use Poz qw/z/;
use Data::UUID;
use Time::Piece;
my $bookSchema = z->object({
    id         => z->string->uuid->default(sub { Data::UUID->new->create_str }),   
    title      => z->string,
    author     => z->string->default("Anonymous"),
    published  => z->date,
    created_at => z->date->default(sub { Time::Piece::localtime()->strftime('%Y-%m-%d') }),
    updated_at => z->date->default(sub { Time::Piece::localtime()->strftime('%Y-%m-%d') }),
})->as("My::Book");

my $book = $bookSchema->parse({
    title     => "Spidering Hacks",
    author    => "Kevin Hemenway",
    published => "2003-10-01",
}) or die "Invalid book data";
$book->isa("My::Book"); # true

my ($otherBook, $err) = $bookSchema->safe_parse({
    title => "Eric Sink on the Business of Software",
    author => "Eric Sink",
    published => "2006-0i-01",
});
$otherBook; # undef
$err; # [{key => "", error => "Not a date"}]

DESCRIPTION

Poz is a simple, composable, and extensible data validation library for Perl. It is inspired heavily from Zod https://zod.dev/ in TypeScript.

EXPORTS

z

use Poz qw/z/;
my $builder = z;

Returns a new instance of Poz::Builder.

METHODS

z->object($schema)

my $schema = z->object({
    id         => z->string->uuid->default(sub { Data::UUID->new->create_str }),   
    title      => z->string,
    author     => z->string->default("Anonymous"),
    published  => z->date,
    created_at => z->date->default(sub { Time::Piece::localtime()->strftime('%Y-%m-%d') }),
    updated_at => z->date->default(sub { Time::Piece::localtime()->strftime('%Y-%m-%d') }),
})->as("My::Book");

Creates a new schema object.

z->string

my $schema = z->string;

Creates a new string schema object.

z->number

my $schema = z->number;

Creates a new number schema object.

z->date

my $schema = z->date;

Creates a new date schema object.

z->object

my $schema = z->object($schema);

Creates a new object schema object.

z->array

my $schema = z->array($schema);

Creates a new array schema object.

z->enum

my $schema = z->enum(@values);

Creates a new enum schema object.

SEE ALSO

Zod Poz::Builder Poz::Types Poz::Types::string Poz::Types::number Poz::Types::object Poz::Types::array Poz::Types::enum

HOW TO CONTRIBUTE

If you want to contribute to Poz, you can follow the steps below:

    1. Prepare: Install cpanm and Minilla

      $ curl -L https://cpanmin.us | perl - --sudo App::cpanminus $ cpanm Minilla

    1. Fork: Please fork the repository on GitHub.

    The Repository on GitHub: https://github.com/ytnobody/p5-Poz

    1. Clone: Clone the repository.

      $ git clone

    1. Branch: Create a feature branch from the main branch.

      $ git checkout -b feature-branch main

    1. Code: Write your code and tests, then build.

      $ minil build

    1. Test: Run the tests.

      $ minil test

    1. Commit: Commit your changes.

      $ git commit -am "Add some feature"

    1. Push: Push to your branch.

      $ git push origin feature-branch

    1. Pull Request: Create a new Pull Request on GitHub.

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