Diff
1diff --git a/plugins/perl/README.md b/plugins/perl/README.md
2index dd9b7dc75392d155674f5dd669f9db40d0b09a9d..a387455c172a531a8af144140c03b79d5e73c5a3 100644
3--- a/plugins/perl/README.md
4+++ b/plugins/perl/README.md
5@@ -8,30 +8,36 @@ To use it, add `perl` to the plugins array in your zshrc file:
6 plugins=(... perl)
7 ```
8
9+## Perlbrew activation
10+
11+If the plugin detects that `perlbrew` hasn't been activated, yet there is an installation of it in
12+`$PERLBREW_ROOT`, it'll initialize by default. To avoid this behaviour, set `ZSH_PERLBREW_ACTIVATE=false`
13+before `source oh-my-zsh.sh` in your zshrc.
14+
15 ## Aliases
16
17-| Aliases | Command | Description |
18-| :------------ | :----------------- | :------------------------------------- |
19-| pbi | `perlbrew install` | Install specific perl version |
20-| pbl | `perlbrew list` | List all perl version installed |
21-| pbo | `perlbrew off` | Go back to the system perl |
22-| pbs | `perlbrew switch` | Turn it back on |
23-| pbu | `perlbrew use` | Use specific version of perl |
24-| pd | `perldoc` | Show the perl documentation |
25-| ple | `perl -wlne` | Use perl like awk/sed |
26-| latest-perl | `curl ...` | Show the latest stable release of Perl |
27+| Aliases | Command | Description |
28+| :---------- | :----------------- | :------------------------------------- |
29+| pbi | `perlbrew install` | Install specific perl version |
30+| pbl | `perlbrew list` | List all perl version installed |
31+| pbo | `perlbrew off` | Go back to the system perl |
32+| pbs | `perlbrew switch` | Turn it back on |
33+| pbu | `perlbrew use` | Use specific version of perl |
34+| pd | `perldoc` | Show the perl documentation |
35+| ple | `perl -wlne` | Use perl like awk/sed |
36+| latest-perl | `curl ...` | Show the latest stable release of Perl |
37
38 ## Functions
39
40-* `newpl`: creates a basic Perl script file and opens it with $EDITOR.
41+- `newpl`: creates a basic Perl script file and opens it with $EDITOR.
42
43-* `pgs`: Perl Global Substitution: `pgs <find_pattern> <replace_pattern> <filename>`
44- Looks for `<find_pattern>` and replaces it with `<replace_pattern>` in `<filename>`.
45+- `pgs`: Perl Global Substitution: `pgs <find_pattern> <replace_pattern> <filename>` Looks for
46+ `<find_pattern>` and replaces it with `<replace_pattern>` in `<filename>`.
47
48-* `prep`: Perl grep, because 'grep -P' is terrible: `prep <pattern> [<filename>]`
49- Lets you work with pipes or files (if no `<filename>` provided, use stdin).
50+- `prep`: Perl grep, because 'grep -P' is terrible: `prep <pattern> [<filename>]` Lets you work with pipes or
51+ files (if no `<filename>` provided, use stdin).
52
53 ## Requirements
54
55-In order to make this work, you will need to have perl installed.
56-More info on the usage and install: https://www.perl.org/get.html
57+In order to make this work, you will need to have perl installed. More info on the usage and install:
58+https://www.perl.org/get.html
59diff --git a/plugins/perl/perl.plugin.zsh b/plugins/perl/perl.plugin.zsh
60index 678e88d9745141e3c6189bcb828a66ecde870696..137fa252a32b5c36d2de58c98665ac61de6918ee 100644
61--- a/plugins/perl/perl.plugin.zsh
62+++ b/plugins/perl/perl.plugin.zsh
63@@ -54,3 +54,12 @@ pgs() { # [find] [replace] [filename]
64 prep() { # [pattern] [filename unless STDOUT]
65 perl -nle 'print if /'"$1"'/;' $2
66 }
67+
68+# If the 'perlbrew' function isn't defined, perlbrew isn't setup.
69+if [[ $ZSH_PERLBREW_ACTIVATE != false ]] && (( ! $+functions[perlbrew] )); then
70+ local _perlbrew="${PERLBREW_ROOT:-${HOME}/perl5/perlbrew}"
71+ if [[ -f "${_perlbrew}/etc/bashrc" ]]; then
72+ source "${_perlbrew}/etc/bashrc"
73+ fi
74+ unset _perlbrew
75+fi