2009-11-24 04:55:05 -05:00
|
|
|
"============================================================================
|
|
|
|
"File: perl.vim
|
|
|
|
"Description: Syntax checking plugin for syntastic.vim
|
2012-05-31 04:26:08 -04:00
|
|
|
"Maintainer: Anthony Carapetis <anthony.carapetis at gmail dot com>,
|
|
|
|
" Eric Harmon <http://eharmon.net>
|
2009-11-24 04:55:05 -05:00
|
|
|
"License: This program is free software. It comes without any warranty,
|
|
|
|
" to the extent permitted by applicable law. You can redistribute
|
|
|
|
" it and/or modify it under the terms of the Do What The Fuck You
|
|
|
|
" Want To Public License, Version 2, as published by Sam Hocevar.
|
|
|
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
"
|
|
|
|
"============================================================================
|
2012-06-29 19:01:49 -04:00
|
|
|
"
|
2014-03-03 02:43:14 -05:00
|
|
|
" Security:
|
|
|
|
"
|
|
|
|
" This checker runs 'perl -c' against your file, which in turn executes
|
|
|
|
" any BEGIN, UNITCHECK, and CHECK blocks, and any use statements in
|
|
|
|
" your file. This is probably fine if you wrote the file yourself,
|
|
|
|
" but it can be a problem if you're trying to check third party files.
|
|
|
|
" If you are 100% willing to let Vim run the code in your file, set
|
|
|
|
" g:syntastic_enable_perl_checker to 1 in your vimrc to enable this
|
|
|
|
" checker:
|
|
|
|
"
|
|
|
|
" let g:syntastic_enable_perl_checker = 1
|
|
|
|
"
|
|
|
|
" References:
|
|
|
|
"
|
|
|
|
" - http://perldoc.perl.org/perlrun.html#*-c*
|
|
|
|
"
|
2013-09-29 10:29:21 -04:00
|
|
|
" Checker options:
|
2012-06-29 19:01:49 -04:00
|
|
|
"
|
2013-09-29 10:29:21 -04:00
|
|
|
" - g:syntastic_perl_interpreter (string; default: 'perl')
|
|
|
|
" The perl interpreter to use.
|
2012-06-29 19:01:49 -04:00
|
|
|
"
|
2013-09-29 10:29:21 -04:00
|
|
|
" - g:syntastic_perl_lib_path (list; default: [])
|
|
|
|
" List of include directories to be added to the perl command line. Example:
|
2012-08-02 19:25:52 -04:00
|
|
|
"
|
2013-09-29 10:29:21 -04:00
|
|
|
" let g:syntastic_perl_lib_path = [ './lib', './lib/auto' ]
|
2009-11-24 04:55:05 -05:00
|
|
|
|
2013-09-29 10:29:21 -04:00
|
|
|
if exists('g:loaded_syntastic_perl_perl_checker')
|
2013-02-21 10:50:41 -05:00
|
|
|
finish
|
|
|
|
endif
|
2014-03-03 02:43:14 -05:00
|
|
|
let g:loaded_syntastic_perl_perl_checker = 1
|
2013-09-29 10:29:21 -04:00
|
|
|
|
|
|
|
if !exists('g:syntastic_perl_lib_path')
|
|
|
|
let g:syntastic_perl_lib_path = []
|
2013-05-17 12:09:21 -04:00
|
|
|
endif
|
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2013-10-28 11:30:25 -04:00
|
|
|
function! SyntaxCheckers_perl_perl_IsAvailable() dict
|
2014-06-24 12:02:42 -04:00
|
|
|
if !exists('g:syntastic_perl_perl_exec') && exists('g:syntastic_perl_interpreter')
|
|
|
|
let g:syntastic_perl_perl_exec = g:syntastic_perl_interpreter
|
2014-03-03 02:43:14 -05:00
|
|
|
endif
|
|
|
|
|
2013-11-21 01:47:11 -05:00
|
|
|
" don't call executable() here, to allow things like
|
|
|
|
" let g:syntastic_perl_interpreter='/usr/bin/env perl'
|
2014-06-24 12:02:42 -04:00
|
|
|
silent! call system(self.getExecEscaped() . ' -e ' . syntastic#util#shescape('exit(0)'))
|
2013-11-21 01:47:11 -05:00
|
|
|
return v:shell_error == 0
|
2013-01-27 15:08:30 -05:00
|
|
|
endfunction
|
2009-11-24 04:55:05 -05:00
|
|
|
|
2013-10-28 07:53:33 -04:00
|
|
|
function! SyntaxCheckers_perl_perl_GetLocList() dict
|
2014-03-03 02:43:14 -05:00
|
|
|
if !exists('g:syntastic_enable_perl_checker') || !g:syntastic_enable_perl_checker
|
2014-06-24 12:02:42 -04:00
|
|
|
call syntastic#log#error('checker perl/perl: checks disabled for security reasons; ' .
|
|
|
|
\ 'set g:syntastic_enable_perl_checker to 1 to override')
|
2014-03-03 02:43:14 -05:00
|
|
|
return []
|
|
|
|
endif
|
|
|
|
|
2013-09-29 10:29:21 -04:00
|
|
|
if type(g:syntastic_perl_lib_path) == type('')
|
2014-06-24 12:02:42 -04:00
|
|
|
call syntastic#log#oneTimeWarn('variable g:syntastic_perl_lib_path should be a list')
|
2013-09-29 10:29:21 -04:00
|
|
|
let includes = split(g:syntastic_perl_lib_path, ',')
|
|
|
|
else
|
2014-02-12 14:25:51 -05:00
|
|
|
let includes = copy(syntastic#util#var('perl_lib_path'))
|
2013-09-29 10:29:21 -04:00
|
|
|
endif
|
2013-04-15 04:21:52 -04:00
|
|
|
let shebang = syntastic#util#parseShebang()
|
2013-09-29 15:13:36 -04:00
|
|
|
let extra = join(map(includes, '"-I" . v:val')) .
|
|
|
|
\ (index(shebang['args'], '-T') >= 0 ? ' -T' : '') .
|
|
|
|
\ (index(shebang['args'], '-t') >= 0 ? ' -t' : '')
|
2013-10-23 05:59:23 -04:00
|
|
|
let errorformat = '%f:%l:%m'
|
2013-09-29 10:29:21 -04:00
|
|
|
|
2014-06-24 12:02:42 -04:00
|
|
|
let makeprg = self.makeprgBuild({ 'args_before': '-c -X ' . extra })
|
2013-09-29 10:29:21 -04:00
|
|
|
|
|
|
|
let errors = SyntasticMake({
|
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
2014-02-26 03:31:38 -05:00
|
|
|
\ 'preprocess': 'perl',
|
2013-09-29 10:29:21 -04:00
|
|
|
\ 'defaults': {'type': 'E'} })
|
|
|
|
if !empty(errors)
|
|
|
|
return errors
|
2012-12-18 04:35:21 -05:00
|
|
|
endif
|
|
|
|
|
2014-06-24 12:02:42 -04:00
|
|
|
let makeprg = self.makeprgBuild({ 'args_before': '-c -Mwarnings ' . extra })
|
2013-09-29 10:29:21 -04:00
|
|
|
|
|
|
|
return SyntasticMake({
|
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
2014-02-26 03:31:38 -05:00
|
|
|
\ 'preprocess': 'perl',
|
2013-09-29 10:29:21 -04:00
|
|
|
\ 'defaults': {'type': 'W'} })
|
2012-12-18 04:35:21 -05:00
|
|
|
endfunction
|
2013-01-27 15:08:30 -05:00
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'perl',
|
|
|
|
\ 'name': 'perl'})
|
2014-01-03 04:29:08 -05:00
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
|
|
|
" vim: set et sts=4 sw=4:
|