NAME
Aion :: Enum - Listing in the style of OOP, when each renewal is an object
VERSION
0.0.3
SYNOPSIS
File lib/StatusEnum.pm:
package StatusEnum;
use Aion::Enum;
# Active status
case active => 1, 'Active';
# Passive status
case passive => 2, 'Passive';
1;
use StatusEnum;
&StatusEnum::active->does('Aion::Enum') # => 1
StatusEnum->active->name # => active
StatusEnum->passive->value # => 2
StatusEnum->active->alias # => Active status
StatusEnum->passive->stash # => Passive
[ StatusEnum->cases ] # --> [StatusEnum->active, StatusEnum->passive]
[ StatusEnum->names ] # --> [qw/active passive/]
[ StatusEnum->values ] # --> [qw/1 2/]
[ StatusEnum->aliases ] # --> ['Active status', 'Passive status']
[ StatusEnum->stashes ] # --> [qw/Active Passive/]
DESCRIPTION
Aion :: Enum allows you to create transfers-objects. These transfers may contain additional methods and properties. You can add roles to them (using with) or use them as a role.
An important feature is the preservation of the procedure for listing.
Aion::Enum is similar to php8 enums, but has the additional properties alias and stash.
SUBROUTINES
case ($name, [$value, [$stash]])
Creates a listing: his constant.
package OrderEnum {
use Aion::Enum;
case 'first';
case second => 2;
case other => 3, {data => 123};
}
&OrderEnum::first->name # => first
&OrderEnum::first->value # -> undef
&OrderEnum::first->stash # -> undef
&OrderEnum::second->name # => second
&OrderEnum::second->value # -> 2
&OrderEnum::second->stash # -> undef
&OrderEnum::other->name # => other
&OrderEnum::other->value # -> 3
&OrderEnum::other->stash # --> {data => 123}
issa ($nameisa, [$valueisa], [$stashisa], [$aliasisa])
Indicates the type (ISA) of meanings and additions.
Its name is a reference to the goddess Isse from the story “Under the Moles of Mars” Burrose.
eval {
package StringEnum;
use Aion::Enum;
issa Str => Int => Undef => Undef;
case active => "Active";
};
$@ # ~> active value must have the type Int. The it is 'Active'
eval {
package StringEnum;
use Aion::Enum;
issa Str => Str => Int;
case active => "Active", "Passive";
};
$@ # ~> active stash must have the type Int. The it is 'Passive'
File lib/StringEnum.pm:
package StringEnum;
use Aion::Enum;
issa Str => Undef => Undef => StrMatch[qr/^[A-Z]/];
# pushkin
case active => ;
1;
require StringEnum # @-> active alias must have the type StrMatch[qr/^[A-Z]/]. The it is 'pushkin'!
CLASS METHODS
cases ($cls)
List of transfers.
[ OrderEnum->cases ] # --> [OrderEnum->first, OrderEnum->second, OrderEnum->other]
names ($cls)
Names of transfers.
[ OrderEnum->names ] # --> [qw/first second other/]
values ($cls)
The values of the transfers.
[ OrderEnum->values ] # --> [undef, 2, 3]
stashes ($cls)
Additions of transfers.
[ OrderEnum->stashes ] # --> [undef, undef, {data => 123}]
aliases ($cls)
Pseudonyms of transfers.
LIB/authorenum.pm file:
package AuthorEnum;
use Aion::Enum;
# Pushkin Aleksandr Sergeevich
case pushkin =>;
# Yacheykin Uriy
case yacheykin =>;
case nouname =>;
1;
require AuthorEnum;
[ AuthorEnum->aliases ] # --> ['Pushkin Aleksandr Sergeevich', 'Yacheykin Uriy', undef]
fromName ($cls, $name)
Get Case by name with exceptions.
OrderEnum->fromName('first') # -> OrderEnum->first
eval { OrderEnum->fromName('not_exists') }; $@ # ~> Did not case with name `not_exists`!
tryFromName ($cls, $name)
Get Case by name.
OrderEnum->tryFromName('first') # -> OrderEnum->first
OrderEnum->tryFromName('not_exists') # -> undef
fromValue ($cls, $value)
Get Case by value with exceptions.
OrderEnum->fromValue(undef) # -> OrderEnum->first
eval { OrderEnum->fromValue('not-exists') }; $@ # ~> Did not case with value `not-exists`!
tryFromValue ($cls, $value)
Get Case by value.
OrderEnum->tryFromValue(undef) # -> OrderEnum->first
OrderEnum->tryFromValue('not-exists') # -> undef
fromStash ($cls, $stash)
Get CASE on addition with exceptions.
OrderEnum->fromStash(undef) # -> OrderEnum->first
eval { OrderEnum->fromStash('not-exists') }; $@ # ~> Did not case with stash `not-exists`!
tryFromStash ($cls, $value)
Get Case for addition.
OrderEnum->tryFromStash({data => 123}) # -> OrderEnum->other
OrderEnum->tryFromStash('not-exists') # -> undef
fromAlias ($cls, $alias)
Get Case by pseudonym with exceptions.
AuthorEnum->fromAlias('Yacheykin Uriy') # -> AuthorEnum->yacheykin
eval { AuthorEnum->fromAlias('not-exists') }; $@ # ~> Did not case with alias `not-exists`!
tryFromAlias ($cls, $alias)
Get case by alias.
AuthorEnum->tryFromAlias('Yacheykin Uriy') # -> AuthorEnum->yacheykin
AuthorEnum->tryFromAlias('not-exists') # -> undef
FEATURES
name
Property only for reading.
package NameEnum {
use Aion::Enum;
case piter =>;
}
NameEnum->piter->name # => piter
value
Property only for reading.
package ValueEnum {
use Aion::Enum;
case piter => 'Pan';
}
ValueEnum->piter->value # => Pan
stash
Property only for reading.
package StashEnum {
use Aion::Enum;
case piter => 'Pan', 123;
}
StashEnum->piter->stash # => 123
alias
Property only for reading.
Aliases work only if the package is in the module, as they read the comment before the case due to reflection.
LIB/aliasenum.pm file:
package AliasEnum;
use Aion::Enum;
# Piter Pan
case piter => ;
1;
require AliasEnum;
AliasEnum->piter->alias # => Piter Pan
SEE ALSO
- 1. enum.
- 2. Class::Enum.
AUTHOR
Yaroslav O. Kosmina Lmailto:dart@cpan.org
LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
⚖ * gplv3 *
COPYRIGHT
The Aion :: Enum Module is Copyright © 2025 Yaroslav O. Kosmina. Rusland. All Rights Reserved.