Poz - A simple, composable, and extensible data validation library for Perl.
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"}]
Poz is a simple, composable, and extensible data validation library for Perl. It is inspired heavily from Zod https://zod.dev/ in TypeScript.
use Poz qw/z/;
my $builder = z;
Returns a new instance of Poz::Builder.
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.
my $schema = z->string;
Creates a new string schema object.
my $schema = z->number;
Creates a new number schema object.
my $schema = z->date;
Creates a new date schema object.
my $schema = z->object($schema);
Creates a new object schema object.
my $schema = z->array($schema);
Creates a new array schema object.
my $schema = z->enum(@values);
Creates a new enum schema object.
Zod Poz::Builder Poz::Types Poz::Types::string Poz::Types::number Poz::Types::object Poz::Types::array Poz::Types::enum
If you want to contribute to Poz, you can follow the steps below:
-
-
Prepare: Install cpanm and Minilla
$ curl -L https://cpanmin.us | perl - --sudo App::cpanminus $ cpanm Minilla
-
-
- Fork: Please fork the repository on GitHub.
The Repository on GitHub: https://github.com/ytnobody/p5-Poz
-
-
Clone: Clone the repository.
$ git clone
-
-
-
Branch: Create a feature branch from the main branch.
$ git checkout -b feature-branch main
-
-
-
Code: Write your code and tests, then build.
$ minil build
-
-
-
Test: Run the tests.
$ minil test
-
-
-
Commit: Commit your changes.
$ git commit -am "Add some feature"
-
-
-
Push: Push to your branch.
$ git push origin feature-branch
-
-
- Pull Request: Create a new Pull Request on GitHub.
Copyright (C) ytnobody.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
ytnobody ytnobody@gmail.com