NAME

Aion :: Enum - Listing in the style of OOP, when each renewal is an object

VERSION

0.0.1

SYNOPSIS

package StatusEnum {
    use Aion::Enum;

    case 'Active';
    case 'Passive';
}

&StatusEnum::Active->does('Aion::Enum') # => 1

StatusEnum->Active->name  # => Active
StatusEnum->Passive->name # => Passive

[ StatusEnum->names ] # --> [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 ($valisa, [$staisa])

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 << 'END';
package StringEnum {
    use Aion::Enum;

    issa Int;

    case Active => "active";
}
END
$@ # ~> Active value must have the type Int. The it is 'active'

eval << 'END';
package StringEnum {
    use Aion::Enum;

    issa Str, Int;

    case Active => "active", "passive";
}
END
$@ # ~> Active stash must have the type Int. The it is 'passive'

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 pseudonym

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.