Hades
view release on metacpan or search on metacpan
lib/Hades/Macro/Dolos.pm view on Meta::CPAN
package Hades::Macro::Dolos;
use strict;
use warnings;
use base qw/Hades::Macro/;
our $VERSION = 0.27;
sub new {
my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
my $self = $cls->SUPER::new(%args);
my %accessors = (
macro => {
default => [
qw/
autoload_cb
caller
clear_unless_keys
call_sub
call_sub_my
delete
die_unless_keys
else
elsif
export
for
foreach
for_keys
for_key_exists_and_return
grep
grep_map
if
map
map_grep
maybe
merge_hash_refs
require
unless
while
/
],
},
);
for my $accessor ( keys %accessors ) {
my $param
= defined $args{$accessor}
? $args{$accessor}
: $accessors{$accessor}->{default};
my $value
= $self->$accessor( $accessors{$accessor}->{builder}
? $accessors{$accessor}->{builder}->( $self, $param )
: $param );
unless ( !$accessors{$accessor}->{required} || defined $value ) {
die "$accessor accessor is required";
}
}
return $self;
}
sub macro {
my ( $self, $value ) = @_;
if ( defined $value ) {
if ( ( ref($value) || "" ) ne "ARRAY" ) {
die qq{ArrayRef: invalid value $value for accessor macro};
}
$self->{macro} = $value;
lib/Hades/Macro/Dolos.pm view on Meta::CPAN
return qq|$base = { $merge };|;
}
sub require {
my ( $self, $mg, $variable ) = @_;
if ( ( ref($mg) || "" ) =~ m/^(|HASH|ARRAY|SCALAR|CODE|GLOB)$/ ) {
$mg = defined $mg ? $mg : 'undef';
die qq{Object: invalid value $mg for variable \$mg in method require};
}
if ( !defined($variable) || ref $variable ) {
$variable = defined $variable ? $variable : 'undef';
die
qq{Str: invalid value $variable for variable \$variable in method require};
}
return qq|eval "require ${variable}";|;
}
sub unless {
my ( $self, $mg, $condition, @code ) = @_;
if ( ( ref($mg) || "" ) =~ m/^(|HASH|ARRAY|SCALAR|CODE|GLOB)$/ ) {
$mg = defined $mg ? $mg : 'undef';
die qq{Object: invalid value $mg for variable \$mg in method unless};
}
if ( !defined($condition) || ref $condition ) {
$condition = defined $condition ? $condition : 'undef';
die
qq{Str: invalid value $condition for variable \$condition in method unless};
}
my $c = join "\n", @code;
return qq|unless ($condition) { $c }|;
}
sub while {
my ( $self, $mg, $condition, @code ) = @_;
if ( ( ref($mg) || "" ) =~ m/^(|HASH|ARRAY|SCALAR|CODE|GLOB)$/ ) {
$mg = defined $mg ? $mg : 'undef';
die qq{Object: invalid value $mg for variable \$mg in method while};
}
if ( !defined($condition) || ref $condition ) {
$condition = defined $condition ? $condition : 'undef';
die
qq{Str: invalid value $condition for variable \$condition in method while};
}
my $c = join "\n", @code;
return qq|while ($condition) { $c }|;
}
1;
__END__
=head1 NAME
Hades::Macro::Dolos - Hades macro helpers for Dolos
=head1 VERSION
Version 0.27
=cut
=head1 SYNOPSIS
Quick summary of what the module does:
Hades->run({
eval => q|
macro {
Dolos
}
Kosmos {
psyche $dolos :t(Int) $eros :t(HashRef) $psyche :t(HashRef) {
â¬if($dolos,â¬if($dolos > 10, return $eros;);, â¬elsif($dolos > 5, â¬merge_hash_refs($eros, $psyche););,
â¬else(return $psyche;););
return undef;
}
}
|;
});
=head1 SUBROUTINES/METHODS
=head2 new
Instantiate a new Hades::Macro::Dolos object.
Hades::Macro::Dolos->new
=head2 autoload_cb
call autoload_cb method. Expects param $mg to be a Object, param $cb to be a Str.
$obj->autoload_cb($mg, $cb)
=head2 caller
call caller method. Expects param $mg to be a Object, param $variable to be a Str.
$obj->caller($mg, $variable)
=head2 clear_unless_keys
call clear_unless_keys method. Expects param $mg to be a Object, param $variable to be a Str, param $hash to be a Str.
$obj->clear_unless_keys($mg, $variable, $hash)
=head2 call_sub
call call_sub method. Expects param $mg to be a Object, param $sub to be any value including undef, param @params to be any value including undef.
$obj->call_sub($mg, $sub, @params)
=head2 call_sub_my
call call_sub_my method. Expects param $mg to be a Object, param $my to be a Str, param $sub to be any value including undef, param @params to be any value including undef.
$obj->call_sub_my($mg, $my, $sub, @params)
=head2 delete
call delete method. Expects param $mg to be a Object, param $hash to be a Str, param $key to be a Str, param $variable to be a Optional[Str], param $or to be a Optional[Str], param $list to be a Optional[Bool].
$obj->delete($mg, $hash, $key, $variable, $or, $list)
=head2 die_unless_keys
call die_unless_keys method. Expects param $mg to be a Object, param $hash to be a Str, param $error to be a Str.
$obj->die_unless_keys($mg, $hash, $error)
=head2 else
call else method. Expects param $mg to be a Object, param @code to be any value including undef.
$obj->else($mg, @code)
=head2 elsif
call elsif method. Expects param $mg to be a Object, param $condition to be a Str, param @code to be any value including undef.
$obj->elsif($mg, $condition, @code)
=head2 export
call export method. Expects param $mg to be a Object, param $method to be a Str, param $code to be a Str, param $no_warnings to be a Int, param $caller to be a Str.
$obj->export($mg, $method, $code, $no_warnings, $caller)
lib/Hades/Macro/Dolos.pm view on Meta::CPAN
=head2 map
call map method. Expects param $mg to be a Object, param $condition to be a Str, param @code to be any value including undef.
$obj->map($mg, $condition, @code)
=head2 map_grep
call map_grep method. Expects param $mg to be a Object, param $condition to be a Str, param $grep_code to be a Str, param @map_code to be any value including undef.
$obj->map_grep($mg, $condition, $grep_code, @map_code)
=head2 maybe
call maybe method. Expects param $mg to be a Object, param $key to be a Str, param $variable to be a Str.
$obj->maybe($mg, $key, $variable)
=head2 merge_hash_refs
call merge_hash_refs method. Expects param $mg to be a Object, param @hashes to be any value including undef.
$obj->merge_hash_refs($mg, @hashes)
=head2 require
call require method. Expects param $mg to be a Object, param $variable to be a Str.
$obj->require($mg, $variable)
=head2 unless
call unless method. Expects param $mg to be a Object, param $condition to be a Str, param @code to be any value including undef.
$obj->unless($mg, $condition, @code)
=head2 while
call while method. Expects param $mg to be a Object, param $condition to be a Str, param @code to be any value including undef.
$obj->while($mg, $condition, @code)
=head1 ACCESSORS
=head2 macro
get or set macro.
$obj->macro;
$obj->macro($value);
=head1 AUTHOR
LNATION, C<< <email at lnation.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-hades::macro::dolos at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Macro-Dolos>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Hades::Macro::Dolos
You can also look for information at:
=over 2
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Hades-Macro-Dolos>
=item * Search CPAN
L<https://metacpan.org/release/Hades-Macro-Dolos>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
This software is Copyright (c) 2020 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
=cut
( run in 1.475 second using v1.01-cache-2.11-cpan-5a3173703d6 )