$ops{$_} = 1 for qw/padsv/;
$ops{$_} = 'list' for qw/padav/;
$ops{$_} = 'list' for qw/padhv rv2hv/;
-$ops{$_} = 'list' for qw/padany flip match entereval readline/;
+$ops{$_} = 'list' for qw/padany match entereval readline/;
$ops{each} = { 0 => 0.5, 2 => 0.5 };
$ops{stat} = { 0 => 0.5, 13 => 0.5 };
sub pp_leaveloop { $_[0]->expect_return($_[1]->first->sibling) }
+sub pp_flip {
+ my ($self, $op) = @_;
+
+ $op = $op->first;
+ return 'list' if name($op) ne 'range';
+
+ my $begin = $op->first;
+ if (name($begin) eq 'const') {
+ my $end = $begin->sibling;
+ if (name($end) eq 'const') {
+ $begin = $self->const_sv($begin);
+ $end = $self->const_sv($end);
+ no warnings 'numeric';
+ return int(${$end->object_2svref}) - int(${$begin->object_2svref}) + 1;
+ } else {
+ my ($p, $r) = $self->expect_return($end);
+ return $p => 1 if $r;
+ }
+ } else {
+ my ($p, $r) = $self->expect_return($begin);
+ return $p => 1 if $r;
+ }
+
+ return 'list'
+}
+
=head1 EXPORT
An object-oriented module shouldn't export any function, and so does this one.
use strict;
use warnings;
-use Test::More tests => 50;
+use Test::More tests => 56;
use Sub::Nary;
[ sub { return $x, @a }, 'list' ],
[ sub { return %h, $y }, 'list' ],
- [ sub { return 1 .. 3 }, 'list' ],
+ [ sub { return 1 .. 3 }, 3 ],
+ [ sub { return $x .. 3 }, 'list' ],
+ [ sub { return 1 .. $x }, 'list' ],
+ [ sub { return '2foo' .. 4 }, 3 ],
+ [ sub { my @a = (7, 8); return @a .. 4 }, 'list' ],
+ [ sub { return do { return 1, 2 } .. 3 }, 2 ],
+ [ sub { return 1 .. do { return 2, 3 } }, 2 ],
[ sub { for (1, 2, 3) { return } }, 0 ],
[ sub { for (1, 2, 3) { } return 1, 2; }, 2 ],
use strict;
use warnings;
-use Test::More tests => 36;
+use Test::More tests => 40;
use Sub::Nary;
[ sub { $x, @a }, 'list' ],
[ sub { %h, $y }, 'list' ],
- [ sub { 1 .. 3 }, 'list' ],
- [ sub { my @a = (1 .. 4) }, 4 ],
+ [ sub { 1 .. 3 }, 3 ],
+ [ sub { $x .. 3 }, 'list' ],
+ [ sub { 1 .. $x }, 'list' ],
+ [ sub { '2foo' .. 4 }, 3 ],
+ [ sub { my @a = (7, 8); @a .. 4 }, 'list' ],
+ [ sub { my @a = (1 .. 4) }, 4 ],
[ sub { "banana" =~ /(a)/g }, 'list' ],