I think the want context is something screwy in this case:
package LuckyDeck;
use Tie::Array;
use overload
'<>' => sub {
use Want;
my $self = shift;
foreach (qw(BOOL SCALAR LIST ASSIGN REF)) {
print STDERR "want $_\n" if want $_;
}
if (want ('BOOL') or want ('SCALAR')) {
return splice( @$self, rand @$self, 1) unless wantarray;
}
my @deck;
push @deck, splice( @$self, rand @$self, 1) while @$self;
@deck;
};
sub new {
my $class = shift;
bless [@_], $class;
}
package main;
my $quux = LuckyDeck->new(1..9);
print 'List Context',$/;
print for <$quux>;
print $/;
Which, when run with 5.6.1, yields:
perl/Language-FP% perl -l ../bar.pl
List Context
zsh: 7739 segmentation fault (core dumped) perl -l ../bar.pl
In
#0 0xfd7b77c in parent_op ()
from #1 0xfd7bf28 in XS_Want_parent_op_name ()
from #2 0x10076ddc in Perl_pp_entersub ()
#3 0x1006fb80 in Perl_runops_standard ()
#4 0x1001fa3c in Perl_amagic_call ()
#5 0x100701e8 in Perl_pp_readline ()
#6 0x1006fb80 in Perl_runops_standard ()
#7 0x10014644 in S_run_body ()
#8 0x10014288 in perl_run ()
#9 0x10010f58 in main ()
#10 0xfe2e69c in __libc_start_main ()
at ../sysdeps/powerpc/elf/libc-start.c:106
#11 0x0 in ?? ()
So it's evidently giving Want something it can't handle. The "amagic_call()" makes me think it's trying to access $quux as a tied array, but I'm hardly Mr. Internals. In any case, it doesn't seem to be called in array context in the for.
Which leads me back to my previous conclusion, that overloading '<>' isn't meant for prime-time.
/s