Subject: | objects from tied scalars |
Date: | Tue, 27 Sep 2011 06:55:18 +1000 |
To: | bug-Wx [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
In recent debian i386 wx 2.8.10.1 and wxperl 0.9901, it seems a Wx::Size
coming out of a tied scalar is not recognised. foo.pl below gives
variable is not of type Wx::Size at foo.pl line 23.
on attempting
$frame->SetSize ($magic);
Where I hoped it would run the FETCH() from the tied $magic and get
Wx::wxDefaultSize.
Often this sort of thing is from the XS not running magic (SvGETMAGIC or
whichever one of those macros is right) before looking into the sv flags
like SvOK, SvROK, etc.
A contrivance like foo.pl can come from "lazy scalars" deferring a value
until needed, or this came up in one spot of perl-gtk lately on objects
held in a Tie::IxHash (or was it a Tie::RefHash?) which end up magic to
support the special features of that tie.
use strict;
use Wx;
my $app = Wx::SimpleApp->new;
{
package MyTiedSize;
sub TIESCALAR {
my $class = shift;
return bless {@_}, $class;
}
sub FETCH {
print "MyTiedSize FETCH runs\n";
return Wx::wxDefaultSize();
}
}
my $magic;
tie $magic, 'MyTiedSize';
# print $magic,"\n";
my $frame = Wx::Frame->new (undef, -1, "Hello");
$frame->SetSize ($magic);
$frame->Show;
$app->MainLoop;