perl.vim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "============================================================================
  2. "File: perl.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  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. " References:
  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
  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
  47. function! SyntaxCheckers_perl_perl_GetLocList() dict
  48. if !exists('g:syntastic_enable_perl_checker') || !g:syntastic_enable_perl_checker
  49. call syntastic#log#error('checker perl/perl: checks disabled for security reasons; ' .
  50. \ 'set g:syntastic_enable_perl_checker to 1 to override')
  51. return []
  52. endif
  53. if type(g:syntastic_perl_lib_path) == type('')
  54. call syntastic#log#oneTimeWarn('variable g:syntastic_perl_lib_path should be a list')
  55. let includes = split(g:syntastic_perl_lib_path, ',')
  56. else
  57. let includes = copy(syntastic#util#var('perl_lib_path'))
  58. endif
  59. let shebang = syntastic#util#parseShebang()
  60. let extra = join(map(includes, '"-I" . v:val')) .
  61. \ (index(shebang['args'], '-T') >= 0 ? ' -T' : '') .
  62. \ (index(shebang['args'], '-t') >= 0 ? ' -t' : '')
  63. let errorformat = '%f:%l:%m'
  64. let makeprg = self.makeprgBuild({ 'args_before': '-c -X ' . extra })
  65. let errors = SyntasticMake({
  66. \ 'makeprg': makeprg,
  67. \ 'errorformat': errorformat,
  68. \ 'preprocess': 'perl',
  69. \ 'defaults': {'type': 'E'} })
  70. if !empty(errors)
  71. return errors
  72. endif
  73. let makeprg = self.makeprgBuild({ 'args_before': '-c -Mwarnings ' . extra })
  74. return SyntasticMake({
  75. \ 'makeprg': makeprg,
  76. \ 'errorformat': errorformat,
  77. \ 'preprocess': 'perl',
  78. \ 'defaults': {'type': 'W'} })
  79. endfunction
  80. call g:SyntasticRegistry.CreateAndRegisterChecker({
  81. \ 'filetype': 'perl',
  82. \ 'name': 'perl'})
  83. let &cpo = s:save_cpo
  84. unlet s:save_cpo
  85. " vim: set sw=4 sts=4 et fdm=marker: