File Coverage

blib/lib/App/EditorTools/Command/InstallVim.pm
Criterion Covered Total %
statement 22 23 95.6
branch 8 10 80.0
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 42 45 93.3


line stmt bran cond sub pod time code
1             package App::EditorTools::Command::InstallVim;
2              
3             # ABSTRACT: Installs vim bindings for App::EditorTools
4              
5 7     7   6658 use strict;
  7         16  
  7         254  
6 7     7   44 use warnings;
  7         17  
  7         247  
7 7     7   1105 use parent 'App::EditorTools::CommandBase::Install';
  7         327  
  7         53  
8              
9             #use App::EditorTools -command;
10 7     7   1531 use File::HomeDir;
  7         8005  
  7         8150  
11             # use IPC::Cmd qw(run);
12              
13             our $VERSION = '1.00';
14              
15 21     21 1 53500 sub command_names { 'install-vim' }
16              
17             sub opt_spec {
18             return (
19 5     5 1 76 [ "local|l", "Install the vim script local for the user (~/.vim/)" ],
20             [ "dest|d=s", "Full path to install the vim script" ],
21             [ "print|p", "Print the vim script to STDOUT" ],
22             [ "dryrun|n", "Print where the vim script would be installed" ],
23             ## [ "global|g", "Install the vim script globally (/usr/share/vim)" ],
24             );
25             }
26              
27             sub validate_args {
28 5     5 1 7378 my ( $self, $opt, $args ) = @_;
29              
30 5 100       39 $self->_confirm_one_opt($opt)
31             or $self->usage_error(
32             "Options --local, --global, --dest and --print cannot be combined");
33              
34 4 100       15 if ( !$opt->{dest} ) {
35 3 50       25 if ( $opt->{global} ) {
    100          
36 0         0 $self->usage_error("--global flag is not implemented");
37             # $opt->{dest} = File::Spec->catfile( $self->_get_vimruntime,
38             # qw(ftplugin perl editortools.vim) );
39              
40             } elsif ( !$opt->{print} ) {
41 2 50       25 $opt->{dest} = File::Spec->catfile(
42             File::HomeDir->my_home,
43             ( $^O eq 'MSWin32' ? 'vimfiles' : '.vim' ),
44             qw(ftplugin perl editortools.vim)
45             );
46             }
47             }
48              
49 4         193 return 1;
50             }
51              
52 1     1   31 sub _script { File::Spec->catfile(qw(vim editortools.vim)) }
53              
54             sub _intro {
55 1     1   10 return <<"END_INTRO";
56             " App::EditorTools::Command::InstallVim generated script
57             " Version: $VERSION
58             END_INTRO
59             }
60              
61             # sub _get_vimruntime {
62             # my $self = shift;
63             #
64             # my $file = 'appeditvim.tmp';
65             # my $cmd = qq{vim -c 'redir > $file' -c 'echomsg \$VIMRUNTIME' -c q};
66             #
67             # run( command => $cmd, verbose => 0, )
68             # or $self->usage_error("Error running vim to find global path");
69             # my $dest = read_file $file
70             # or $self->usage_error("Unable to find global vim path");
71             # unlink $file;
72             #
73             # $dest =~ s{[\n\r]}{}mg;
74             # return $dest;
75             # }
76              
77             # Pod if we add the global option
78             # =item --global
79             # Install the vim script globally. This will put the script in
80             # C or a similar location
81             # for your operating system.
82              
83              
84             1;
85              
86             __END__