From: Peter Rabbitson Date: Fri, 3 Jun 2016 14:12:32 +0000 (+0200) Subject: Add true/false non-singleton boolean objects X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=293cb2f1de2a488aa6062036deac8a562e8e16c6 Add true/false non-singleton boolean objects This will be needed for the sanitychecker on OLD_MRO --- diff --git a/lib/DBIx/Class/_Util.pm b/lib/DBIx/Class/_Util.pm index 76f9b35..7af2102 100644 --- a/lib/DBIx/Class/_Util.pm +++ b/lib/DBIx/Class/_Util.pm @@ -173,6 +173,7 @@ our @EXPORT_OK = qw( fail_on_internal_wantarray fail_on_internal_call refdesc refcount hrefaddr set_subname describe_class_methods scope_guard detected_reinvoked_destructor + true false is_exception dbic_internal_try visit_namespaces quote_sub qsub perlstring serialize deep_clone dump_value uniq parent_dir mkdir_p @@ -369,6 +370,20 @@ sub dump_value ($) { $dump_str; } +### +### This is *NOT* boolean.pm - deliberately not using a singleton +### +{ + package # hide from pause + DBIx::Class::_Util::_Bool; + use overload + bool => sub { ${$_[0]} }, + fallback => 1, + ; +} +sub true () { my $x = 1; bless \$x, "DBIx::Class::_Util::_Bool" } +sub false () { my $x = 0; bless \$x, "DBIx::Class::_Util::_Bool" } + sub scope_guard (&) { croak 'Calling scope_guard() in void context makes no sense' if ! defined wantarray; diff --git a/xt/extra/internals/bool.t b/xt/extra/internals/bool.t new file mode 100644 index 0000000..473a562 --- /dev/null +++ b/xt/extra/internals/bool.t @@ -0,0 +1,23 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + +use strict; +use warnings; + +use Test::More; +use DBIx::Class::_Util qw( true false ); +use Scalar::Util 'refaddr'; + +my @things = ( true, false, true, false, true, false ); + +for (my $i = 0; $i < $#things; $i++ ) { + for my $j ( $i+1 .. $#things ) { + cmp_ok + refaddr( $things[$i] ), + '!=', + refaddr( $things[$j] ), + "Boolean thingy '$i' distinct from '$j'", + ; + } +} + +done_testing;