Compiled::Params::OO - compiled params object oriented.
Version 1.00
package Life; use Compiled::Params::OO qw/cpo/; use Types::Standard qw/Str Int/; our $validate; BEGIN { $validate = cpo( time => { testing => Int, me => { type => Str, default => sub { return 'insanity'; } } }, circles => [Str, Int] ); } sub new { return bless {}, $_[0]; } sub time { my $self = shift; my $params = $validate->time->( testing => 16000000, ); return $params->me; } sub circles { my $self = shift; my @params = $validate->circles->('dreaming', 211000000); return \@params; } 1;
This package exports a single sub routine cpo (compiled params object) that is a wrapper around Type::Params compile and compile_named_oo. It accepts a list where the key is the named accessor and the value is the params that will be validated. The value can either be a hash reference to build a Type::Params::compile_name_oo call or an array reference of Type::Tiny Objects that will be passed directly to Type::Params::compile. If passed as a hash reference the value can either be a Type::Tiny object or another hash reference with two keys representing a type and default value.
$validate = cpo( time => { testing => Int, me => { type => Str, default => sub { return 'house of lords'; } } }, circles => [Str, { default => sub { 'lucky buddha' } }, Int] );
The following example demonstrates how to validate optional parameters.
my $validate = cpo( new_pdf => { name => Optional->of(Str), page_size => { type => Optional->of(Enum[qw/A1 A2 A3 A4 A5/]), default => sub { 'A4' }, }, pages => Optional->of(ArrayRef), num => { type => Optional->of(Int), default => sub { 0 } }, page_args => Optional->of(HashRef), plugins => Optional->of(ArrayRef) }, end_pdf => [Str, Optional->of(Int)] );
lnation, <email at lnation.org>
<email at lnation.org>
Please report any bugs or feature requests to bug-compiled-params-oo at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Compiled-Params-OO. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-compiled-params-oo at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Compiled::Params::OO
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Compiled-Params-OO
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Compiled-Params-OO
CPAN Ratings
https://cpanratings.perl.org/d/Compiled-Params-OO
Search CPAN
https://metacpan.org/release/Compiled-Params-OO
This software is Copyright (c) 2021 by lnation.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Compiled::Params::OO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Compiled::Params::OO
CPAN shell
perl -MCPAN -e shell install Compiled::Params::OO
For more information on module installation, please visit the detailed CPAN module installation guide.