On 30 May 2010 22:36, Gabor Szabo <[email protected]> wrote:
> So I wanted to show how
> if ( $foo ) {
> is a boolean context and started to write an example:
>
> use strict;
> use warnings;
>
> tie my $z, 'X', 1;
> print $z;
>
> package X;
> use strict;
> use warnings;
> use Want;
>
> sub TIESCALAR {
> my ($class, $self) = @_;
> return bless \$self, $class,
> }
>
> sub FETCH {
> my ($self) = @_;
> print "ok" if want('BOOL');
> return $$self;
> }
>
>
> the response was surprising:
>
> Segmentation fault
>
> using v5.10.1 that comes with Ubuntu 10.4 and Want 0.18
>
> the call to 'want' generates this.
>
> Can someone with a newer version of perl confirm this?
Perhaps an older version of Perl would be better suited ;-)
I think the problem is that the context for tie methods is not a Perl
stack per se, there's some C in the middle.
Want also crashes inside Template::Stash::XS for the same reason.
Check to see if this variant works:
if ( (tied $foo)->FETCH ) { ... }
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl