Object::Generic::False - Object::Generic::False documentation


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

Index


NAME

Top

Object::Generic::False - a perl object that evaluates as false but allows method calls.

SYNOPSIS

Top

  use Object::Generic::False qw(false);
  my $n = false;        # returns global $Object::Generic::False::_false_
  print "n is false" if not $n;
  print "n->foo->bar is also false" if not $n->foo->bar;

  my $result = Object::Generic::False->new('Some error message.');
  print The error is '" . $result->error . "'\n" if not $result;

DESCRIPTION

Top

Lately I've been doing some object oriented perl in which I would like to have $object->foo return false without having $object->foo->bar generate an error. Hence this module.

To generate a false object, either use the exported false() method, which returns the package global $Object::Generic::False::_false_, or create your own instance with Object::Generic::False->new;

Object::Generic::False objects continue to be false when combined with other perl entities. Thus for example unlike numeric 0, (2 + false) is still false. In that respect they act somewhat "tainted" variables.

The exceptions to this rule are comparisons and string concatenation: (false == 0) and (false eq '') are both true, while false()."foo" is "foo".

These objects can also be used as a returned error with an enclosed message. To do so, just pass in a string when creating one with the new message, ie "$result = new Object::Generic::False 'your message'". $result still evaluates as false, but the message may be retrieved with $result->error.

EXPORT

The false() function is exported, which returns the global $Object::Generic::False::_false_ object.

AUTHOR

Top

Jim Mahoney, <mahoney@marlboro.edu<gt>

COPYRIGHT AND LICENSE

Top


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