Subject: | decompose fails on a closure, for loop and until loop |
Devel::Graph version 0.10
The attached file is a test for failure on parsing a closure. Subsequent investigations
have also shown that for and unless loops fail similarly.
The error seems to be in the private method _parse_compound, and is thrown by the
test for 'PPI::Structure::Condition'. Neither a closure nor a loop will satisfy this test.
****
# work around closure bug
return $self->_parse($element->children)
if $type eq 'continue';
return $self->_parse_loop($element)
if $type eq 'for' || $type eq 'foreach';
$self->error("Cannot find condition: possible syntax error in $element")
unless defined $self->_find_first( $element, 'PPI::Structure::Condition' );
****
Subject: | closure.t |
#!/usr/bin/perl -w
use Test::More;
use strict;
BEGIN
{
plan tests => 4;
chdir 't' if -d 't';
use lib '../lib';
use_ok ("Devel::Graph") or die($@);
};
#############################################################################
# croak on errors
my $grapher = Devel::Graph->new();
is (ref($grapher), 'Devel::Graph');
my $if_code = <<'IF_CODE';
my $a = 1;
if($a){
my $var = 1;
my $other_var = 2;
my $var_now = $var + $other_var;
print "$var_now\n";
}
IF_CODE
eval "\$grapher->decompose( \\\$if_code )";
is ($@, '', 'if error');
my $closure_code = <<'CLOSURE_CODE';
{
my $var = 1;
my $other_var = 2;
my $var_now = $var + $other_var;
print "$var_now\n";
}
CLOSURE_CODE
eval "\$grapher->decompose( \\\$closure_code )";
is ($@, '', 'closure error');