Subject: | Numeric comparison for Tickit::Window instances fails due to overload |
Hi,
Looks like there's a few places where numeric comparisons between
Tickit::Window objects are used. Verified it still happens in the latest
bzr code:
Tickit/Widget.pm(97):
return if $window and $self->window and $self->window == $window
and for this to work, I believe numeric overload is needed as well as
the existing string overload.
This patch should apply cleanly to latest trunk.
cheers,
Tom
Subject: | 20110517-tickit-numeric-window-comparison.patch |
=== modified file 'lib/Tickit/Window.pm'
--- lib/Tickit/Window.pm 2011-04-26 18:44:40 +0000
+++ lib/Tickit/Window.pm 2011-05-17 17:55:15 +0000
@@ -649,7 +649,14 @@
return sprintf "%s[%dx%d abs@%d,%d]",
ref $self,
$self->cols, $self->lines, $self->abs_left, $self->abs_top;
-};
+},
+# Numeric comparison is used in a few places, make sure it doesn't fall through to string
+'0+' => sub {
+ my ($self, $x, $y) = @_;
+ return $self;
+},
+# Allow fallback so that refaddr comparisons (==) work as expected
+fallback => 1;
=head1 AUTHOR
=== modified file 't/11window.t'
--- t/11window.t 2011-05-01 12:55:22 +0000
+++ t/11window.t 2011-05-17 17:54:26 +0000
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 40;
+use Test::More tests => 41;
use Test::Fatal;
use Test::Identity;
use Test::Refcount;
@@ -21,6 +21,7 @@
is_refcount( $rootwin, 3, '$rootwin has refcount 3 after ->make_sub' );
is( "$win", 'Tickit::Window[20x4 abs@10,3]', '$win string overload' );
+ok( !($win == $rootwin), '$win numeric ==' );
my $geom_changed = 0;
$win->set_on_geom_changed( sub { $geom_changed++ } );