line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Section::Seekable::Writer; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
72566
|
use 5.010001; |
|
2
|
|
|
|
|
18
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use overload |
8
|
2
|
|
|
|
|
13
|
'""' => 'as_string', |
9
|
2
|
|
|
2
|
|
1288
|
; |
|
2
|
|
|
|
|
1036
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
12
|
|
|
|
|
|
|
our $DATE = '2023-03-24'; # DATE |
13
|
|
|
|
|
|
|
our $DIST = 'Data-Section-Seekable'; # DIST |
14
|
|
|
|
|
|
|
our $VERSION = '0.092'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
4
|
|
|
4
|
1
|
1585
|
my $class = shift; |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
16
|
my $self = bless {@_}, $class; |
20
|
4
|
|
|
|
|
16
|
$self->empty; |
21
|
|
|
|
|
|
|
$self->{header} //= sub { |
22
|
4
|
|
|
4
|
|
14
|
my ($self, $name, $content, $extra) = @_; |
23
|
4
|
|
|
|
|
13
|
"### $name ###\n"; |
24
|
4
|
|
100
|
|
|
36
|
}; |
25
|
4
|
|
|
|
|
9
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub empty { |
29
|
4
|
|
|
4
|
1
|
19
|
my $self = shift; |
30
|
4
|
|
|
|
|
72
|
$self->{_toc} = []; |
31
|
4
|
|
|
|
|
11
|
$self->{_content} = ''; |
32
|
4
|
|
|
|
|
10
|
$self->{_part_names} = {}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub header { |
36
|
5
|
|
|
5
|
1
|
14
|
my $self = shift; |
37
|
5
|
100
|
|
|
|
14
|
$self->{header} = $_[0] if @_; |
38
|
5
|
|
|
|
|
19
|
$self->{header}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_part { |
42
|
12
|
|
|
12
|
1
|
479
|
my ($self, $name, $content, $extra) = @_; |
43
|
12
|
100
|
|
|
|
41
|
die "Name cannot be empty" unless length($name); |
44
|
11
|
100
|
|
|
|
67
|
die "Name cannot contain comma/newline" if $name =~ /,|\R/; |
45
|
9
|
100
|
100
|
|
|
39
|
die "Extra cannot contain newline" if defined($extra) && $extra =~ /\R/; |
46
|
|
|
|
|
|
|
|
47
|
8
|
100
|
|
|
|
52
|
die "Duplicate part name '$name'" if $self->{_part_names}{$name}++; |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
|
|
12
|
my $header; |
50
|
7
|
100
|
|
|
|
21
|
if (ref($self->{header}) eq 'CODE') { |
51
|
5
|
|
|
|
|
26
|
$header = $self->{header}->($self, $name, $content, $extra); |
52
|
|
|
|
|
|
|
} else { |
53
|
2
|
|
|
|
|
5
|
$header = $self->{header}; |
54
|
|
|
|
|
|
|
} |
55
|
7
|
50
|
|
|
|
26
|
$self->{_content} .= $header if defined($header); |
56
|
|
|
|
|
|
|
|
57
|
7
|
|
|
|
|
21
|
push @{ $self->{_toc} }, [ |
58
|
|
|
|
|
|
|
$name, |
59
|
7
|
|
|
|
|
12
|
length($self->{_content}), |
60
|
|
|
|
|
|
|
length($content), |
61
|
|
|
|
|
|
|
$extra, |
62
|
|
|
|
|
|
|
]; |
63
|
7
|
|
|
|
|
22
|
$self->{_content} .= $content; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub as_string { |
67
|
4
|
|
|
4
|
1
|
298
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
join( |
70
|
|
|
|
|
|
|
"", |
71
|
|
|
|
|
|
|
"Data::Section::Seekable v1\n", |
72
|
7
|
100
|
|
|
|
79
|
(map {"$_->[0],$_->[1],$_->[2]".(defined($_->[3]) ? ",$_->[3]":"")."\n"} |
73
|
4
|
|
|
|
|
29
|
@{ $self->{_toc} }), |
74
|
|
|
|
|
|
|
"\n", |
75
|
|
|
|
|
|
|
$self->{_content}, |
76
|
4
|
|
|
|
|
9
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
# ABSTRACT: Generate data section with multiple parts |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |