Lazy-Bool

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

I'm very interesting in your opinion! Please give me some feedback :)

###UPDATE###

From version 0.03 there all boolean expression now supports shortcut and there is a new class, Lazy::Bool::Cached who memoize the value of the expression.

##Helpers##

There are two helpers to easily create new instances from an anonymous subroutine: lzb and lzbc 

```perl
use Test::More tests => 2;

use Lazy::Bool qw(lzb);
use Lazy::Bool::Cached qw(lzbc);

ok( lzb { 1 }, "lzb should be true" );
ok( lzbc { 1 }, "lzbc should be true" );
```

##How to install##
To install this module is simple:
	bash$ cpan Lazy::Bool

###Test Coverage##

Total 96.6 % 
```
---------------------------- ------ ------ ------ ------ ------ ------ ------
File                           stmt   bran   cond    sub    pod   time  total
---------------------------- ------ ------ ------ ------ ------ ------ ------
blib/lib/Lazy/Bool.pm         100.0  100.0   66.7  100.0   75.0   64.9   97.2
blib/lib/Lazy/Bool/Cached.pm  100.0  100.0   66.7  100.0   50.0   35.1   95.7
Total                         100.0  100.0   66.7  100.0   66.7  100.0   96.6
---------------------------- ------ ------ ------ ------ ------ ------ ------
```
	
##Final Considerations##

I try to do this module in Ruby and I realize it is not possible [see here](http://stackoverflow.com/questions/14444975/how-to-create-an-object-who-act-as-a-false-in-ruby/). In Ruby we have only two "false" values: nil and false. And it is HARD CODED...

The same thing in Java: I have the Boolean wrapper class but it is final. But I can emulate the same thing in Python using the `__nonzero__` special method like this:

```python
class MyBooleanClass:
	def __init__(self, value):
		self.value = value
		
	def __nonzero__(self):
		return self.value # Just to simplify the example
		
t = MyBooleanClass(True)
f = MyBooleanClass(False)

assert t, "should be true"
assert not f, "should be false"
```

Build a dynamic proxy to one real object can be very helpful in many situations. You can find this in Hibernate (the Java ORM solution) if you choose working with Lazy Initialization.

Perl, Python, Java, Ruby or PHP: each language has some advantages to do something. I can't choose one language just based on one aspect. We need to consider the community, the environment, tools, etc. Perl is a good choice for software development i...



( run in 0.904 second using v1.01-cache-2.11-cpan-2398b32b56e )