1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

Handle perl -T checks

This commit is contained in:
Stig Sandbeck Mathisen 2014-10-05 00:17:23 +02:00
parent 9b01da77ba
commit beca89999e

View file

@ -14,13 +14,14 @@ use vars qw/*name *dir *prune/;
my $num_plugins = 0; my $num_plugins = 0;
sub wanted { sub wanted {
my ( $dev, $ino, $mode, $nlink, $uid, $gid, $interpreter ); my ( $dev, $ino, $mode, $nlink, $uid, $gid, $interpreter, $arguments );
( ( $dev, $ino, $mode, $nlink, $uid, $gid ) = lstat($_) ) ( ( $dev, $ino, $mode, $nlink, $uid, $gid ) = lstat($_) )
&& -f _ && -f _
&& ( $interpreter = hashbang("$_") ) && ( ( $interpreter, $arguments ) = hashbang("$_") )
&& ($interpreter)
&& ++$num_plugins && ++$num_plugins
&& process_file( $_, $name, $interpreter ); && process_file( $_, $name, $interpreter, $arguments );
} }
File::Find::find( { wanted => \&wanted }, 'plugins' ); File::Find::find( { wanted => \&wanted }, 'plugins' );
@ -35,13 +36,16 @@ sub hashbang {
\s* # optional space \s* # optional space
(?:/usr/bin/env\s+)? # optional /usr/bin/env (?:/usr/bin/env\s+)? # optional /usr/bin/env
(?<interpreter>\S+) # interpreter (?<interpreter>\S+) # interpreter
}xm; (?:\s+
(?<arguments>[^\n]*) # optional interpreter arguments
)?
}xms;
return $+{interpreter}; return ($+{interpreter}, $+{arguments});
} }
sub process_file { sub process_file {
my ( $file, $filename, $interpreter ) = @_; my ( $file, $filename, $interpreter, $arguments ) = @_;
use v5.10.1; use v5.10.1;
if ( $interpreter =~ m{/bin/sh} ) { if ( $interpreter =~ m{/bin/sh} ) {
@ -76,8 +80,15 @@ sub process_file {
); );
} }
elsif ( $interpreter =~ m{perl} ) { elsif ( $interpreter =~ m{perl} ) {
my $command;
if ($arguments =~ m{-.*T}mx) {
$command = [ 'perl', '-cwT', $file ];
}
else {
$command = [ 'perl', '-cw', $file ];
}
run_check( run_check(
{ command => [ 'perl', '-cw', $file ], { command => $command,
description => 'perl syntax check', description => 'perl syntax check',
filename => $filename filename => $filename
} }