Skip Menu |

This queue is for tickets about the version CPAN distribution.

Report information
The Basics
Id: 123309
Status: new
Priority: 0/
Queue: version

People
Owner: Nobody in particular
Requestors: DBOOK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Boolean overload behavior
A version object that evaluates to 0 will return false when used as a boolean. This appears to be confusingly documented in version::Internals: If you need to test whether a version object has been initialized, you can simply test it directly: $vobj = version->new($something); if ( $vobj ) # true only if $something was non-blank This does not in fact test if the version object has been initialized, since it is always initialized, otherwise an exception would be thrown. But it does test if $something was either undef or evaluates to the version 0; 'blank' is not really the best terminology for this either. Aside from the documentation needing more specificity, there's the question of whether this is useful behavior at all. In general unless an object is specifically designed to represent 'false' (such as with JSON boolean objects) it should always boolify to 'true', so that if ($obj) will always be true if it's defined. In particular this 'gotcha' currently makes the "semantically-equivalent" code in the require function docs incorrect: http://perldoc.perl.org/functions/require.html The boolean check 'if ( my $version = eval { version->parse($filename) } ) {' will be skipped if given a version that evaluates to 0, but this is not how Perl behaves; 'require 0;' is still treated as a version check (which of course always succeeds). This is just documentation that could be fixed, but it's an example of a trap that others may easily fall into given how objects usually work in Perl.