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:
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
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
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
name
name() (maybe[string])
The name method returns the name of the member selected or returns undefined.
Since 3.55
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
value
value() (maybe[string])
The value method returns the value of the member selected or returns undefined.
Since 3.55
- 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
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) 2022, 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.