The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Hades::Realm::Compiled::Params - The great new Hades::Realm::Compiled::Params!

VERSION

Version 0.03

SYNOPSIS

use Hades::Realm::Compiled::Params;

Hades::Realm::Compiled::Params->run({
	eval => q|
		Kosmos { 
			penthos :d(2) :p :pr :c :t(Int) 
			curae :r :t(Any) 
			geras $nosoi :t(Int) { 
				if ($self->penthos == $nosoi) { 
					return $self->curae; 
				} 
			} 
		}
	|,
	lib => 't/lib'
});

... generates ...

package Kosmos;
use strict;
use warnings;
use Types::Standard qw/Str Optional HashRef Tuple Map Dict ArrayRef Int Any/;
use Compiled::Params::OO;
our $VERSION = 0.01;
our $VALIDATE;

BEGIN {
	$VALIDATE = Compiled::Params::OO::cpo(
		penthos => [ Int, { default => 2 } ],
		curae   => [ Any ],
		geras   => [ Int, { default => 2 } ]
	);
}

sub new {
	my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
	my $self = bless {}, $cls;
	my %accessors
	    = ( curae => { required => 1, }, penthos => { default => 2, }, );
	for my $accessor ( keys %accessors ) {
		my $value
		    = $self->$accessor(
			defined $args{$accessor}
			? $args{$accessor}
			: $accessors{$accessor}->{default} );
		unless ( !$accessors{$accessor}->{required} || defined $value ) {
			die "$accessor accessor is required";
		}
	}
	return $self;
}

sub penthos {
	my ( $self, $value ) = @_;
	my $private_caller = caller();
	if ( $private_caller ne __PACKAGE__ ) {
		die "cannot call private method penthos from $private_caller";
	}
	if ( defined $value ) {
		($value) = $VALIDATE->penthos->($value);
		$self->{penthos} = $value;
	}
	return $self->{penthos};
}

sub clear_penthos {
	my ($self) = @_;
	delete $self->{penthos};
	return $self;
}

sub has_penthos {
	my ($self) = @_;
	return exists $self->{penthos};
}

sub curae {
	my ( $self, $value ) = @_;
	if ( defined $value ) {
		($value) = $VALIDATE->curae->($value);
		$self->{curae} = $value;
	}
	return $self->{curae};
}

sub geras {
	my ( $self, $nosoi ) = ( shift, $VALIDATE->geras->(@_) );
	if ( $self->penthos == $nosoi ) { return $self->curae; }
}

SUBROUTINES/METHODS

new

Instantiate a new Hades::Realm::Compiled::Params object.

Hades::Realm::Compiled::Params->new

push_cpo

call push_cpo method. Expects param $key to be a Str, param $value to be a Str.

$obj->push_cpo($key, $value)

build_accessor

call build_accessor method.

build_sub

call build_sub method. Expects param $mg to be a Ref, param $name to be a Str, param $meta to be a HashRef.

$obj->build_sub($mg, $name, $meta)

build_type

call build_type method. Expects param $name to be a Str, param $type to be a Optional[Str], param $value to be a Optional[Str].

$obj->build_type($name, $type, $value)

after_class

call after_class method. Expects param $mg to be a Object.

$obj->after_class($mg)

ACCESSORS

cpo

get or set cpo.

$obj->cpo;

$obj->cpo($value);

AUTHOR

LNATION, <email at lnation.org>

BUGS

Please report any bugs or feature requests to bug-hadesrealmcompiledparams at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Realm-Compiled-Params. 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 Hades::Realm::Compiled::Params

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)