perl.vim 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "============================================================================
  2. "File: perl.vim
  3. "Description: Syntax checking plugin for syntastic
  4. "Maintainer: Anthony Carapetis <anthony.carapetis at gmail dot com>,
  5. " Eric Harmon <http://eharmon.net>
  6. "License: This program is free software. It comes without any warranty,
  7. " to the extent permitted by applicable law. You can redistribute
  8. " it and/or modify it under the terms of the Do What The Fuck You
  9. " Want To Public License, Version 2, as published by Sam Hocevar.
  10. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  11. "
  12. "============================================================================
  13. "
  14. " Security:
  15. "
  16. " This checker runs 'perl -c' against your file, which in turn executes
  17. " any BEGIN, UNITCHECK, and CHECK blocks, and any use statements in
  18. " your file. This is probably fine if you wrote the file yourself,
  19. " but it can be a problem if you're trying to check third party files.
  20. " If you are 100% willing to let Vim run the code in your file, set
  21. " g:syntastic_enable_perl_checker to 1 in your vimrc to enable this
  22. " checker:
  23. "
  24. " let g:syntastic_enable_perl_checker = 1
  25. "
  26. " Reference:
  27. "
  28. " - http://perldoc.perl.org/perlrun.html#*-c*
  29. if exists('g:loaded_syntastic_perl_perl_checker')
  30. finish
  31. endif
  32. let g:loaded_syntastic_perl_perl_checker = 1
  33. if !exists('g:syntastic_perl_lib_path')
  34. let g:syntastic_perl_lib_path = []
  35. endif
  36. let s:save_cpo = &cpo
  37. set cpo&vim
  38. function! SyntaxCheckers_perl_perl_IsAvailable() dict " {{{1
  39. if !exists('g:syntastic_perl_perl_exec') && exists('g:syntastic_perl_interpreter')
  40. let g:syntastic_perl_perl_exec = g:syntastic_perl_interpreter
  41. endif
  42. " don't call executable() here, to allow things like
  43. " let g:syntastic_perl_interpreter='/usr/bin/env perl'
  44. silent! call syntastic#util#system(self.getExecEscaped() . ' -e ' . syntastic#util#shescape('exit(0)'))
  45. return v:shell_error == 0
  46. endfunction " }}}1
  47. function! SyntaxCheckers_perl_perl_GetLocList() dict " {{{1
  48. if type(g:syntastic_perl_lib_path) == type('')
  49. call syntastic#log#oneTimeWarn('variable g:syntastic_perl_lib_path should be a list')
  50. let includes = split(g:syntastic_perl_lib_path, ',')
  51. else
  52. let includes = copy(syntastic#util#var('perl_lib_path', []))
  53. endif
  54. let shebang = syntastic#util#parseShebang()
  55. let extra = map(includes, '"-I" . v:val') +
  56. \ (index(shebang['args'], '-T') >= 0 ? ['-T'] : []) +
  57. \ (index(shebang['args'], '-t') >= 0 ? ['-t'] : [])
  58. let errorformat = '%f:%l:%m'
  59. let makeprg = self.makeprgBuild({ 'args_before': ['-c', '-X '] + extra })
  60. let errors = SyntasticMake({
  61. \ 'makeprg': makeprg,
  62. \ 'errorformat': errorformat,
  63. \ 'preprocess': 'perl',
  64. \ 'defaults': {'type': 'E'} })
  65. if !empty(errors)
  66. return errors
  67. endif
  68. let makeprg = self.makeprgBuild({ 'args_before': ['-c', '-Mwarnings'] + extra })
  69. return SyntasticMake({
  70. \ 'makeprg': makeprg,
  71. \ 'errorformat': errorformat,
  72. \ 'preprocess': 'perl',
  73. \ 'defaults': {'type': 'W'} })
  74. endfunction " }}}1
  75. call g:SyntasticRegistry.CreateAndRegisterChecker({
  76. \ 'filetype': 'perl',
  77. \ 'name': 'perl',
  78. \ 'enable': 'enable_perl_checker'})
  79. let &cpo = s:save_cpo
  80. unlet s:save_cpo
  81. " vim: set sw=4 sts=4 et fdm=marker: