Enumeration

Yet Another enumeration class implementation
Download

Enumeration Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Eric J. Roode
  • Publisher web site:
  • http://search.cpan.org/~roode/

Enumeration Tags


Enumeration Description

Yet Another enumeration class implementation Enumeration is a Perl module that provides an enumeration class. For those of you who are not familiar with this concept from other languages, an enumeration is a class whose instantiated objects may only be assigned values that come from a fixed list.There are two ways of using this module. Typically, you will create a subclass that inherits from Enumeration and which specifies the list of allowable values. This is very simple. Your class module will contain only three lines of code: # MyEnumeration.pm # package MyEnumeration; use base 'Enumeration'; __PACKAGE__->set_enumerations( qw(red yellow blue green) );Programs will use this class as follows: # some_program.pl # use MyEnumeration; # .... my $var = new MyEnumeration(MyEnumeration::yellow); # or just: $var = new MyEnumeration;Users of your subclass may choose to have all of your enumeration symbols imported into their namespace. They do this by using the string ':all' on the use line: use MyEnumeration ':all'; # .... my $var = new MyEnumeration(yellow);The other way to use this module is for when you need an ad-hoc enumeration at run-time: # some_program.pl # my $var = new Enumeration qw(whee this is fun);SYNOPSIS # Usually you will subclass Enumeration, and others will use your subclass. use YourSubClass; use YourSubClass ':all'; # import enumeration constants # Class methods (used when subclassing; see below) __PACKAGE__->set_enumerations( qw(red yellow blue green) ); # Creation $var = new Enumeration (@allowable_values); $var = new YourSubClass; $var = new YourSubClass($initial_value); # Set the value $var->set($new_value); # (note: undef is always allowed) # Return the value $string = $var->value; # "YourSubClass::enum_value" $string = $var->bare_value; # "enum_value" $string = "$var"; # same as ->value # Compare $boolean = $var eq $some_value; $boolean = $var ne $some_value; $boolean = $var->is_any(@list_of_possible_values); $boolean = $var->is_none(@list_of_possible_values); # Test whether some value is a member of the set $boolean = YourSubClass->is_allowable_value($some_value); $boolean = $var->is_allowable_value($some_value); Requirements: · Perl


Enumeration Related Software