NAME
Devel::Ladybug::Enum - C style enumerated types in Perl
DESCRIPTION
This module emulates the interface of enum.pm, sans support for bitmasks. Unlike enum.pm, the symbols generated by this module are actual Perl constants, and may be imported and exported as such by external modules.
ENUMERATIONS
-
Provide
false
andtrue
enumerated constants -
Constant enumeration of supported database types
SYNOPSIS
The following is borrowed from the perldoc for enum.pm:
use Devel::Ladybug::Enum qw(Sun Mon Tue Wed Thu Fri Sat);
# Sun == 0, Mon == 1, etc
use Devel::Ladybug::Enum qw(Forty=40 FortyOne Five=5 Six Seven);
# Yes, you can change the start indexs at any time as in C
use Devel::Ladybug::Enum qw(:Prefix_ One Two Three);
## Creates Prefix_One, Prefix_Two, Prefix_Three
use Devel::Ladybug::Enum qw(:Letters_ A..Z);
## Creates Letters_A, Letters_B, Letters_C, ...
use Devel::Ladybug::Enum qw(
:Months_=0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
:Days_=0 Sun Mon Tue Wed Thu Fri Sat
:Letters_=20 A..Z
);
## Prefixes can be changed mid list and can have index changes too
Bitmask support is not currently implemented.
Basic Usage
Create a quick package of enumerated constants:
#
# File: Month.pm
#
package Month;
use Devel::Ladybug::Enum qw|
jan feb mar apr may jun jul aug sep oct nov dec
|;
1;
Meanwhile, in caller:
#
# File: hangover.pl
#
use Month;
...
my $month = getMonth();
if ( $month == Month::jan ) {
print "Happy New Year\n";
}
Auto Export
Same usage as the Month.pm example above, with an extra block of code eval'd for Exporter.
#
# File: DayOfWeek.pm
#
package DayOfWeek;
use Devel::Ladybug::Enum qw| sun mon tue wed thu fri sat |;
eval { @EXPORT = @EXPORT_OK };
1;
Meanwhile, in caller:
#
# File: pizza-reminder.pl
#
use DayOfWeek;
...
my $day = getDayOfWeek();
if ( $day == fri ) {
print "It's pizza day!\n";
}
SEE ALSO
This file is part of Devel::Ladybug.