Add true/false non-singleton boolean objects
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / _Util.pm
index dfa20c4..7af2102 100644 (file)
@@ -6,8 +6,6 @@ use DBIx::Class::StartupCheck;  # load es early as we can, usually a noop
 use warnings;
 use strict;
 
-use constant SPURIOUS_VERSION_CHECK_WARNINGS => ( "$]" < 5.010 ? 1 : 0);
-
 my $mro_recursor_stack;
 
 BEGIN {
@@ -17,18 +15,23 @@ BEGIN {
   use Config;
 
   use constant {
+    PERL_VERSION => "$]",
+    OS_NAME => "$^O",
+  };
+
+  use constant {
 
     # but of course
-    BROKEN_FORK => ($^O eq 'MSWin32') ? 1 : 0,
+    BROKEN_FORK => (OS_NAME eq 'MSWin32') ? 1 : 0,
 
-    BROKEN_GOTO => ( "$]" < 5.008003 ) ? 1 : 0,
+    BROKEN_GOTO => ( PERL_VERSION < 5.008003 ) ? 1 : 0,
 
     # perl -MScalar::Util=weaken -e 'weaken( $hash{key} = \"value" )'
-    BROKEN_WEAK_SCALARREF_VALUES => ( "$]" < 5.008003 ) ? 1 : 0,
+    BROKEN_WEAK_SCALARREF_VALUES => ( PERL_VERSION < 5.008003 ) ? 1 : 0,
 
     HAS_ITHREADS => $Config{useithreads} ? 1 : 0,
 
-    UNSTABLE_DOLLARAT => ( "$]" < 5.013002 ) ? 1 : 0,
+    UNSTABLE_DOLLARAT => ( PERL_VERSION < 5.013002 ) ? 1 : 0,
 
     ( map
       #
@@ -47,11 +50,9 @@ BEGIN {
     ),
 
     IV_SIZE => $Config{ivsize},
-
-    OS_NAME => $^O,
   };
 
-  if ( "$]" < 5.009_005) {
+  if ( PERL_VERSION < 5.009_005) {
     require MRO::Compat;
     constant->import( OLD_MRO => 1 );
 
@@ -149,6 +150,8 @@ BEGIN {
   sub PEEPEENESS () { &$sigh }
 }
 
+use constant SPURIOUS_VERSION_CHECK_WARNINGS => ( DBIx::Class::_ENV_::PERL_VERSION < 5.010 ? 1 : 0);
+
 # FIXME - this is not supposed to be here
 # Carp::Skip to the rescue soon
 use DBIx::Class::Carp '^DBIx::Class|^DBICTest';
@@ -170,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
@@ -366,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;