Skip to content

Commit

Permalink
version 0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Jan 15, 2011
1 parent 1510d12 commit 400cb47
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 113 deletions.
10 changes: 10 additions & 0 deletions Changes
@@ -1,4 +1,14 @@
---
version: 0.25
date: Sat Jan 15 19:05:19 EST 2011
changes:
- Fixed a bug caused by Readonly::XS (schwern++)
- Removed the new methods and autobox methods.
They didn't add much except confusion.
- Documented that you can use isTrue and isFalse as methods.
- &boolean(1,2,3) now dies like boolean(1,2,3)
- &boolean() now dies like boolean()
---
version: 0.24
date: Thu Jan 13 15:27:09 EST 2011
changes:
Expand Down
42 changes: 14 additions & 28 deletions README
Expand Up @@ -7,14 +7,7 @@ SYNOPSIS
do &always if true;
do &never if false;

do &maybe if boolean($value)->is_true;

With autobox:

use autobox;
use boolean;

do &maybe if $value->is_true;
do &maybe if boolean($value)->isTrue;

and:

Expand Down Expand Up @@ -56,14 +49,14 @@ FUNCTIONS
This module defines the following functions:

true
This function returns a scalar value which should evaluate to true.
This function returns a scalar value which will evaluate to true.
The value is a singleton object, meaning there is only one "true"
value in a Perl process at any time. You can check to see whether
the value is the "true" object with the isTrue function described
below.

false
This function returns a scalar value which should evaluate to false.
This function returns a scalar value which will evaluate to false.
The value is a singleton object, meaning there is only one "false"
value in a Perl process at any time. You can check to see whether
the value is the "false" object with the isFalse function described
Expand All @@ -89,25 +82,12 @@ FUNCTIONS
METHODS
Since true and false return objects, you can call methods on them.

$boolean->is_true
$boolean->isTrue
Same as isTrue($boolean).

$boolean->is_false
$boolean->isFalse
Same as isFalse($boolean).

autobox Methods
If you use "boolean" with "autobox" you can call the following methods
on any scalar:

$scalar->boolean
Same as boolean($scalar).

$scalar->is_true
Same as isTrue(boolean($scalar)).

$scalar->is_false
Same as isFalse(boolean($scalar)).

EXPORTABLES
By default this module exports the "true", "false" and "boolean"
functions.
Expand All @@ -117,9 +97,6 @@ EXPORTABLES
:all
Exports "true", "false", "boolean", "isTrue", "isFalse", "isBoolean"

:test
Exports "isTrue", "isFalse", "isBoolean"

AUTHOR
Ingy döt Net <ingy@cpan.org>

Expand All @@ -131,3 +108,12 @@ COPYRIGHT

See http://www.perl.com/perl/misc/Artistic.html

POD ERRORS
Hey! The above document had some coding errors, which are explained
below:

Around line 177:
You forgot a '=back' before '=head1'

You forgot a '=back' before '=head1'

83 changes: 17 additions & 66 deletions lib/boolean.pm
Expand Up @@ -2,7 +2,7 @@ package boolean;
use 5.005003;
use strict;
# use warnings;
$boolean::VERSION = '0.24';
$boolean::VERSION = '0.25';

my ($true, $false);

