Subject: | Use of Contextual::Return causes issues |
Contextual::Return being loaded can cause other modules to break in some cases. One such case is MooseX::NonMoose when used with the perl debugger on perl 5.14. Contextual::Return and Want.pm can also cause segfaults.
Contextual::Return is a rather heavy solution and its full power isn't really needed for this module. Attached is a patch that implements a minimal solution using a class with overloads.
Subject: | boolean-no-cr.patch |
diff --git i/lib/DBIx/Class/InflateColumn/Boolean.pm w/lib/DBIx/Class/InflateColumn/Boolean.pm
index 114a80d..b4a666f 100644
--- i/lib/DBIx/Class/InflateColumn/Boolean.pm
+++ w/lib/DBIx/Class/InflateColumn/Boolean.pm
@@ -171,21 +171,21 @@ sub register_column {
$ref eq '' ?
sub {
my $x = shift;
- BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { $x eq $false_is ? 0 : 1 };
+ DBIx::Class::InflateColumn::Boolean::Value->new($x, $x ne $false_is);
} :
$ref eq 'ARRAY' ?
sub {
my $x = shift;
for (@$false_is) {
- return BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { 0 }
+ return DBIx::Class::InflateColumn::Boolean::Value->new($x, 0)
if $x eq $_;
}
- BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { 1 };
+ DBIx::Class::InflateColumn::Boolean::Value->new($x, 1)
} :
# $ref eq 'Regexp'
sub {
my $x = shift;
- BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { $x =~ $false_is ? 0 : 1 };
+ DBIx::Class::InflateColumn::Boolean::Value->new($x, $x !~ $false_is);
},
deflate => sub { shift },
}
@@ -199,21 +199,21 @@ sub register_column {
$ref eq '' ?
sub {
my $x = shift;
- BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { $x eq $true_is ? 1 : 0 };
+ DBIx::Class::InflateColumn::Boolean::Value->new($x, $x eq $true_is);
} :
$ref eq 'ARRAY' ?
sub {
my $x = shift;
for (@$true_is) {
- return BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { 1 }
+ return DBIx::Class::InflateColumn::Boolean::Value->new($x, 1)
if $x eq $_;
}
- BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { 0 };
+ DBIx::Class::InflateColumn::Boolean::Value->new($x, 0)
} :
# $ref eq 'Regexp'
sub {
my $x = shift;
- BLESSED { 'Contextual::Return::Value' } SCALAR { $x } BOOL { $x =~ $true_is ? 1 : 0 };
+ DBIx::Class::InflateColumn::Boolean::Value->new($x, $x =~ $true_is)
},
deflate => sub { shift },
}
@@ -221,6 +221,22 @@ sub register_column {
}
}
+{
+ package #hide
+ DBIx::Class::InflateColumn::Boolean::Value;
+
+ use overload
+ '""' => sub { $_[0][0] },
+ 'bool' => sub { $_[0][1] },
+ fallback => 1,
+ ;
+
+ sub new {
+ my ($class, $value, $bool) = @_;
+ my $self = bless [$value, !!$bool], $class;
+ }
+}
+
1;
__END__
diff --git i/t/01-boolean.t w/t/01-boolean.t
index 7877826..94422e7 100644
--- i/t/01-boolean.t
+++ w/t/01-boolean.t
@@ -38,9 +38,9 @@ ok(blessed($true->foo), '$true->foo has been inflated into an object');
ok(blessed($true->bar), '$true->bar has been inflated into an object');
ok(blessed($true->baz), '$true->baz has been inflated into an object');
-ok(blessed($true->foo) && ref($true->foo) eq 'Contextual::Return::Value', 'ref($true->foo) eq "Contextual::Return::Value"');
-ok(blessed($true->bar) && ref($true->bar) eq 'Contextual::Return::Value', 'ref($true->bar) eq "Contextual::Return::Value"');
-ok(blessed($true->baz) && ref($true->baz) eq 'Contextual::Return::Value', 'ref($true->baz) eq "Contextual::Return::Value"');
+ok(blessed($true->foo) && ref($true->foo) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($true->foo) eq "DBIx::Class::InflateColumn::Boolean::Value"');
+ok(blessed($true->bar) && ref($true->bar) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($true->bar) eq "DBIx::Class::InflateColumn::Boolean::Value"');
+ok(blessed($true->baz) && ref($true->baz) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($true->baz) eq "DBIx::Class::InflateColumn::Boolean::Value"');
is($true->foo, 'Y', '$true->foo eq "Y"');
is($true->bar, 'oui', '$true->bar eq "oui"');
@@ -54,9 +54,9 @@ ok(blessed($false->foo), '$false->foo has been inflated into an object');
ok(blessed($false->bar), '$false->bar has been inflated into an object');
ok(blessed($false->baz), '$false->baz has been inflated into an object');
-ok(blessed($false->foo) && ref($false->foo) eq 'Contextual::Return::Value', 'ref($true->foo) eq "Contextual::Return::Value"');
-ok(blessed($false->bar) && ref($false->bar) eq 'Contextual::Return::Value', 'ref($true->bar) eq "Contextual::Return::Value"');
-ok(blessed($false->baz) && ref($false->baz) eq 'Contextual::Return::Value', 'ref($true->baz) eq "Contextual::Return::Value"');
+ok(blessed($false->foo) && ref($false->foo) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($true->foo) eq "DBIx::Class::InflateColumn::Boolean::Value"');
+ok(blessed($false->bar) && ref($false->bar) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($true->bar) eq "DBIx::Class::InflateColumn::Boolean::Value"');
+ok(blessed($false->baz) && ref($false->baz) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($true->baz) eq "DBIx::Class::InflateColumn::Boolean::Value"');
is($false->foo, 'N', '$false->foo eq "N"');
is($false->bar, 'non', '$false->bar eq "non"');
@@ -71,7 +71,7 @@ $false->update;
my $row = $rs->find(2); # re-read 2nd row
ok(blessed($row->bar), '$row->bar has been inflated into an object');
-ok(blessed($row->bar) && ref($row->bar) eq 'Contextual::Return::Value', 'ref($row->bar) eq "Contextual::Return::Value"');
+ok(blessed($row->bar) && ref($row->bar) eq 'DBIx::Class::InflateColumn::Boolean::Value', 'ref($row->bar) eq "DBIx::Class::InflateColumn::Boolean::Value"');
is($row->bar, 'oui', '$row->bar eq "oui"');
ok($row->bar, '$true->bar is row');
ok(!blessed($row->get_column('bar')), '$row->get_column("bar") is not blessed');