Subject: | PPI::Statement::Compound->type() for "for (@list)" |
The doc for "PPI::Statement::Compound" says:
type
The "type" method returns the fundamental type of the com
pound statement.
[snip]
Returns the simple string if, for or while, or
"undef" if the type cannot be determined.
However, the following perl script
#!/usr/bin/perl -w
use Test::More tests => 2;
use strict;
use PPI;
my $code = 'for (@list) { $i++; }';
my $doc = PPI::Document->new(\$code);
my $loop = $doc->{children}->[0];
is ($loop->type(), 'for', 'for my $i');
$code = 'for my $i (@list) { $i++; }';
$doc = PPI::Document->new(\$code);
$loop = $doc->{children}->[0];
is ($loop->type(), 'for', 'for my $i');
prints:
1..2
ok 1 - for my $i
not ok 2 - for my $i
# Failed test 'for my $i'
# in c.pl at line 17.
# got: 'foreach'
# expected: 'for'
# Looks like you failed 1 test of 2.
e.g. type() returns 'foreach', and not 'for'. Who is right, the doc or the code?
Best wishes,
Tels