diff --git a/lib/Zarn/Engine/Source_to_Sink.pm b/lib/Zarn/Engine/Source_to_Sink.pm index dc9c714..0d581ac 100644 --- a/lib/Zarn/Engine/Source_to_Sink.pm +++ b/lib/Zarn/Engine/Source_to_Sink.pm @@ -19,9 +19,32 @@ package Zarn::Engine::Source_to_Sink { 'rules=s' => \$rules ); + if ($ast && $rules) { + my @absence = grep { $_->{type} && $_->{type} eq 'absence' } $rules->@*; + for my $rule (@absence) { + my $category = $rule -> {category}; + my $title = $rule -> {name}; + my $message = $rule -> {message}; + foreach my $token ($rule -> {sample} -> @*) { + if ($ast->content() !~ m/$token/xms ) { + push @results, { + category => $category, + title => $title, + message => $message, + line_sink => 'n/a', + rowchar_sink => 'n/a', + line_source => 'n/a', + rowchar_source => 'n/a' + }; + } + } + } + + my @presence = grep { !($_->{type}) || $_->{type} eq 'presence' } $rules->@*; + foreach my $token (@{$ast -> find('PPI::Token') || []}) { - foreach my $rule (@{$rules}) { + foreach my $rule (@presence) { my @sample = $rule -> {sample} -> @*; my $category = $rule -> {category}; my $title = $rule -> {name}; diff --git a/lib/Zarn/Helper/Rules.pm b/lib/Zarn/Helper/Rules.pm index fdfc8d1..b702da1 100644 --- a/lib/Zarn/Helper/Rules.pm +++ b/lib/Zarn/Helper/Rules.pm @@ -19,4 +19,4 @@ package Zarn::Helper::Rules { } } -1; \ No newline at end of file +1; diff --git a/zarn.pl b/zarn.pl index 4ea7a6f..774f237 100755 --- a/zarn.pl +++ b/zarn.pl @@ -56,7 +56,7 @@ sub main { ); if (@analysis) { - $analysis[0]->{'file'} = $file; + map { $_->{file} = $file } @analysis; } push @results, @analysis; @@ -87,4 +87,4 @@ sub main { return 0; } -main(); \ No newline at end of file +main();