perl.vim 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. let buf = bufnr('')
  49. if type(g:syntastic_perl_lib_path) == type('')
  50. call syntastic#log#oneTimeWarn('variable g:syntastic_perl_lib_path should be a list')
  51. let includes = split(g:syntastic_perl_lib_path, ',')
  52. else
  53. let includes = copy(syntastic#util#bufVar(buf, 'perl_lib_path', []))
  54. endif
  55. let shebang = syntastic#util#parseShebang(buf)
  56. let extra = map(includes, '"-I" . v:val') +
  57. \ (index(shebang['args'], '-T') >= 0 ? ['-T'] : []) +
  58. \ (index(shebang['args'], '-t') >= 0 ? ['-t'] : [])
  59. let errorformat = '%f:%l:%m'
  60. let makeprg = self.makeprgBuild({ 'args_before': ['-c', '-X '] + extra })
  61. let errors = SyntasticMake({
  62. \ 'makeprg': makeprg,
  63. \ 'errorformat': errorformat,
  64. \ 'preprocess': 'perl',
  65. \ 'defaults': {'type': 'E'} })
  66. if !empty(errors)
  67. return errors
  68. endif
  69. let makeprg = self.makeprgBuild({ 'args_before': ['-c', '-Mwarnings'] + extra })
  70. return SyntasticMake({
  71. \ 'makeprg': makeprg,
  72. \ 'errorformat': errorformat,
  73. \ 'preprocess': 'perl',
  74. \ 'defaults': {'type': 'W'} })
  75. endfunction " }}}1
  76. call g:SyntasticRegistry.CreateAndRegisterChecker({
  77. \ 'filetype': 'perl',
  78. \ 'name': 'perl',
  79. \ 'enable': 'enable_perl_checker'})
  80. let &cpo = s:save_cpo
  81. unlet s:save_cpo
  82. " vim: set sw=4 sts=4 et fdm=marker: