line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
14213
|
use 5.10.1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
2
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package String::Nudge; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.1001'; # VERSION |
8
|
|
|
|
|
|
|
# ABSTRACT: Indents all lines in a multi-line string |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
|
|
8
|
use Sub::Exporter::Progressive -setup => { |
11
|
|
|
|
|
|
|
exports => [qw/nudge/], |
12
|
|
|
|
|
|
|
groups => { |
13
|
|
|
|
|
|
|
default => [qw/nudge/], |
14
|
|
|
|
|
|
|
}, |
15
|
1
|
|
|
1
|
|
455
|
}; |
|
1
|
|
|
|
|
798
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub nudge ($;$) { |
18
|
0
|
|
|
0
|
1
|
|
my $first = shift; |
19
|
0
|
|
|
|
|
|
my $second = shift; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $indent = 4; |
22
|
0
|
|
|
|
|
|
my $string; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if(defined $second) { |
25
|
0
|
0
|
0
|
|
|
|
if(int $first eq $first && int $first >= 0) { |
26
|
0
|
|
|
|
|
|
$indent = int $first; |
27
|
0
|
|
|
|
|
|
$string = $second; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
0
|
|
|
|
|
|
warnings::warn(numeric => q{first argument to nudge isn't numeric.}); |
31
|
0
|
|
|
|
|
|
$string = $second; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
0
|
|
|
|
|
|
$string = $first; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
my $nudgement = ' ' x $indent; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$string =~ s{^(?=\V)}{$nudgement}gms; |
41
|
0
|
|
|
|
|
|
$string =~ s{^\h*$}{}gms; |
42
|
0
|
|
|
|
|
|
return $string; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding utf-8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
String::Nudge - Indents all lines in a multi-line string |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 VERSION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Version 0.1001, released 2015-01-17. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use String::Nudge; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub out { |
67
|
|
|
|
|
|
|
print nudge q{ |
68
|
|
|
|
|
|
|
A long |
69
|
|
|
|
|
|
|
text. |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# is exactly the same as |
74
|
|
|
|
|
|
|
sub out { |
75
|
|
|
|
|
|
|
print q{ |
76
|
|
|
|
|
|
|
A long |
77
|
|
|
|
|
|
|
text. |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
String::Nudge provides C<nudge>, a simple function that indents all lines in a multi line string. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head3 nudge $string |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ' hello' |
90
|
|
|
|
|
|
|
my $string = nudge 'hello'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head3 nudge $number_of_spaces, $string |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# ' hello' |
95
|
|
|
|
|
|
|
my $string = nudge 8, 'hello'; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
If C<$number_of_spaces> is not given (or isn't an integer >= 0) its default value is C<4>. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Every line in C<$string> is indented by C<$number_of_spaces>. Lines only consisting of white space is trimmed (but not removed). |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 MORE EXAMPLES |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head3 Usage with L<qi|Syntax::Feature::Qi> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Syntax::Feature::Qi> adds C<qi> and C<qqi> that removes the same amount of leading whitespace as the first (significant) line has from all lines in a string: |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# these three packages are equivalent: |
108
|
|
|
|
|
|
|
package Example::Nudge { |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
use String::Nudge; |
111
|
|
|
|
|
|
|
use syntax 'qi'; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub out { |
114
|
|
|
|
|
|
|
print nudge qi{ |
115
|
|
|
|
|
|
|
sub funcname { |
116
|
|
|
|
|
|
|
print 'stuff'; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
package Example::Q { |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub out { |
124
|
|
|
|
|
|
|
print q{ |
125
|
|
|
|
|
|
|
sub funcname { |
126
|
|
|
|
|
|
|
print 'stuff'; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
package Example::HereDoc { |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub out { |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
(my $text = <<" END") =~ s{^ {8}}{}gm; |
136
|
|
|
|
|
|
|
sub funcname { |
137
|
|
|
|
|
|
|
print 'stuff'; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
END |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
print $text; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head3 Usage with L<qs|Syntax::Feature::Qs> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L<Syntax::Feature::Qs> adds C<qs> and C<qqs> that removes all leading whitespace from all lines in a string: |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# these three packages are equivalent: |
150
|
|
|
|
|
|
|
package Example::Nudge { |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
use String::Nudge; |
153
|
|
|
|
|
|
|
use syntax 'qs'; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub out { |
156
|
|
|
|
|
|
|
print nudge qs{ |
157
|
|
|
|
|
|
|
This is |
158
|
|
|
|
|
|
|
a multi line |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
string. |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
package Example::Q { |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub out { |
167
|
|
|
|
|
|
|
print q{ |
168
|
|
|
|
|
|
|
This is |
169
|
|
|
|
|
|
|
a multi line |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
string. |
172
|
|
|
|
|
|
|
}; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
package Example::HereDoc { |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub out { |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
(my $text = <<" END") =~ s{^ {8}}{}gm; |
180
|
|
|
|
|
|
|
This is |
181
|
|
|
|
|
|
|
a multi line |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
string. |
184
|
|
|
|
|
|
|
END |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
print $text; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SEE ALSO |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over 4 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L<Indent::String> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
L<String::Indent> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L<qi|Syntax::Feature::Qi> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L<qi|Syntax::Feature::Qs> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=back |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 SOURCE |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
L<https://github.com/Csson/p5-String-Nudge> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 HOMEPAGE |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
L<https://metacpan.org/release/String-Nudge> |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHOR |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Erik Carlsson <info@code301.com> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Erik Carlsson. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
229
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |