NAME

Venus::Enum - Enum Class

ABSTRACT

Enum Class for Perl 5

SYNOPSIS

package main;

use Venus::Enum;

my $enum = Venus::Enum->new(['n', 's', 'e', 'w']);

# my $north = $enum->get('n');

# "n"

DESCRIPTION

This package provides an interface for working with enumerations.

INHERITS

This package inherits behaviors from:

Venus::Sealed

METHODS

This package provides the following methods:

get

get(string $name) (Venus::Enum)

The get method returns a new object representing the enum member specified.

Since 3.55

get example 1
# given: synopsis

package main;

my $get = $enum->get('n');

# bless(..., "Venus::Enum")

# $get->value

# "n"
get example 2
# given: synopsis

package main;

my $get = $enum->get('s');

# bless(..., "Venus::Enum")

# $get->value

# "s"

has

has(string $name) (boolean)

The has method returns true if the member name or value exists in the enum, otherwise returns false.

Since 3.55

has example 1
# given: synopsis

package main;

my $has = $enum->has('n');

# true
has example 2
# given: synopsis

package main;

my $has = $enum->has('z');

# false

is

is(string $name) (boolean)

The is method returns true if the member name or value specified matches the member selected in the enum, otherwise returns false.

Since 3.55

is example 1
# given: synopsis

package main;

my $is = $enum->get('n')->is('n');

# true
is example 2
# given: synopsis

package main;

my $is = $enum->get('s')->is('n');

# false

items

items() (tuple[string, string])

The items method returns an arrayref of arrayrefs containing the name and value pairs for the enumerations. Returns a list in list context.

Since 3.55

items example 1
# given: synopsis

package main;

my $items = $enum->items;

# [["e", "e"], ["n", "n"], ["s", "s"], ["w", "w"]]
items example 2
# given: synopsis

package main;

my @items = $enum->items;

# (["e", "e"], ["n", "n"], ["s", "s"], ["w", "w"])

list

list() (within[arrayref, string])

The list method returns an arrayref containing the values for the enumerations. Returns a list in list context.

Since 3.55

list example 1
# given: synopsis

package main;

my $list = $enum->list;

# ["e", "n", "s", "w"]
list example 2
# given: synopsis

package main;

my @list = $enum->list;

# ("e", "n", "s", "w")

name

name() (maybe[string])

The name method returns the name of the member selected or returns undefined.

Since 3.55

name example 1
# given: synopsis

package main;

my $name = $enum->name;

# undef
name example 2
# given: synopsis

package main;

my $n = $enum->get('n');

my $name = $n->name;

# "n"

names

names() (within[arrayref, string])

The names method returns an arrayref containing the names for the enumerations. Returns a list in list context.

Since 3.55

names example 1
# given: synopsis

package main;

my $names = $enum->names;

# ["e", "n", "s", "w"]
names example 2
# given: synopsis

package main;

my @names = $enum->names;

# ("e", "n", "s", "w")

value

value() (maybe[string])

The value method returns the value of the member selected or returns undefined.

Since 3.55

value example 1
# given: synopsis

package main;

my $value = $enum->value;

# undef
value example 2
# given: synopsis

package main;

my $n = $enum->get('n');

my $value = $n->value;

# "n"

values

values() (within[arrayref, string])

The values method returns an arrayref containing the values for the enumerations. Returns a list in list context.

Since 3.55

values example 1
# given: synopsis

package main;

my $values = $enum->values;

# ["e", "n", "s", "w"]
values example 2
# given: synopsis

package main;

my @values = $enum->values;

# ("e", "n", "s", "w")

OPERATORS

This package overloads the following operators:

operation: ("")

This package overloads the "" operator.

example 1

# given: synopsis;

my $result = "$enum";

# ""

example 2

# given: synopsis;

my $n = $enum->get("n");

my $result = "$n";

# "n"
operation: (eq)

This package overloads the eq operator.

example 1

# given: synopsis;

my $result = $enum eq "";

# 1

example 2

# given: synopsis;

my $s = $enum->get("s");

my $result = $s eq "s";

# 1
operation: (ne)

This package overloads the ne operator.

example 1

# given: synopsis;

my $result = $enum ne "";

# 0

example 2

# given: synopsis;

my $n = $enum->get("n");

my $result = $n ne "";

# 1
operation: (qr)

This package overloads the qr operator.

example 1

# given: synopsis;

my $n = $enum->get('n');

my $test = 'north' =~ qr/$n/;

# 1

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2000, Awncorp, awncorp@cpan.org.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.