line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Indent; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
83886
|
use strict; |
|
7
|
|
|
|
|
133
|
|
|
7
|
|
|
|
|
207
|
|
4
|
7
|
|
|
7
|
|
50
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
234
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
3318
|
use Class::Utils qw(set_params); |
|
7
|
|
|
|
|
202137
|
|
|
7
|
|
|
|
|
156
|
|
7
|
7
|
|
|
7
|
|
512
|
use Error::Pure qw(err); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
258
|
|
8
|
7
|
|
|
7
|
|
35
|
use Readonly; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
3195
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Constants. |
11
|
|
|
|
|
|
|
Readonly::Scalar my $EMPTY_STR => q{}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.06; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constructor. |
16
|
|
|
|
|
|
|
sub new { |
17
|
16
|
|
|
16
|
1
|
15266
|
my ($class, @params) = @_; |
18
|
16
|
|
|
|
|
42
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Default indent. |
21
|
16
|
|
|
|
|
57
|
$self->{'indent'} = $EMPTY_STR; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Every next indent string. |
24
|
16
|
|
|
|
|
35
|
$self->{'next_indent'} = "\t"; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Process params. |
27
|
16
|
|
|
|
|
68
|
set_params($self, @params); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Check to 'next_indent' parameter. |
30
|
14
|
100
|
|
|
|
155
|
if (! defined $self->{'next_indent'}) { |
31
|
1
|
|
|
|
|
6
|
err "'next_indent' parameter must be defined."; |
32
|
|
|
|
|
|
|
} |
33
|
13
|
100
|
|
|
|
40
|
if (ref $self->{'next_indent'}) { |
34
|
2
|
|
|
|
|
5
|
err "'next_indent' parameter must be a string."; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Check to 'indent' parameter. |
38
|
11
|
100
|
|
|
|
31
|
if (! defined $self->{'indent'}) { |
39
|
1
|
|
|
|
|
4
|
err "'indent' parameter must be defined."; |
40
|
|
|
|
|
|
|
} |
41
|
10
|
100
|
|
|
|
29
|
if (ref $self->{'indent'}) { |
42
|
2
|
|
|
|
|
8
|
err "'indent' parameter must be a string."; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Object. |
46
|
8
|
|
|
|
|
34
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Add an indent to global indent. |
50
|
|
|
|
|
|
|
sub add { |
51
|
7
|
|
|
7
|
1
|
27
|
my ($self, $indent) = @_; |
52
|
7
|
100
|
|
|
|
27
|
if (! defined $indent) { |
53
|
2
|
|
|
|
|
5
|
$indent = $self->{'next_indent'}; |
54
|
|
|
|
|
|
|
} |
55
|
7
|
|
|
|
|
18
|
$self->{'indent'} .= $indent; |
56
|
7
|
|
|
|
|
24
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Get a indent value. |
60
|
|
|
|
|
|
|
sub get { |
61
|
13
|
|
|
13
|
1
|
1323
|
my $self = shift; |
62
|
13
|
|
|
|
|
63
|
return $self->{'indent'}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Remove an indent from global indent. |
66
|
|
|
|
|
|
|
sub remove { |
67
|
3
|
|
|
3
|
1
|
16
|
my ($self, $indent) = @_; |
68
|
3
|
100
|
|
|
|
7
|
if (! defined $indent) { |
69
|
1
|
|
|
|
|
2
|
$indent = $self->{'next_indent'}; |
70
|
|
|
|
|
|
|
} |
71
|
3
|
|
|
|
|
6
|
my $indent_length = length $indent; |
72
|
3
|
100
|
|
|
|
10
|
if (substr($self->{'indent'}, -$indent_length) ne $indent) { |
73
|
1
|
|
|
|
|
10
|
err "Cannot remove indent '$indent'."; |
74
|
|
|
|
|
|
|
} |
75
|
2
|
|
|
|
|
10
|
$self->{'indent'} = substr $self->{'indent'}, 0, -$indent_length; |
76
|
2
|
|
|
|
|
4
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Reseting indent. |
80
|
|
|
|
|
|
|
sub reset { |
81
|
2
|
|
|
2
|
1
|
11
|
my ($self, $reset_value) = @_; |
82
|
2
|
100
|
|
|
|
7
|
if (! defined $reset_value) { |
83
|
1
|
|
|
|
|
2
|
$reset_value = $EMPTY_STR; |
84
|
|
|
|
|
|
|
} |
85
|
2
|
|
|
|
|
5
|
$self->{'indent'} = $reset_value; |
86
|
2
|
|
|
|
|
3
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |