| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! /usr/bin/perl -w |
|
2
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
# Text::OutdentEdge. |
|
4
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
5
|
|
|
|
|
|
|
# Mastering programmed by YAMASHINA Hio |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# Copyright 2006 YAMASHINA Hio |
|
8
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
9
|
|
|
|
|
|
|
# $Id: /perl/Text-OutdentEdge/lib/Text/OutdentEdge.pm 252 2006-11-25T09:35:55.628540Z hio $ |
|
10
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
11
|
|
|
|
|
|
|
package Text::OutdentEdge; |
|
12
|
2
|
|
|
2
|
|
48400
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
63
|
|
|
13
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
56
|
|
|
14
|
2
|
|
|
2
|
|
10
|
use base 'Exporter'; |
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
934
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw(xoutdent outdent); |
|
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
24
|
|
|
|
|
|
|
# $out = xoutdent($text); |
|
25
|
|
|
|
|
|
|
# |
|
26
|
|
|
|
|
|
|
sub xoutdent($;$) |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
11
|
|
|
11
|
1
|
1186
|
my $text = shift; |
|
29
|
11
|
|
100
|
|
|
31
|
my $opts = shift || {}; |
|
30
|
11
|
100
|
|
|
|
29
|
defined($opts->{indent}) or $opts->{indent} = qr/[ \t]+/; |
|
31
|
11
|
100
|
|
|
|
30
|
defined($opts->{xchar}) or $opts->{xchar} = qr/\S([ \t]|$)/; |
|
32
|
11
|
100
|
100
|
|
|
34
|
if( !exists($opts->{trim}) || $opts->{trim} ) |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
10
|
|
|
|
|
36
|
$text =~ s/\A\r?\n?//s; |
|
35
|
10
|
|
|
|
|
34
|
$text =~ s/[ \t]+\z//s; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
11
|
|
|
|
|
150
|
$text =~ s/^$opts->{indent}$opts->{xchar}//mg; |
|
38
|
11
|
100
|
|
|
|
26
|
if( $opts->{chomp} ) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
1
|
|
|
|
|
4
|
chomp $text; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
11
|
|
|
|
|
56
|
$text; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
46
|
|
|
|
|
|
|
# $out = outdent($text); |
|
47
|
|
|
|
|
|
|
# $out = outdent($text, qr//); |
|
48
|
|
|
|
|
|
|
# $out = outdent($text, $opts); |
|
49
|
|
|
|
|
|
|
# |
|
50
|
|
|
|
|
|
|
sub outdent($;$) |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
9
|
|
|
9
|
1
|
9966
|
my $text = shift; |
|
53
|
9
|
|
|
|
|
13
|
my $opts = shift; |
|
54
|
9
|
|
|
|
|
11
|
my $re; |
|
55
|
9
|
100
|
100
|
|
|
67
|
if( (ref($opts)||'') eq 'Regexp' ) |
|
56
|
|
|
|
|
|
|
{ |
|
57
|
1
|
|
|
|
|
1
|
$re = $opts; |
|
58
|
1
|
|
|
|
|
3
|
$opts = {}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
9
|
|
100
|
|
|
51
|
$re ||= $opts->{indent}; |
|
61
|
9
|
100
|
|
|
|
19
|
if( !$re ) |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
7
|
|
|
|
|
40
|
my ($len) = sort{ $a<=>$b } map{length($_)} $text =~ /^([ \t]*(?=\S))/gm; |
|
|
9
|
|
|
|
|
17
|
|
|
|
13
|
|
|
|
|
32
|
|
|
64
|
7
|
100
|
|
|
|
68
|
$re = $len ? qr/[ \t]{1,$len}/ : qr//; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
9
|
|
|
|
|
39
|
xoutdent $text, {%$opts, indent=>$re, xchar=>'' }; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
70
|
|
|
|
|
|
|
# End of File. |
|
71
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
72
|
|
|
|
|
|
|
__END__ |