Object::Enum - replacement for C<< if ($foo eq 'bar') >>


Object-Enum documentation  | view source Contained in the Object-Enum distribution.

Index


NAME

Top

Object::Enum - replacement for if ($foo eq 'bar')

VERSION

Top

Version 0.072

SYNOPSIS

Top

  use Object::Enum qw(Enum);

  my $color = Enum([ qw(red yellow green) ]);
  # ... later
  if ($color->is_red) {
  # it can't be yellow or green

EXPORTS

Top

See Sub::Exporter for ways to customize this module's exports.

Enum

An optional shortcut for Object::Enum->new.

CLASS METHODS

Top

new

  my $obj = Object::Enum->new(\@values);
  # or
  $obj = Object::Enum->new(\%arg);

Return a new Object::Enum, with one or more sets of possible values.

The simplest case is to pass an arrayref, which returns an object capable of having any one of the given values or of being unset.

The more complex cases involve passing a hashref, which may have the following keys:

* unset

whether this object can be 'unset' (defaults to true)

* default

this object's default value is (defaults to undef)

* values

an arrayref, listing the object's possible values (at least one required)

OBJECT METHODS

Top

spawn

clone

  my $new = $obj->clone;

  my $new = $obj->clone($value);

Create a new Enum from an existing object, using the same arguments as were originally passed to new when that object was created.

An optional value may be passed in; this is identical to (but more convenient than) calling value with the same argument on the newly cloned object.

This method was formerly named spawn. That name will still work but is deprecated.

value

The current value as a string (or undef)

Note: don't pass in undef; use the unset method instead.

values

The possible values for this object

unset

Unset the object's value (set to undef)

is_*

set_*

Automatically generated from the values passed into new.

None of these methods take any arguments.

The set_* methods are chainable; that is, they return the object on which they were called. This lets you do useful things like:

  use Object::Enum Enum => { -as => 'color', values => [qw(red blue)] };

  print color->set_red->value; # prints 'red'

AUTHOR

Top

Hans Dieter Pearcey, <hdp at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-object-enum at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Object-Enum. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Object::Enum

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Object-Enum

* CPAN Ratings

http://cpanratings.perl.org/d/Object-Enum

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Object-Enum

* Search CPAN

http://search.cpan.org/dist/Object-Enum

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Object-Enum documentation  | view source Contained in the Object-Enum distribution.