blib/lib/Text/Editor/Vip/Buffer/Indenter.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 29 / 29 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Text/Editor/Vip/Buffer/Constants.pm ↑ Summary
1  
2 package Text::Editor::Vip::Buffer::Indenter;
3  
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use Carp qw(cluck) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 BEGIN
9 18 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 $VERSION = 0.01;
13 18 @ISA = qw (Exporter);
14 18 @EXPORT = qw ();
15 18 @EXPORT_OK = qw ();
16 18 %EXPORT_TAGS = ();
17 }
18  
19 =head1 NAME
20  
21 Text::Editor::Vip::Buffer::Indenter - Default indentiation plugin and documentation for indentation plugins.
22  
23 =head1 SYNOPSIS
24  
25 Nothing need to be done for using the default indenter. Read on to learn how to define your own indenters.
26  
27 If you have an indenter for any "standard" indentation, please contribute it to VIP.
28  
29 =head1 DESCRIPTION
30  
31 If Vip::Buffer::Insert() or InsertNewLine() is called with a SMART_INDENTATION argument,
32 B<IndentNewLine> is called. This lets you define your own indentation strategy.
33  
34 To define you own indenter, Create a perl module, preferably under Text::Editor::Vip::Buffer::Plugins::Indent::.
35  
36 The module needs a single function B<IndentNewLine>
37  
38 package Text::Editor::Vip::Buffer::Plugins::Indent::MyIndenter ;
39  
40 sub IndentNewLine
41 {
42 # modification position is set at the line to indent
43
44 my $buffer = shift ; # the buffer
45 my $line_index = shift ; # usefull if we indent depending on previous lines
46
47 # code to implement you indenter
48 }
49
50 =head1 USING THE INDENTER
51  
52 use Text::Editor::Vip::Buffer ;
53 my $buffer = new Text::Editor::Vip::Buffer() ;
54
55 $buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Plugins::Indent::MyIndenter') ;
56  
57 =head1 INLINED INDENTERS
58  
59 if you want to play with an indenter but don't want to bother creating a separate file and package.
60  
61 use Text::Editor::Vip::Buffer ;
62 my $buffer = new Text::Editor::Vip::Buffer() ;
63  
64 sub my_indenter
65 {
66 # modification position is set at the line to indent
67
68 my $buffer = shift ; # the buffer
69 my $line_index = shift ; # usefull if we indent depending on previous lines
70
71 $buffer->Insert(' ') ; # silly indentation
72 $buffer->MarkBufferAsEdited() ;
73 }
74  
75 $buffer->ExpandWith('IndentNewLine', \&my_indenter) ;
76 $buffer->Insert("hi\nThere\nWhats\nYour\nName\n") ;
77
78 is($buffer->GetLineText(1), " There", "Same text") ;
79  
80 =head1 AUTHOR
81  
82 Khemir Nadim ibn Hamouda
83 CPAN ID: NKH
84 mailto:nadim@khemir.net
85 http:// no web site
86  
87 =head1 COPYRIGHT
88  
89 This program is free software; you can redistribute
90 it and/or modify it under the same terms as Perl itself.
91  
92 The full text of the license can be found in the
93 LICENSE file included with this module.
94  
95 =cut
96  
97 #-------------------------------------------------------------------------------
98  
99 sub IndentNewLine
100 2159 ▶{
Subroutine IndentNewLine: called CC=1 SCAR=0.0
Pod documented
101  
102 =head2 IndentNewLine
103  
104 Default Line indenter for Vip::Buffer. Does nothing.
105  
106 =cut
107  
108 }
109  
110  
111 #-------------------------------------------------------------------------------
112  
113 18 1;
114  
« blib/lib/Text/Editor/Vip/Buffer/Constants.pm ↑ Summary