blib/lib/Vim/X/Buffer.pm

filter: Statementstmt 20.5% 8 / 39 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 20.0% 2 / 10 Podpod 100% 8 / 8 totaltotal 28.5% 18 / 63 CC 5 SCAR 14.2
CC
5
Cov
18%
lines_content
6.0
delete
6.0
set_line
6.0
CRAP 4.1
« Build ↑ Summary blib/lib/Vim/X.pm »
1 package Vim::X::Buffer;
2 BEGIN {
3 4 ▶ $Vim::X::Buffer::AUTHORITY = 'cpan:YANICK';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 # ABSTRACT: A buffer in Vim
6 4 $Vim::X::Buffer::VERSION = '1.0.1';
7 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 has "index" => (
10 is => 'ro',
11 required => 1,
12 );
13  
14 4 has "_buffer" => (
15 is => 'ro',
16 required => 1,
17 );
18  
19  
20 sub lines_content {
21 0 ▶ my( $self, @lines ) = @_;
Subroutine lines_content: not called CC=2 SCAR=17.9
Pod documented
22 0 @lines = map { $self->_buffer->Get($_) } @lines;
23 0 ▶ return wantarray ? @lines : join "\n", @lines;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
24 }
25  
26  
27 sub append {
28 0 ▶ my( $self, $index, @lines ) = @_;
Subroutine append: not called CC=1 SCAR=6.9
Pod documented
29 0 $self->_buffer->Append( $index, map { split "\n" } @lines );
30 }
31  
32  
33 sub delete {
34 0 ▶ my ( $self, @lines ) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
35 0 my %seen;
36 0 @lines = sort { $a <=> $b } grep { !$seen{$_}++ } map { 0+$_ } @lines;
37  
38 0 for my $r ( reverse @lines ) {
39 0 $self->_buffer->Delete( $r );
40 }
41 }
42  
43  
44 sub line {
45 0 ▶ my ( $self, $nbr ) = @_;
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
46  
47 0 return Vim::X::Line->new( buffer => $self, index => $nbr );
48 }
49  
50  
51 sub set_line {
52 0 ▶ my( $self, $i, @content ) = @_;
Subroutine set_line: not called CC=2 SCAR=17.9
Pod documented
53 0 $self->_buffer->Set($i => shift @content);
54 0 ▶ $self->append( $i => @content ) if @content;
Branch: 1 branch
BranchTrueFalseTotal
if @content 0 0 0
55 }
56  
57  
58 sub lines {
59 0 ▶ my $self = shift;
Subroutine lines: not called CC=2 SCAR=17.9
Pod documented
60 0 my @lines = @_;
61 0 ▶ unless(@lines) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@lines) 0 0 0
62 0 @lines = 1..$self->size;
63 }
64  
65 0 @lines = map { Vim::X::Line->new( buffer => $self, index => $_ ) } @lines;
66 0 return @lines;
67 }
68  
69  
70 sub size {
71 0 ▶ my $self = shift;
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
72 0 $self->_buffer->Count;
73 }
74  
75  
76 sub range {
77 0 ▶ require Vim::X::Range;
Subroutine range: not called CC=1 SCAR=6.9
Pod documented
78 0 return Vim::X::Range->new(
79 _buffer => $_[0],
80 from => $_[1],
81 to => $_[2]
82 );
83 }
84  
85 4 1;
86  
87 __END__
88  
89 =pod
90  
91 =encoding UTF-8
92  
93 =head1 NAME
94  
95 Vim::X::Buffer - A buffer in Vim
96  
97 =head1 VERSION
98  
99 version 1.0.1
100  
101 =head1 FUNCTIONS
102  
103 =head2 lines_content( @indexes )
104  
105 Returns the content of the lines given by I<@indexes>.
106  
107 If invoked in scalar context, the lines will be joined together with carriage
108 returns.
109  
110 =head2 append($index, @lines)
111  
112 Appends the I<@lines> after the given I<$index>.
113  
114 If the lines contain carriage returns, they will be properly
115 splitted.
116  
117 =head2 delete( @indexes )
118  
119 Deletes the provided lines.
120  
121 The lines are automatically filtered for duplicates and deleted in
122 reverse order, so you can safely do
123  
124 vim_buffer->delete( 1..5, 5..6 );
125  
126 and things will Just Work(tm).
127  
128 =head2 line($index)
129  
130 Returns the line as a L<Vim::X::Line> object.
131  
132 =head2 set_line( $index, $content )
133  
134 Sets the content of the line.
135  
136 =head2 lines( @indexes )
137  
138 Returns the lines given as L<Vim::X::Line> objects. If no indexes are
139 provided, returns all the lines of the buffer.
140  
141 =head2 size()
142  
143 Returns the number of lines in the buffer.
144  
145 =head2 range( $from, $to )
146  
147 Returns the L<Vim::X::Range> object for the given range of lines.
148  
149 =head1 AUTHOR
150  
151 Yanick Champoux <yanick@cpan.org>
152  
153 =head1 COPYRIGHT AND LICENSE
154  
155 This software is copyright (c) 2014 by Yanick Champoux.
156  
157 This is free software; you can redistribute it and/or modify it under
158 the same terms as the Perl 5 programming language system itself.
159  
160 =cut
« Build ↑ Summary blib/lib/Vim/X.pm »