Expand All @@ -26,13 +26,14 @@ BEGIN {

my $t = 1;
my $f = 0;
$true = do {bless \$t, 'boolean'};
$false = do {bless \$f, 'boolean'};

if ( $have_readonly ) {
Readonly::Scalar($t => $t);
Readonly::Scalar($f => $f);
}

$true = do {bless \$t, 'boolean'};
$false = do {bless \$f, 'boolean'};
$true_val = overload::StrVal($true);
$false_val = overload::StrVal($false);
$bool_vals = {$true_val => 1, $false_val => 1};
Expand All @@ -41,15 +42,11 @@ BEGIN {
sub true() { $true }
sub false() { $false }
sub boolean($) {
return $false if scalar(@_) == 0;
return $true if scalar(@_) > 1;
die "Not enough arguments for boolean::boolean" if scalar(@_) == 0;
die "Too many arguments for boolean::boolean" if scalar(@_) > 1;
return not(defined $_[0]) ? false :
"$_[0]" ? $true : $false;
}
sub isBoolean($) {
not(defined $_[0]) ? false :
(exists $bool_vals->{overload::StrVal($_[0])}) ? true : false;
}
sub isTrue($) {
not(defined $_[0]) ? false :
(overload::StrVal($_[0]) eq $true_val) ? true : false;
Expand All @@ -58,24 +55,9 @@ sub isFalse($) {
not(defined $_[0]) ? false :
(overload::StrVal($_[0]) eq $false_val) ? true : false;
}

# Methods
sub is_true {
return isTrue($_[0]);
}
sub is_false {
return isFalse($_[0]);
}

# For autobox
sub SCALAR::boolean {
return boolean($_[0]);
}
sub SCALAR::is_true {
return isTrue(boolean($_[0]));
}
sub SCALAR::is_false {
return isFalse(boolean($_[0]));
sub isBoolean($) {
not(defined $_[0]) ? false :
(exists $bool_vals->{overload::StrVal($_[0])}) ? true : false;
}

1;
Expand All @@ -93,14 +75,7 @@ boolean - Boolean support for Perl
do &always if true;
do &never if false;
do &maybe if boolean($value)->is_true;
With autobox:
use autobox;
use boolean;
do &maybe if $value->is_true;
do &maybe if boolean($value)->isTrue;
and:
Expand Down Expand Up @@ -148,17 +123,17 @@ This module defines the following functions:
=item true
This function returns a scalar value which should evaluate to true. The
This function returns a scalar value which will evaluate to true. The
value is a singleton object, meaning there is only one "true" value in a
Perl process at any time. You can check to see whether the value is the
"true" object with the isTrue function described below.
=item false
This function returns a scalar value which should evaluate to false. The
value is a singleton object, meaning there is only one "false" value in a
Perl process at any time. You can check to see whether the value is the
"false" object with the isFalse function described below.
This function returns a scalar value which will evaluate to false. The
value is a singleton object, meaning there is only one "false" value in
a Perl process at any time. You can check to see whether the value is
the "false" object with the isFalse function described below.
=item boolean($scalar)
Expand Down Expand Up @@ -189,36 +164,16 @@ Since true and false return objects, you can call methods on them.
=over
=item $boolean->is_true
=item $boolean->isTrue
Same as isTrue($boolean).
=item $boolean->is_false
=item $boolean->isFalse
Same as isFalse($boolean).
=back
=head2 autobox Methods
If you use C<boolean> with C<autobox> you can call the following methods on any scalar:
=over
=item $scalar->boolean
Same as boolean($scalar).
=item $scalar->is_true
Same as isTrue(boolean($scalar)).
=item $scalar->is_false
Same as isFalse(boolean($scalar)).
=back
=head1 EXPORTABLES
By default this module exports the C<true>, C<false> and C<boolean> functions.
Expand All @@ -231,10 +186,6 @@ The module also defines these export tags:
Exports C<true>, C<false>, C<boolean>, C<isTrue>, C<isFalse>, C<isBoolean>
=item :test
Exports C<isTrue>, C<isFalse>, C<isBoolean>
=back
=head1 AUTHOR
Expand Down
16 changes: 0 additions & 16 deletions t/autobox.t

This file was deleted.

19 changes: 16 additions & 3 deletions t/boolean.t
@@ -1,4 +1,4 @@
use Test::More tests => 61;
use Test::More tests => 65;
use strict;
use lib 'lib';

Expand Down Expand Up @@ -87,6 +87,19 @@ ok $f eq 0, 'false eq 0';
ok $f == 0, 'false == 0';

# boolean()
eval "boolean()";
like $@, qr/Not enough arguments for boolean::boolean/,
"boolean() has too few args (prototyped)";
eval "&boolean()";
like $@, qr/Not enough arguments for boolean::boolean/,
"&boolean() has too few args (unprototyped)";
eval "boolean(1,2,3)";
like $@, qr/Too many arguments for boolean::boolean/,
"boolean(1,2,3) has too many args (prototyped)";
eval "&boolean(1,2,3)";
like $@, qr/Too many arguments for boolean::boolean/,
"&boolean(1,2,3) has too many args (unprototyped)";

my @t = (0);
ok isBoolean(boolean(42)), "boolean() returns boolean";
ok isBoolean(boolean(undef)), "boolean() works with undef";
Expand Down Expand Up @@ -118,5 +131,5 @@ SKIP: {
}
}

ok true->is_true, "true is_true";
ok false->is_false, "true is_true";
ok true->isTrue, "true isTrue";
ok false->isFalse, "false isFalse";

0 comments on commit 400cb47

Please sign in to comment.