| 1 | package Vim::X; | ||||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||||
| 3 | 4 | ▶ | $Vim::X::AUTHORITY = 'cpan:YANICK'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | # ABSTRACT: Candy for Perl programming in Vim | ||||||||||||||||||||
| 6 | 4 | $Vim::X::VERSION = '1.1.0'; | |||||||||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | ▶ | use Sub::Attribute; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 4 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 4 | ▶ | use parent 'Exporter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | our @EXPORT = qw/ | |||||||||||||||||||
| 16 | vim_func vim_prefix vim_msg vim_buffer vim_cursor vim_window | ||||||||||||||||||||
| 17 | vim_current_file | ||||||||||||||||||||
| 18 | vim_command | ||||||||||||||||||||
| 19 | vim_expand | ||||||||||||||||||||
| 20 | vim_call | ||||||||||||||||||||
| 21 | vim_lines | ||||||||||||||||||||
| 22 | vim_append | ||||||||||||||||||||
| 23 | vim_eval | ||||||||||||||||||||
| 24 | vim_range | ||||||||||||||||||||
| 25 | vim_line | ||||||||||||||||||||
| 26 | vim_input | ||||||||||||||||||||
| 27 | vim_delete /; | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 4 | ▶ | use Vim::X::Window; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 4 | ▶ | use Vim::X::Buffer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 4 | ▶ | use Vim::X::Cursor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 4 | ▶ | use Vim::X::Line; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | sub import { | ||||||||||||||||||||
| 35 | 3 | ▶ | __PACKAGE__->export_to_level(1, @_); | ||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 3 | my $target_class = caller; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 3 | ▶ | eval <<"END"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | package $target_class; | ||||||||||||||||||||
| 41 | use Sub::Attribute; | ||||||||||||||||||||
| 42 | sub Vim :ATTR_SUB { goto &Vim::X::Vim; } | ||||||||||||||||||||
| 43 | END | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub Vim :ATTR_SUB { | ||||||||||||||||||||
| 48 | 4 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2 | ▶ | my( $class, $sym_ref, undef, undef, $attr_data ) = @_; | ||||||||||||||||||
|
Subroutine
Vim: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | my $name = *{$sym_ref}{NAME}; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | ▶ | my $args = $attr_data =~ 'args' ? '...' : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | my $range = 'range' x ( $attr_data =~ /range/ ); | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 59 | 1 | VIM::DoCommand(<<END); | |||||||||||||||||||
| 60 | function $name($args) $range | ||||||||||||||||||||
| 61 | perl \$Vim::X::RETURN = ${class}::$name( split "\\n", scalar VIM::Eval('a:000')) | ||||||||||||||||||||
| 62 | perl vim_command( "let vimx_return = '\$Vim::X::RETURN'" ) | ||||||||||||||||||||
| 63 | return vimx_return | ||||||||||||||||||||
| 64 | endfunction | ||||||||||||||||||||
| 65 | END | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | return; | |||||||||||||||||||
| 68 | 4 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub load_function_dir { | ||||||||||||||||||||
| 72 | 0 | ▶ | my $dir = shift; | ||||||||||||||||||
|
Subroutine
load_function_dir: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | my @files = <$dir/*.pl>; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | for my $f ( @files ) { | |||||||||||||||||||
| 77 | 0 | my $name = _func_name($f); | |||||||||||||||||||
| 78 | 0 | vim_command( | |||||||||||||||||||
| 79 | "au FuncUndefined $name perl Vim::X::load_function_file('$f')" | ||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub source_function_dir { | ||||||||||||||||||||
| 86 | 0 | ▶ | my $dir = shift; | ||||||||||||||||||
|
Subroutine
source_function_dir: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | my @files = ( <$dir/*.pl>, <$dir/*.pvim> ); | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | for my $f ( @files ) { | |||||||||||||||||||
| 91 | 0 | my $name = _func_name($f); | |||||||||||||||||||
| 92 | 0 | ▶ | vim_command( "source $f" ) if $f =~ /\.pvim$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 0 | vim_command( | |||||||||||||||||||
| 94 | "au FuncUndefined $name perl Vim::X::load_function_file('$f')" | ||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub _func_name { | ||||||||||||||||||||
| 100 | 0 | ▶ | my $name = shift; | ||||||||||||||||||
|
Subroutine
_func_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 101 | 0 | $name =~ s#^.*/##; | |||||||||||||||||||
| 102 | 0 | $name =~ s#\.p(?:l|vim)$##; | |||||||||||||||||||
| 103 | 0 | return $name; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub load_function_file { | ||||||||||||||||||||
| 108 | 0 | ▶ | my $file = shift; | ||||||||||||||||||
|
Subroutine
load_function_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | my $name = _func_name($file); | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | eval "{ package Vim::X::Function::$name;\n" | |||||||||||||||||||
| 113 | . "no warnings;\n" | ||||||||||||||||||||
| 114 | . Path::Tiny::path($file)->slurp | ||||||||||||||||||||
| 115 | . "\n}" | ||||||||||||||||||||
| 116 | ; | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | ▶ | vim_msg( "ERROR: $@" ) if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | return ''; | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 4 | ▶ | unless ( $main::curbuf ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | package | ||||||||||||||||||||
| 126 | VIM; | ||||||||||||||||||||
| 127 | 4 | ▶ | no strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 128 | ▶ | sub AUTOLOAD { | |||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 129 | # warn "calling $AUTOLOAD"; | ||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | sub vim_msg { | ||||||||||||||||||||
| 135 | 0 | ▶ | VIM::Msg( join " ", @_ ); | ||||||||||||||||||
|
Subroutine
vim_msg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | sub vim_prefix { | ||||||||||||||||||||
| 139 | 0 | ▶ | my( $prefix ) = @_; | ||||||||||||||||||
|
Subroutine
vim_prefix: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 0 | $Vim::X::PREFIX = $prefix; | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | sub vim_buffer { | ||||||||||||||||||||
| 146 | 0 | ▶ | my $buf = shift // $::curbuf->Number; | ||||||||||||||||||
|
Subroutine
vim_buffer: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
shift() // $main::curbuf->Number
MC/DC0%0/2
shift() // $main::curbuf->Number
shift()
$main::curbuf->Number
Truth table0%0/3
A // B
A= shift()B= $main::curbuf->Number
| |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 0 | return Vim::X::Buffer->new( index => $buf, _buffer => $::curbuf ); | |||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | sub vim_current_file { | ||||||||||||||||||||
| 153 | 0 | ▶ | my $symbol = '%' . ( ':p' x ! shift ); | ||||||||||||||||||
|
Subroutine
vim_current_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | ▶ | my $r = vim_expand( $symbol ) or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | return Path::Tiny::path( $r ); | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | sub vim_lines { | ||||||||||||||||||||
| 162 | 0 | ▶ | vim_buffer->lines(@_); | ||||||||||||||||||
|
Subroutine
vim_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | sub vim_line { | ||||||||||||||||||||
| 167 | 0 | ▶ | @_ ? vim_buffer->line(shift) : vim_cursor()->line; | ||||||||||||||||||
|
Subroutine
vim_line: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | sub vim_append { | ||||||||||||||||||||
| 172 | 0 | ▶ | vim_cursor()->line->append(@_); | ||||||||||||||||||
|
Subroutine
vim_append: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 173 | } | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | sub vim_eval { | ||||||||||||||||||||
| 177 | 0 | ▶ | my @results = map { scalar VIM::Eval($_) } @_; | ||||||||||||||||||
|
Subroutine
vim_eval: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 178 | 0 | ▶ | return wantarray ? @results : $results[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | sub vim_range { | ||||||||||||||||||||
| 183 | 0 | ▶ | my @range = map { 0 + $_ } @_ == 2 ? @_ | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 184 | : @_ == 1 ? ( @_ ) x 2 | ||||||||||||||||||||
| 185 | 0 | ▶ | : map { vim_eval($_) } qw/ a:firstline a:lastline /; | ||||||||||||||||||
|
Subroutine
vim_range: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 0 | return vim_buffer->range( @range ); | |||||||||||||||||||
| 188 | } | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | sub vim_command { | ||||||||||||||||||||
| 192 | 0 | ▶ | my @results = map { VIM::DoCommand($_) } @_; | ||||||||||||||||||
|
Subroutine
vim_command: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 193 | 0 | ▶ | return wantarray ? @results : $results[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | sub vim_call { | ||||||||||||||||||||
| 198 | 0 | ▶ | my( $func, @args ) = @_; | ||||||||||||||||||
|
Subroutine
vim_call: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 199 | 0 | my $cmd = join ' ', 'call', $func . '(', map( { "'$_'" } @args ), ')'; | |||||||||||||||||||
| 200 | 0 | vim_command( $cmd ); | |||||||||||||||||||
| 201 | } | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | sub vim_expand { | ||||||||||||||||||||
| 205 | 0 | ▶ | my @mapped = map { vim_eval( "expand('$_')" ) } @_; | ||||||||||||||||||
|
Subroutine
vim_expand: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 206 | 0 | ▶ | return wantarray ? @mapped : $mapped[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 207 | } | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | sub vim_input { | ||||||||||||||||||||
| 211 | 0 | ▶ | my @args = @_; | ||||||||||||||||||
|
Subroutine
vim_input: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 212 | 0 | s/"/\\"/g for @args; | |||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 0 | my $args = join ',', map { qq{"$_"} } @args; | |||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | vim_command( "let l = input($args)" ); | |||||||||||||||||||
| 217 | 0 | return vim_eval("l"); | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | sub vim_window { | ||||||||||||||||||||
| 222 | 0 | ▶ | return Vim::X::Window->new( _window => shift || $::curwin); | ||||||||||||||||||
|
Subroutine
vim_window: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
shift() || $main::curwin
MC/DC0%0/2
shift() || $main::curwin
shift()
$main::curwin
Truth table0%0/3
A || B
A= shift()B= $main::curwin
| |||||||||||||||||||||
| 223 | } | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | sub vim_cursor { | ||||||||||||||||||||
| 227 | 0 | ▶ | my $w = vim_window(); | ||||||||||||||||||
|
Subroutine
vim_cursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 228 | 0 | return $w->cursor; | |||||||||||||||||||
| 229 | } | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | sub vim_delete { | ||||||||||||||||||||
| 233 | 0 | ▶ | vim_buffer->delete(@_); | ||||||||||||||||||
|
Subroutine
vim_delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 234 | } | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | 4 | 1; | |||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | __END__ | ||||||||||||||||||||