| 1 | package Vim::X::Range; | ||||||||||
| 2 | BEGIN { | ||||||||||
| 3 | 1 | ▶ | $Vim::X::Range::AUTHORITY = 'cpan:YANICK'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: A range of lines in a Vim buffer | ||||||||||
| 6 | 1 | $Vim::X::Range::VERSION = '1.0.1'; | |||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | use overload | ||||||||||
| 10 | '@{}' => sub { | ||||||||||
| 11 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 12 | 0 | return $self->lines; | |||||||||
| 13 | }, | ||||||||||
| 14 | '""' => sub { | ||||||||||
| 15 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 16 | 0 | return join "\n", $self->lines; | |||||||||
| 17 | 1 | ▶ | }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 1 | has [ qw/ from to / ] => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | required => 1, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | 1 | has "_buffer" => ( | |||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | required => 1, | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | sub lines { | ||||||||||
| 34 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
lines: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | 0 | return $self->_buffer->lines( $self->from..$self->to ); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | sub replace { | ||||||||||
| 40 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
replace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | |||||||||||
| 42 | # strinfigy if needed | ||||||||||
| 43 | 0 | my @new = map { split "\n", "$_" } @_; | |||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 0 | $self->_buffer->delete( ($self->from+1)..$self->to ); | |||||||||
| 47 | |||||||||||
| 48 | 0 | $self->to( $self->from + @new -1 ); | |||||||||
| 49 | |||||||||||
| 50 | 0 | $self->_buffer->line($self->from)->content( @new ); | |||||||||
| 51 | |||||||||||
| 52 | 0 | return $self; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | sub from_rewind { | ||||||||||
| 57 | 0 | ▶ | my( $self, $condition ) = @_; | ||||||||
|
Subroutine
from_rewind: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 58 | 0 | my( $from ) = $self->lines; | |||||||||
| 59 | 0 | ▶ | $from->rewind($condition) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | $self->from( 0 + $from ); | |||||||||
| 61 | 0 | return $self->from; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | sub from_ff { | ||||||||||
| 65 | 0 | ▶ | my( $self, $condition ) = @_; | ||||||||
|
Subroutine
from_ff: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 66 | 0 | my( $from ) = $self->lines; | |||||||||
| 67 | 0 | ▶ | $from->ff($condition) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | ▶ | return if $from + 0 > $self->to; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | $self->from( 0 + $from ); | |||||||||
| 70 | 0 | return $self->from; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub to_rewind { | ||||||||||
| 74 | 0 | ▶ | my( $self, $condition ) = @_; | ||||||||
|
Subroutine
to_rewind: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 75 | 0 | my $to = ( $self->lines )[-1]; | |||||||||
| 76 | 0 | ▶ | $to->rewind($condition) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 0 | ▶ | return if $to + 0 < $self->from; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | $self->to( 0 + $to ); | |||||||||
| 79 | 0 | return $self->to; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub to_ff { | ||||||||||
| 83 | 0 | ▶ | my( $self, $condition ) = @_; | ||||||||
|
Subroutine
to_ff: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 84 | 0 | my $to = ( $self->lines )[-1]; | |||||||||
| 85 | 0 | ▶ | $to->ff($condition) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $self->to( 0 + $to ); | |||||||||
| 87 | 0 | return $self->to; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | 1; | |||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | 1 | 1; | |||||||||
| 94 | |||||||||||
| 95 | __END__ | ||||||||||
| 96 | |||||||||||
| 97 | =pod | ||||||||||
| 98 | |||||||||||
| 99 | =encoding UTF-8 | ||||||||||
| 100 | |||||||||||
| 101 | =head1 NAME | ||||||||||
| 102 | |||||||||||
| 103 | Vim::X::Range - A range of lines in a Vim buffer | ||||||||||
| 104 | |||||||||||
| 105 | =head1 VERSION | ||||||||||
| 106 | |||||||||||
| 107 | version 1.0.1 | ||||||||||
| 108 | |||||||||||
| 109 | =head1 DESCRIPTION | ||||||||||
| 110 | |||||||||||
| 111 | Represents a range of lines in a buffer. Note that, just like | ||||||||||
| 112 | for L<Vim::X::Line>, the object stores the indexes of the range, | ||||||||||
| 113 | so if the buffer after the object creation, it'll likely not | ||||||||||
| 114 | operate on the expected lines. Caveat emptor and all that. | ||||||||||
| 115 | |||||||||||
| 116 | =head1 ATTRIBUTES | ||||||||||
| 117 | |||||||||||
| 118 | =head2 from | ||||||||||
| 119 | |||||||||||
| 120 | The first line of the range. | ||||||||||
| 121 | |||||||||||
| 122 | =head2 to | ||||||||||
| 123 | |||||||||||
| 124 | The last line of the range. If not given, defaults to the same | ||||||||||
| 125 | line as 'from'. | ||||||||||
| 126 | |||||||||||
| 127 | =head1 FUNCTIONS | ||||||||||
| 128 | |||||||||||
| 129 | =head2 replace( @new_lines ) | ||||||||||
| 130 | |||||||||||
| 131 | Replaces the lines in the range with the provided new lines. | ||||||||||
| 132 | If the new number of lines differs from the old one, the | ||||||||||
| 133 | C<to> value of the object will be updated in consequence. | ||||||||||
| 134 | |||||||||||
| 135 | Returns itself. | ||||||||||
| 136 | |||||||||||
| 137 | =head1 AUTHOR | ||||||||||
| 138 | |||||||||||
| 139 | Yanick Champoux <yanick@cpan.org> | ||||||||||
| 140 | |||||||||||
| 141 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 142 | |||||||||||
| 143 | This software is copyright (c) 2014 by Yanick Champoux. | ||||||||||
| 144 | |||||||||||
| 145 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 146 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||