| 1 | package Vim::X::Line; | ||||||||||||||
| 2 | BEGIN { | ||||||||||||||
| 3 | 5 | ▶ | $Vim::X::Line::AUTHORITY = 'cpan:YANICK'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | } | ||||||||||||||
| 5 | # ABSTRACT: A line in a Vim buffer | ||||||||||||||
| 6 | 5 | $Vim::X::Line::VERSION = '1.1.0'; | |||||||||||||
| 7 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | |||||||||||||||
| 10 | use overload | ||||||||||||||
| 11 | 0 | ▶ | '""' => sub { $_[0]->content }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 12 | 0 | ▶ | 'eq' => sub { $_[0]->content eq $_[1] }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 13 | 0 | ▶ | '<<=' => sub { $_[0]->content( $_[1] ) }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 14 | 0 | ▶ | '0+' => sub { return $_[0]->index }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 15 | 0 | ▶ | '+' => sub { return $_[0]->index + $_[1] }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 16 | '<=>' => sub { | ||||||||||||||
| 17 | 0 | ▶ | return $_[0]->index <=> (ref $_[1] ? $_[1]->index : $_[1]) | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 18 | }, | ||||||||||||||
| 19 | 5 | ▶ | ; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | |||||||||||||||
| 22 | |||||||||||||||
| 23 | 5 | has buffer => ( | |||||||||||||
| 24 | is => 'ro', | ||||||||||||||
| 25 | required => 1, | ||||||||||||||
| 26 | ); | ||||||||||||||
| 27 | |||||||||||||||
| 28 | |||||||||||||||
| 29 | 5 | has 'index' => ( | |||||||||||||
| 30 | is => 'rw', | ||||||||||||||
| 31 | required => 1, | ||||||||||||||
| 32 | ); | ||||||||||||||
| 33 | |||||||||||||||
| 34 | |||||||||||||||
| 35 | sub clone { | ||||||||||||||
| 36 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 37 | 0 | return Vim::X::Line->new( buffer => $self->buffer, index => $self->index ); | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | |||||||||||||||
| 41 | sub content { | ||||||||||||||
| 42 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
content: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 43 | 0 | ▶ | $self->buffer->set_line( $self->index, map { split "\n" } @_ ) if @_; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | return $self->buffer->lines_content( $self->index ); | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | |||||||||||||||
| 48 | sub append { | ||||||||||||||
| 49 | 0 | ▶ | my( $self, @lines ) = @_; | ||||||||||||
|
Subroutine
append: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 50 | 0 | $self->buffer->append( $self->index, @lines ); | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | |||||||||||||||
| 54 | |||||||||||||||
| 55 | sub dec { | ||||||||||||||
| 56 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
dec: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | return if $self->index == 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | $self->index( $self->index - 1 ); | |||||||||||||
| 61 | 0 | return $self; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | |||||||||||||||
| 65 | sub inc { | ||||||||||||||
| 66 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
inc: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | ▶ | return if $self->index == $self->buffer->size; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | $self->index( $self->index + 1 ); | |||||||||||||
| 71 | 0 | return $self; | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | sub _search { | ||||||||||||||
| 75 | 0 | ▶ | my( $self, $direction, $condition ) = @_; | ||||||||||||
|
Subroutine
_search: not called CC=5 SCAR=34.0
| |||||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | my $target = $self->clone; | |||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | ▶ | my $it = $direction > 0 ? sub { $target->inc } : sub { $target->dec }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | my $cond = $condition; | |||||||||||||
| 82 | 0 | ▶ | $cond = sub { $_[0]->content =~ $condition } if ref $condition eq 'Regexp'; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | $_ = $target; | |||||||||||||
| 85 | 0 | ▶ | $it->() or return until $cond->($target); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | $self->index( $target->index ); | |||||||||||||
| 88 | 0 | return $self; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | |||||||||||||||
| 92 | sub rewind { | ||||||||||||||
| 93 | 0 | ▶ | my( $self, $condition ) = @_; | ||||||||||||
|
Subroutine
rewind: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 94 | |||||||||||||||
| 95 | 0 | return $self->_search(-1,$condition); | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | |||||||||||||||
| 98 | |||||||||||||||
| 99 | |||||||||||||||
| 100 | sub ff { | ||||||||||||||
| 101 | 0 | ▶ | my( $self, $condition ) = @_; | ||||||||||||
|
Subroutine
ff: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 102 | |||||||||||||||
| 103 | 0 | return $self->_search(1,$condition); | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | |||||||||||||||
| 106 | sub map { | ||||||||||||||
| 107 | 0 | ▶ | my( $self, $code ) = @_; | ||||||||||||
|
Subroutine
map: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | $_ = "$self"; | |||||||||||||
| 110 | 0 | my @values = $code->(); | |||||||||||||
| 111 | 0 | $self &= $values[0]; | |||||||||||||
| 112 | |||||||||||||||
| 113 | } | ||||||||||||||
| 114 | |||||||||||||||
| 115 | 5 | 1; | |||||||||||||
| 116 | |||||||||||||||
| 117 | __END__ | ||||||||||||||