| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::TestBase; |
|
2
|
14
|
|
|
14
|
|
98354
|
use strict; |
|
|
14
|
|
|
|
|
28
|
|
|
|
14
|
|
|
|
|
463
|
|
|
3
|
14
|
|
|
14
|
|
68
|
use warnings; |
|
|
14
|
|
|
|
|
25
|
|
|
|
14
|
|
|
|
|
324
|
|
|
4
|
14
|
|
|
14
|
|
515
|
use 5.008001; |
|
|
14
|
|
|
|
|
53
|
|
|
|
14
|
|
|
|
|
978
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
|
8
|
14
|
|
|
|
|
122
|
rw => [qw/block_delim data_delim block_class/], |
|
9
|
14
|
|
|
14
|
|
15996
|
); |
|
|
14
|
|
|
|
|
23250
|
|
|
10
|
14
|
|
|
14
|
|
1223
|
use Carp (); |
|
|
14
|
|
|
|
|
31
|
|
|
|
14
|
|
|
|
|
280
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
14
|
|
|
14
|
|
10075
|
use Text::TestBase::Block; |
|
|
14
|
|
|
|
|
33
|
|
|
|
14
|
|
|
|
|
13538
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
17
|
|
|
17
|
1
|
764
|
my $class = shift; |
|
16
|
17
|
50
|
|
|
|
102
|
my %args = @_==1 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
17
|
17
|
|
|
|
|
172
|
bless { |
|
18
|
|
|
|
|
|
|
block_delim => '===', |
|
19
|
|
|
|
|
|
|
data_delim => '---', |
|
20
|
|
|
|
|
|
|
block_class => 'Text::TestBase::Block', |
|
21
|
|
|
|
|
|
|
%args, |
|
22
|
|
|
|
|
|
|
}, $class; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub parse { |
|
26
|
16
|
|
|
16
|
1
|
41
|
my ($self, $spec) = @_; |
|
27
|
16
|
|
|
|
|
94
|
my $cd = $self->block_delim; |
|
28
|
16
|
|
|
|
|
187
|
my $lineno = 1; |
|
29
|
16
|
|
|
|
|
31
|
my @hunks; |
|
30
|
|
|
|
|
|
|
|
|
31
|
16
|
|
|
|
|
760
|
$spec =~ s/ |
|
32
|
|
|
|
|
|
|
^(\Q${cd}\E.*?(?=^\Q${cd}\E|\z)) |
|
33
|
|
|
|
|
|
|
| ^([^\n]*\n) |
|
34
|
|
|
|
|
|
|
/ |
|
35
|
287
|
100
|
|
|
|
1227
|
if ($1) { |
|
|
|
50
|
|
|
|
|
|
|
36
|
32
|
|
|
|
|
84
|
push @hunks, $1; |
|
37
|
|
|
|
|
|
|
} elsif ($2) { |
|
38
|
255
|
|
|
|
|
418
|
$lineno++; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
287
|
|
|
|
|
956
|
''; |
|
41
|
|
|
|
|
|
|
/msgxe; |
|
42
|
|
|
|
|
|
|
|
|
43
|
16
|
|
|
|
|
65
|
my @blocks; |
|
44
|
16
|
|
|
|
|
44
|
for my $hunk (@hunks) { |
|
45
|
32
|
|
|
|
|
115
|
push @blocks, $self->_make_block($hunk, $lineno); |
|
46
|
32
|
|
|
|
|
151
|
$hunk =~ s/\n/$lineno++/ge; |
|
|
135
|
|
|
|
|
331
|
|
|
47
|
|
|
|
|
|
|
} |
|
48
|
16
|
|
|
|
|
150
|
return @blocks; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _make_block { |
|
52
|
33
|
|
|
33
|
|
79
|
my ($self, $hunk, $lineno) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
33
|
|
|
|
|
172
|
my $cd = $self->block_delim; |
|
55
|
33
|
|
|
|
|
242
|
my $dd = $self->data_delim; |
|
56
|
33
|
50
|
|
|
|
689
|
$hunk =~ s/\A\Q${cd}\E[ \t]*(.*)\s+// or die; |
|
57
|
33
|
|
|
|
|
99
|
my $name = $1; |
|
58
|
33
|
|
|
|
|
622
|
my @parts = split /^\Q${dd}\E +\(?(\w+)\)? *(.*)?\n/m, $hunk; |
|
59
|
33
|
|
|
|
|
116
|
my $description = shift @parts; |
|
60
|
33
|
|
50
|
|
|
171
|
$description ||= ''; |
|
61
|
33
|
50
|
|
|
|
99
|
unless ($description =~ /\S/) { |
|
62
|
33
|
|
|
|
|
60
|
$description = $name; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
33
|
|
|
|
|
831
|
$description =~ s/\s*\z//; |
|
65
|
33
|
|
|
|
|
162
|
my $block = $self->block_class->new( |
|
66
|
|
|
|
|
|
|
description => $description, |
|
67
|
|
|
|
|
|
|
name => $name, |
|
68
|
|
|
|
|
|
|
_lineno => $lineno, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
33
|
|
|
|
|
92
|
my $filter_map = {}; |
|
72
|
33
|
|
|
|
|
70
|
my $section_order = []; |
|
73
|
33
|
|
|
|
|
147
|
while (@parts) { |
|
74
|
48
|
|
|
|
|
132
|
my ($type, $filters, $value) = splice(@parts, 0, 3); |
|
75
|
48
|
|
|
|
|
157
|
$self->_check_reserved($type); |
|
76
|
48
|
100
|
|
|
|
138
|
$value = '' unless defined $value; |
|
77
|
48
|
100
|
|
|
|
140
|
$filters = '' unless defined $filters; |
|
78
|
48
|
100
|
|
|
|
283
|
if ($filters =~ /:(\s|\z)/) { |
|
79
|
24
|
50
|
|
|
|
115
|
Carp::croak "Extra lines not allowed in '$type' section" |
|
80
|
|
|
|
|
|
|
if $value =~ /\S/; |
|
81
|
24
|
|
|
|
|
171
|
($filters, $value) = split /\s*:(?:\s+|\z)/, $filters, 2; |
|
82
|
24
|
50
|
|
|
|
76
|
$value = '' unless defined $value; |
|
83
|
24
|
|
|
|
|
202
|
$value =~ s/^\s*(.*?)\s*$/$1/; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
48
|
|
|
|
|
202
|
$block->push_section($type, $value, $filters); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
33
|
|
|
|
|
143
|
return $block; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $reserved_section_names = {}; |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
|
|
|
|
|
|
%$reserved_section_names = map { |
|
93
|
|
|
|
|
|
|
($_, 1); |
|
94
|
|
|
|
|
|
|
} keys(%Text::TestBase::Block::), qw( new DESTROY ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
sub _check_reserved { |
|
97
|
48
|
|
|
48
|
|
80
|
my $id = shift; |
|
98
|
48
|
50
|
33
|
|
|
634
|
Carp::croak "'$id' is a reserved name. Use something else.\n" |
|
|
|
|
33
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if $reserved_section_names->{$id} or |
|
100
|
|
|
|
|
|
|
$id =~ /^_/ or $id =~ /^(get_|set_|push_)/; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
|
105
|
|
|
|
|
|
|
__END__ |