ingydotnet / boolean-pm

Boolean Type Support for Perl
7 stars 5 forks source link

Fix type coercion with Moo / Type::Tiny #13

Open pjfl opened 9 years ago

pjfl commented 9 years ago

Would you add this overload?

'&{}' => sub { my $x = shift; sub { ${ $x } } },

It will allow the following to work

package Test;
use boolean;
use Types::Standard qw( Bool );
use Moo;
has 'f' => is => 'ro', isa => Bool, default => false;
has 't' => is => 'ro', isa => Bool, default => true;
1;
package main;
my $t = Test->new;
print $t->f."\n";
print $t->t."\n";
perlpunk commented 6 years ago

Hm, if $object->some_boolean returns 1 or 0 instead of the boolean object itself, then why use boolean.pm in the first place? If this overload is added, people wouldn't be able to retrieve a boolean object via method call anymore.