line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Outdent; |
2
|
5
|
|
|
5
|
|
97180
|
use 5.006; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
395
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
$VERSION = 0.01; |
5
|
|
|
|
|
|
|
@EXPORT_OK = qw/ |
6
|
|
|
|
|
|
|
outdent |
7
|
|
|
|
|
|
|
outdent_all |
8
|
|
|
|
|
|
|
outdent_quote |
9
|
|
|
|
|
|
|
expand_leading_tabs |
10
|
|
|
|
|
|
|
/; |
11
|
|
|
|
|
|
|
$EXPORT_TAGS{ALL} = \@EXPORT_OK; |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
192
|
|
14
|
5
|
|
|
5
|
|
33
|
use base 'Exporter'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
6331
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
my $indent_re = qr/^([^\S\n]*(?=\S))/m; |
18
|
|
|
|
|
|
|
sub find_indention { |
19
|
3
|
|
|
3
|
0
|
5
|
my ($str) = @_; |
20
|
|
|
|
|
|
|
|
21
|
3
|
50
|
|
|
|
13
|
return '' if $str !~ /\S/; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
18
|
$str =~ /$indent_re/g; |
24
|
3
|
|
|
|
|
7
|
my $i = $1; |
25
|
3
|
50
|
|
|
|
8
|
return '' if not length $i; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
19
|
while ($str =~ /$indent_re/g) { |
28
|
12
|
|
|
|
|
21
|
my $i2 = $1; |
29
|
12
|
|
|
|
|
48
|
($i) = "$i\n$i2" =~ /^(.*).*\n\1/; |
30
|
12
|
50
|
|
|
|
79
|
return '' if not length $i2; |
31
|
|
|
|
|
|
|
} |
32
|
3
|
|
|
|
|
9
|
return $i; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
my $indent_re = qr/^(?!$)([^\S\n]*)/m; |
38
|
|
|
|
|
|
|
sub find_indention_all { |
39
|
4
|
|
|
4
|
0
|
5
|
my ($str) = @_; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
33
|
$str =~ /$indent_re/g; |
42
|
4
|
|
|
|
|
12
|
my $i = $1; |
43
|
4
|
50
|
|
|
|
9
|
return '' if not length $i; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
22
|
while ($str =~ /$indent_re/g) { |
46
|
25
|
|
|
|
|
42
|
my $i2 = $1; |
47
|
25
|
|
|
|
|
100
|
($i) = "$i\n$i2" =~ /^(.*).*\n\1/; |
48
|
25
|
50
|
|
|
|
190
|
return '' if not length $i2; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
12
|
return $i; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub outdent_all { |
55
|
4
|
|
|
4
|
1
|
1463
|
my ($str) = @_; |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
11
|
my $indent = find_indention_all($str); |
58
|
4
|
|
|
|
|
135
|
$str =~ s/^$indent//gm; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
21
|
return $str; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub outdent { |
64
|
3
|
|
|
3
|
1
|
962
|
my ($str) = @_; |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
9
|
my $indent = find_indention($str); |
67
|
3
|
|
|
|
|
50
|
$str =~ s/^$indent(?=.*?\S)//gm; |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
17
|
return $str; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Removes any leading whitespaces uptil and including the first whitespace. |
73
|
|
|
|
|
|
|
# Removes any trailing whitespaces if they come directly after a newline. |
74
|
|
|
|
|
|
|
# (In this paragraph "whitespace" excludes newline.) |
75
|
|
|
|
|
|
|
sub heredocify { |
76
|
10
|
|
|
10
|
0
|
4802
|
my ($str) = @_; |
77
|
|
|
|
|
|
|
|
78
|
10
|
|
|
|
|
46
|
$str =~ s/^[^\S\n]*\n//; |
79
|
10
|
|
|
|
|
26
|
$str =~ s/^[^\S\n]+\z//m; |
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
30
|
return $str; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
1
|
0
|
sub outdent_quote { outdent(heredocify($_[0])) } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub expand_leading_tabs { |
87
|
1
|
|
|
1
|
1
|
19
|
my ($tabstop, $str) = @_; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
10
|
1 while $str =~ s{ |
90
|
|
|
|
|
|
|
^ ([^\S\t\n]*?) (\t+) |
91
|
|
|
|
|
|
|
}{ |
92
|
8
|
|
|
|
|
63
|
$1 . ' ' x ($tabstop * length($2) - length($1) % $tabstop) |
93
|
|
|
|
|
|
|
}gemx; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
8
|
return $str; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |