File Coverage

blib/lib/App/Rakubrew/Shell/Zsh.pm
Criterion Covered Total %
statement 34 60 56.6
branch 2 8 25.0
condition 0 6 0.0
subroutine 11 18 61.1
pod 0 8 0.0
total 47 100 47.0


line stmt bran cond sub pod time code
1             package App::Rakubrew::Shell::Zsh;
2 1     1   8 use App::Rakubrew::Shell;
  1         3  
  1         62  
3             our @ISA = "App::Rakubrew::Shell";
4 1     1   7 use strict;
  1         2  
  1         27  
5 1     1   5 use warnings;
  1         2  
  1         126  
6 1     1   23 use 5.010;
  1         4  
7              
8 1     1   7 use File::Spec::Functions qw(catfile);
  1         2  
  1         91  
9 1     1   9 use Encode::Locale qw(env);
  1         3  
  1         60  
10              
11 1     1   8 use App::Rakubrew::Variables;
  1         2  
  1         229  
12 1     1   9 use App::Rakubrew::Tools;
  1         3  
  1         117  
13 1     1   9 use App::Rakubrew::VersionHandling;
  1         3  
  1         255  
14 1     1   11 use App::Rakubrew::Build;
  1         2  
  1         938  
15              
16             sub supports_hooking {
17 0     0 0 0 my $self = shift;
18 0         0 1;
19             }
20              
21             sub install_note {
22 1     1 0 904 my $rc_file = qw( .zshenv );
23 1 50       8 if ( exists $ENV{ZDOTDIR} ) {
24 0         0 $rc_file = catfile( env('ZDOTDIR'), $rc_file );
25             }
26              
27 1         5 my $text = <
28             Load $brew_name automatically in `zsh` by adding
29              
30             eval "\$($brew_exec init Zsh)"
31              
32             to ~/$rc_file.
33             This can be easily done using:
34              
35             echo 'eval "\$($brew_exec init Zsh)"' >> ~/$rc_file
36             EOT
37              
38 1 50       6 if ($prefix =~ / /) {
39 0         0 $text .= <
40              
41             =================================== WARNING ==================================
42              
43             rakubrews home directory is currently
44              
45             $prefix
46              
47             That folder contains spaces. This will break building rakudos as the build
48             system currently doesn't work in such a path. You can work around this problem
49             by changing that folder to a directory without spaces. Do so by putting
50              
51             export RAKUBREW_HOME=/some/folder/without/space/rakubrew
52              
53             in your `~/$rc_file` file *before* the `eval` line.
54             EOW
55             }
56 1         25 return $text;
57             }
58              
59             sub get_init_code {
60 0     0 0   my $self = shift;
61 0           my $path = env('PATH');
62 0           $path = $self->clean_path($path);
63 0 0         if (get_brew_mode() eq 'env') {
64 0           my $version = get_global_version();
65 0 0 0       if ($version && $version ne 'system' && !is_version_broken($version)) {
      0        
66 0           $path = join(':', get_bin_paths($version), $path);
67             }
68             }
69             else { # get_brew_mode() eq 'shim'
70 0           $path = join(':', $shim_dir, $path);
71             }
72              
73 0           return <
74             export PATH="$path"
75             $brew_name() {
76             command $brew_exec internal_hooked Zsh "\$@" &&
77             eval "`command $brew_exec internal_shell_hook Zsh post_call_eval "\$@"`"
78             }
79              
80             compctl -K _${brew_name}_completions -x 'p[2] w[1,register]' -/ -- $brew_name
81              
82             _${brew_name}_completions() {
83             local WORDS POS RESULT
84             read -cA WORDS
85             read -cn POS
86             reply=(\$(command $brew_exec internal_shell_hook Zsh completions \$POS \$WORDS))
87             }
88             EOT
89              
90             }
91              
92             sub post_call_eval {
93 0     0 0   my $self = shift;
94 0           $self->print_shellmod_code(@_);
95             }
96              
97             sub get_path_setter_code {
98 0     0 0   my $self = shift;
99 0           my $path = shift;
100 0           return "export PATH=\"$path\"";
101             }
102              
103             sub get_shell_setter_code {
104 0     0 0   my $self = shift;
105 0           my $version = shift;
106 0           return "export $env_var=\"$version\"";
107             }
108              
109             sub get_shell_unsetter_code {
110 0     0 0   my $self = shift;
111 0           return "unset $env_var";
112             }
113              
114             sub completions {
115 0     0 0   my $self = shift;
116 0           my $index = shift;
117 0           say join(' ', $self->get_completions($self->strip_executable($index - 1, @_)));
118             }
119              
120             1;
121