line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::Utils::Preserve; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
86572
|
use strict; |
|
26
|
|
|
|
|
80
|
|
|
26
|
|
|
|
|
794
|
|
4
|
26
|
|
|
26
|
|
126
|
use warnings; |
|
26
|
|
|
|
|
51
|
|
|
26
|
|
|
|
|
2417
|
|
5
|
|
|
|
|
|
|
|
6
|
26
|
|
|
26
|
|
1904
|
use Class::Utils qw(set_params); |
|
26
|
|
|
|
|
44893
|
|
|
26
|
|
|
|
|
1051
|
|
7
|
26
|
|
|
26
|
|
391
|
use List::Util qw(any); |
|
26
|
|
|
|
|
47
|
|
|
26
|
|
|
|
|
1171
|
|
8
|
26
|
|
|
26
|
|
145
|
use Readonly; |
|
26
|
|
|
|
|
68
|
|
|
26
|
|
|
|
|
13693
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Constants. |
11
|
|
|
|
|
|
|
Readonly::Scalar my $LAST_INDEX => -1; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.14; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constructor. |
16
|
|
|
|
|
|
|
sub new { |
17
|
82
|
|
|
82
|
1
|
5633
|
my ($class, @params) = @_; |
18
|
82
|
|
|
|
|
184
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Preserved tags. |
21
|
82
|
|
|
|
|
231
|
$self->{'preserved'} = []; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Process params. |
24
|
82
|
|
|
|
|
284
|
set_params($self, @params); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Initialization. |
27
|
80
|
|
|
|
|
1045
|
$self->reset; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Object. |
30
|
80
|
|
|
|
|
292
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Process for begin of tag. |
34
|
|
|
|
|
|
|
sub begin { |
35
|
96
|
|
|
96
|
1
|
6194
|
my ($self, $tag) = @_; |
36
|
|
|
|
|
|
|
|
37
|
96
|
|
|
|
|
234
|
$self->save_previous; |
38
|
96
|
100
|
100
|
|
|
135
|
if (scalar @{$self->{'preserved'}} |
|
96
|
|
|
|
|
338
|
|
39
|
17
|
|
|
17
|
|
59
|
&& any { $tag eq $_ } @{$self->{'preserved'}}) { |
|
17
|
|
|
|
|
59
|
|
40
|
|
|
|
|
|
|
|
41
|
8
|
|
|
|
|
13
|
push @{$self->{'preserved_stack'}}, $tag; |
|
8
|
|
|
|
|
19
|
|
42
|
8
|
|
|
|
|
15
|
$self->{'preserved_flag'} = 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Return preserved flags. |
46
|
|
|
|
|
|
|
return wantarray |
47
|
|
|
|
|
|
|
? ($self->{'preserved_flag'}, $self->{'prev_preserved_flag'}) |
48
|
96
|
100
|
|
|
|
314
|
: $self->{'preserved_flag'}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Process for end of tag. |
52
|
|
|
|
|
|
|
sub end { |
53
|
83
|
|
|
83
|
1
|
5861
|
my ($self, $tag) = @_; |
54
|
|
|
|
|
|
|
|
55
|
83
|
|
|
|
|
206
|
$self->save_previous; |
56
|
83
|
|
|
|
|
131
|
my $stack = $self->{'preserved_stack'}; |
57
|
83
|
100
|
100
|
|
|
105
|
if (scalar @{$stack} && $tag eq $stack->[$LAST_INDEX]) { |
|
83
|
|
|
|
|
259
|
|
58
|
6
|
|
|
|
|
11
|
pop @{$stack}; |
|
6
|
|
|
|
|
9
|
|
59
|
6
|
50
|
|
|
|
12
|
if (! scalar @{$stack}) { |
|
6
|
|
|
|
|
15
|
|
60
|
6
|
|
|
|
|
15
|
$self->{'preserved_flag'} = 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Return preserved flags. |
65
|
|
|
|
|
|
|
return wantarray |
66
|
|
|
|
|
|
|
? ($self->{'preserved_flag'}, $self->{'prev_preserved_flag'}) |
67
|
83
|
100
|
|
|
|
284
|
: $self->{'preserved_flag'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Get preserved flag. |
71
|
|
|
|
|
|
|
sub get { |
72
|
89
|
|
|
89
|
1
|
157
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Return preserved flags. |
75
|
|
|
|
|
|
|
return wantarray |
76
|
|
|
|
|
|
|
? ($self->{'preserved_flag'}, $self->{'prev_preserved_flag'}) |
77
|
89
|
100
|
|
|
|
342
|
: $self->{'preserved_flag'}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Resets. |
81
|
|
|
|
|
|
|
sub reset { |
82
|
84
|
|
|
84
|
1
|
3711
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Preserved flag. |
85
|
84
|
|
|
|
|
173
|
$self->{'preserved_flag'} = 0; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Previsous preserved flag. |
88
|
84
|
|
|
|
|
148
|
$self->{'prev_preserved_flag'} = 0; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Preserved tag. |
91
|
84
|
|
|
|
|
184
|
$self->{'preserved_stack'} = []; |
92
|
|
|
|
|
|
|
|
93
|
84
|
|
|
|
|
139
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Save previous stay. |
97
|
|
|
|
|
|
|
sub save_previous { |
98
|
180
|
|
|
180
|
1
|
1248
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
180
|
|
|
|
|
278
|
$self->{'prev_preserved_flag'} = $self->{'preserved_flag'}; |
101
|
|
|
|
|
|
|
|
102
|
180
|
|
|
|
|
254
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |