Venus::Enum - Enum Class
Enum Class for Perl 5
package main; use Venus::Enum; my $enum = Venus::Enum->new(['n', 's', 'e', 'w']); # my $north = $enum->get('n'); # "n"
This package provides an interface for working with enumerations.
This package inherits behaviors from:
Venus::Sealed
This package provides the following methods:
get(string $name) (Venus::Enum)
The get method returns a new object representing the enum member specified.
Since 3.55
3.55
# given: synopsis package main; my $get = $enum->get('n'); # bless(..., "Venus::Enum") # $get->value # "n"
# given: synopsis package main; my $get = $enum->get('s'); # bless(..., "Venus::Enum") # $get->value # "s"
has(string $name) (boolean)
The has method returns true if the member name or value exists in the enum, otherwise returns false.
# given: synopsis package main; my $has = $enum->has('n'); # true
# given: synopsis package main; my $has = $enum->has('z'); # false
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.
# given: synopsis package main; my $is = $enum->get('n')->is('n'); # true
# given: synopsis package main; my $is = $enum->get('s')->is('n'); # false
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.
# given: synopsis package main; my $items = $enum->items; # [["e", "e"], ["n", "n"], ["s", "s"], ["w", "w"]]
# given: synopsis package main; my @items = $enum->items; # (["e", "e"], ["n", "n"], ["s", "s"], ["w", "w"])
list() (within[arrayref, string])
The list method returns an arrayref containing the values for the enumerations. Returns a list in list context.
# given: synopsis package main; my $list = $enum->list; # ["e", "n", "s", "w"]
# given: synopsis package main; my @list = $enum->list; # ("e", "n", "s", "w")
name() (maybe[string])
The name method returns the name of the member selected or returns undefined.
# given: synopsis package main; my $name = $enum->name; # undef
# given: synopsis package main; my $n = $enum->get('n'); my $name = $n->name; # "n"
names() (within[arrayref, string])
The names method returns an arrayref containing the names for the enumerations. Returns a list in list context.
# given: synopsis package main; my $names = $enum->names; # ["e", "n", "s", "w"]
# given: synopsis package main; my @names = $enum->names; # ("e", "n", "s", "w")
value() (maybe[string])
The value method returns the value of the member selected or returns undefined.
# given: synopsis package main; my $value = $enum->value; # undef
# given: synopsis package main; my $n = $enum->get('n'); my $value = $n->value; # "n"
values() (within[arrayref, string])
The values method returns an arrayref containing the values for the enumerations. Returns a list in list context.
# given: synopsis package main; my $values = $enum->values; # ["e", "n", "s", "w"]
# given: synopsis package main; my @values = $enum->values; # ("e", "n", "s", "w")
This package overloads the following operators:
("")
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"
(eq)
This package overloads the eq operator.
eq
# given: synopsis; my $result = $enum eq ""; # 1
# given: synopsis; my $s = $enum->get("s"); my $result = $s eq "s"; # 1
(ne)
This package overloads the ne operator.
ne
# given: synopsis; my $result = $enum ne ""; # 0
# given: synopsis; my $n = $enum->get("n"); my $result = $n ne ""; # 1
(qr)
This package overloads the qr operator.
qr
# given: synopsis; my $n = $enum->get('n'); my $test = 'north' =~ qr/$n/; # 1
Awncorp, awncorp@cpan.org
awncorp@cpan.org
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.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.