--- GtkLinkButton.t 02 Sep 2008 09:21:24 +1000 1.4 +++ GtkLinkButton.t 03 Sep 2008 09:28:23 +1000 @@ -52,6 +52,48 @@ $button->set_uri_hook (undef); +{ my $saw_data; + sub hook2 { + $saw_data = $_[-1]; + $_[-1]++; + } + $button->set_uri_hook (\&hook2, 100); + $button->clicked; + is ($saw_data, 100, 'initial userdata'); + $button->clicked; + is ($saw_data, 101, 'incremented once'); + $button->clicked; + is ($saw_data, 102, 'incremented twice'); + + $button->set_uri_hook (undef); +} + +{ my $userdata = [ 'something' ]; + sub hook3 { + $_[-1] = undef; + } + $button->set_uri_hook (\&hook3, $userdata); + require Scalar::Util; + Scalar::Util::weaken ($userdata); + is_deeply ($userdata, [ 'something' ], + 'still alive when first weakened'); + $button->clicked; + is ($userdata, undef, 'then gone when hook zaps its last arg'); + + $button->set_uri_hook (undef); +} + +{ my $saw_data; + sub hook4 { + $button->set_uri_hook (undef); + $saw_data = $_[-1]; + } + $button->set_uri_hook (\&hook4, [ 'hello' ]); + $button->clicked; + is_deeply ($saw_data, [ 'hello' ], + 'userdata still ok when hook disconnects itself'); +} + SKIP: { skip 'new 2.14 stuff', 1 unless Gtk2->CHECK_VERSION(2, 13, 7); # FIXME: 2.14