1#compdef perl
2#
3# zsh completion code for the Perl interpreter
4# Adam Spiers <adam@spiers.net>
5#
6# Completions currently based on Perl 5.14.1.
7
8_perl () {
9  _arguments -s \
10    '-0-[input record separator ($/)]:$/ in octal or hex (\0, if no argument)' \
11    '-a[autosplit mode with -n or -p (splits $_ into @F)]' \
12    '-C-[control some unicode features]: :_perl_unicode_flags' \
13    "-c[check syntax only (runs BEGIN and END blocks)]" \
14    '(   -dt -d: -dt:)-d[run scripts under debugger]' \
15    '(-d     -d: -dt:)-dt[run scripts under debugger (debugged code uses threads)]' \
16    '(-d -dt     -dt:)-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules --strip-prefix --perl-hierarchy=Devel' \
17    '(-d -dt -d:     )-dt\:-[run under control of a debugging/tracing module (debugged coded uses threads)]:debugging/tracing module:_perl_modules --strip-prefix --perl-hierarchy=Devel' \
18    '-D-[set debugging flags]: :_perl_debugging_flags' \
19    '(   -E)*-e+[run one line of program]:one line of program' \
20    '(-e   )*-E+[like -e but enable all optional features]:one line of program: ' \
21    '-f[disable executing $Config{sitelib}/sitecustomize.pl at startup]' \
22    '-F-[split() pattern for autosplit (-a)]:split() pattern, // is optional' \
23    '-h[list help summary]' \
24    '-i-[edit <> files in place (make backup if extension supplied)]:backup file extension: ' \
25    '*-I-[specify @INC/#include directory (may be used more than once)]:include path:_files -/' \
26    '-l-[enable line ending processing, specifies line terminator]:output record separator in octal: ' \
27    \*{-m,-M}"-[module.. executes \`use/no module...' before executing your script]:module:_perl_m_opt" \
28    "-n[assume 'while (<>) { ... }' loop around your script]" \
29    "-p[assume loop like -n but print line also like sed]" \
30    '-P[run script through C preprocessor before compilation (deprecated)]' \
31    "-s[enable some switch parsing for switches after script name]" \
32    "-S[look for the script using PATH environment variable]" \
33    '(   -T)-t[turn on taint checks but only issue warnings]' \
34    '(-t   )-T[turn on taint checks]' \
35    "-u[dump core after parsing script]" \
36    "-U[allow unsafe operations]" \
37    "-v[print version number, patchlevel plus VERY IMPORTANT perl info]" \
38    "-V-[print perl configuration information]:configuration keys:_perl_config_vars" \
39    '(   -W -X)-w[turn warnings on for compilation of your script (recommended)]' \
40    "(-w    -X)-W[enable all warnings (ignores 'no warnings')]" \
41    "(-w -W   )-X[disable all warnings (ignores 'use warnings')]" \
42    '-x-[strip off text before #!perl line and perhaps cd to directory]:directory to cd to:_files -/' \
43    '1:Perl script:_files -/ -g "*.(p[ml]|PL|t)(-.)"' \
44    '*::args: _normal'
45}
46
47_perl_m_opt () {
48  compset -P '-'
49
50  if compset -P '*='; then
51    _message -e module-arguments 'module arguments, comma separated'
52  else
53    _perl_modules -S= -q
54  fi
55}
56
57_perl_config_vars () {
58  if (( ! $+_perl_config_vars )); then
59    _perl_config_vars=( $(perl -MConfig -e 'print join("\n", keys %Config);') )
60  fi
61
62  local add_colon='-P:'
63  compset -P '*:' && add_colon=''
64
65  local delimiter='\ '
66  (( compstate[quoting] )) && delimiter=' '
67
68  compset -P '* ' && compset -q
69  compadd "$expl[@]" $add_colon -S$delimiter -q -a _perl_config_vars
70}
71
72_perl_unicode_flags () {
73  _values -s '' 'unicode bitmask or flags' \
74    'I[  1 STDIN is assumed to be in UTF-8]' \
75    'O[  2 STDOUT will be in UTF-8]' \
76    'E[  4 STDERR will be in UTF-8]' \
77    'S[  7 I + O + E]' \
78    'i[  8 UTF-8 is the default PerlIO layer for input streams]' \
79    'o[ 16 UTF-8 is the default PerlIO layer for output streams]' \
80    'D[ 24 i + o]' \
81    'A[ 32 the @ARGV elements are expected to be strings encoded in UTF-8]' \
82    'L[ 64 make "IOEioA" conditional on the locale environment variables]' \
83    'a[256 set ${^UTF8CACHE} to -1, used for debugging]' \
84}
85
86_perl_debugging_flags () {
87  _values -s '' 'debugging bitmask or flags' \
88    'p[      1 Tokenizing and parsing (with v, displays parse stack)]' \
89    's[      2 Stack snapshots (with v, displays all stacks)]' \
90    'l[      4 Context (loop) stack processing]' \
91    't[      8 Trace execution]' \
92    'o[     16 Method and overloading resolution]' \
93    'c[     32 String/numeric conversions]' \
94    'P[     64 Print profiling info, preprocessor command for -P, source file input state]' \
95    'm[    128 Memory and SV allocation]' \
96    'f[    256 Format processing]' \
97    'r[    512 Regular expression parsing and execution]' \
98    'x[   1024 Syntax tree dump]' \
99    'u[   2048 Tainting checks]' \
100    'U[   4096 Unofficial, User hacking (reserved for private, unreleased use)]' \
101    'H[   8192 Hash dump -- usurps values()]' \
102    'X[  16384 Scratchpad allocation]' \
103    'D[  32768 Cleaning up]' \
104    'S[  66536 Thread synchronization]' \
105    'T[ 131072 Tokenising]' \
106    'R[ 262144 Include reference counts of dumped variables (eg when using -Ds)]' \
107    'J[ 524288 Do not s,t,P-debug (Jump over) opcodes within package DB]' \
108    'v[1048576 Verbose: use in conjunction with other flags]' \
109    'C[2097152 Copy On Write]' \
110    'A[4194304 Consistency checks on internal structures]' \
111    'q[8388608 quiet - currently only suppresses the "EXECUTING" message]' \
112}
113
114_perl "$@"
115