NAME

Compiled::Params::OO - compiled params object oriented.

VERSION

Version 0.04

SYNOPSIS

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;

EXPORT

cpo

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]
);

Examples

Optional params

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)]
);

AUTHOR

lnation, <email at lnation.org>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Compiled::Params::OO

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2020 by lnation.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)