NAME

Class::Enumeration - Abstract parent class of enum classes

SYNOPSIS

use strict;
use warnings;

package TurnstileState;

use parent 'Class::Enumeration';

# Declaration of enum objects
our @Values = do {
  my $ordinal = 0;
  map { __PACKAGE__->_new( $ordinal++, $_ ) } qw( Locked Unlocked )
};

1

CAVEAT

This class is abstract and should not be used directly. You should use the Class::Enumeration::Builder module instead.

DESCRIPTION

An enum class is a fixed list of enum objects. Each enum object is immutable and has a name and an ordinal attribute.

Each enum class has a name() getter method (an object method), that returns the name of the enum object, exactly as declared.

Each enum class has an ordinal() getter method (an object method), that returns the ordinal of the enum object (its position in its declaration, where the initial object is assigned an ordinal of zero).

Each enum class has a names() class method, that returns a list of names of the enum objects in the order they are declared.

Each enum class has a values() class method, that returns the fixed list of the enum objects in the order they are declared.

Each enum class has a value_of( $name ) factory method (a class method), that returns the enum object with the specified name.

Each enum class inherits stringification '""' from its Class::Enumeration parent class. By default the string representation of an enum object returns its name. If you want to override this behaviour, you have to provide an to_string() implementation in your enum class.

The parent class Class::Enumeration overloads the operators '==', and '!=' too. Magic auto-generation of overload implementations for other operators is turned off. An enum class can add its own overload implementations.

SEE ALSO

AUTHOR

Sven Willenbuecher <sven.willenbuecher@gmx.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2025 by Sven Willenbuecher.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.