line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Book::Collate::Book; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
14
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
853
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Book |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.0.1 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = 'v0.0.1'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Book object |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Book; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $book = Book->new( |
28
|
|
|
|
|
|
|
title => 'Al rescues the universe again', |
29
|
|
|
|
|
|
|
author => 'Leam Hall', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Initializes with a data hash consisiting of title and author. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
0
|
|
|
0
|
1
|
|
my ( $class, %data ) = @_; |
43
|
|
|
|
|
|
|
bless { |
44
|
|
|
|
|
|
|
_author => $data{author}, |
45
|
|
|
|
|
|
|
_blurb_file => $data{blurb_file}, |
46
|
|
|
|
|
|
|
_book_dir => $data{book_dir}, |
47
|
|
|
|
|
|
|
_file_name => $data{file_name}, |
48
|
|
|
|
|
|
|
_image => $data{image}, |
49
|
|
|
|
|
|
|
_output_dir => $data{output_dir}, |
50
|
|
|
|
|
|
|
_report_dir => $data{report_dir}, |
51
|
|
|
|
|
|
|
_sections => [], |
52
|
|
|
|
|
|
|
_title => $data{title}, |
53
|
|
|
|
|
|
|
_url => $data{url}, |
54
|
0
|
|
|
|
|
|
}, $class; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 add_section |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Appends a section object to the internal list of sections. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_section { |
64
|
0
|
|
|
0
|
1
|
|
my ($self, $section) = @_; |
65
|
0
|
|
|
|
|
|
push(@{$self->sections}, $section); |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 author |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns the author. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
1
|
|
sub author { $_[0]->{_author} }; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 blurb |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Returns the blurb. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub blurb { |
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
85
|
0
|
|
|
|
|
|
my $file; |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
|
|
|
local $/; |
|
0
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
open my $fh, '<', $self->{_blurb_file} or die "Can't open blurb file: $!"; |
89
|
0
|
|
|
|
|
|
$file = <$fh>; |
90
|
0
|
|
|
|
|
|
chomp($file); |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
return $file; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 book_dir |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Returns the directory for the book project. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
1
|
|
sub book_dir { $_[0]->{_book_dir} }; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 file_name |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns the file portion of the file_name. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
0
|
1
|
|
sub file_name { $_[0]->{_file_name} }; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 image |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the localized path to the image. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
1
|
|
sub image { $_[0]->{_image} }; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 output_dir |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns the directory where the files are written. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
0
|
1
|
|
sub output_dir { $_[0]->{_output_dir} }; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 report_dir |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the directory where reports are written. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
0
|
1
|
|
sub report_dir { $_[0]->{_report_dir} }; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 sections |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns the array of section objects. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
0
|
1
|
|
sub sections { $_[0]->{_sections} }; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 title |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the title. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
1
|
|
sub title { $_[0]->{_title} }; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 url |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Return the URL of the book. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
0
|
1
|
|
sub url { $_[0]->{_url} }; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 write_report |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Writes the report files. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub write_report { |
168
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
169
|
0
|
|
|
|
|
|
my $num = 1; |
170
|
0
|
|
|
|
|
|
foreach my $section ( @{$self->sections} ){ |
|
0
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#my $report_file = $self->book_dir . '/' . $self->report_dir . "/report_${num}.txt"; |
172
|
0
|
|
|
|
|
|
my $report_file = $self->report_dir . "/report_${num}.txt"; |
173
|
0
|
0
|
|
|
|
|
open( my $file, '>', $report_file ) or die "Can't open $report_file: $!"; |
174
|
0
|
|
|
|
|
|
print $file $section->write_report; |
175
|
0
|
|
|
|
|
|
close($file); |
176
|
0
|
|
|
|
|
|
$num += 1; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 write_text |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Writes the text version of the file. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub write_text { |
188
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
189
|
0
|
|
|
|
|
|
my $title = $self->title; |
190
|
|
|
|
|
|
|
#my $text_file = $self->book_dir . '/' . $self->output_dir . '/' . $self->file_name . '.txt'; |
191
|
0
|
|
|
|
|
|
my $text_file = $self->output_dir . '/' . $self->file_name . '.txt'; |
192
|
0
|
|
|
|
|
|
my $section_break = "\n__section_break__\n"; |
193
|
|
|
|
|
|
|
|
194
|
0
|
0
|
|
|
|
|
open( my $file, '>', $text_file) or die "Can't open $text_file: $!"; |
195
|
0
|
|
|
|
|
|
select $file; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
foreach my $section ( @{$self->sections} ) { |
|
0
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
print $section_break; |
199
|
0
|
|
|
|
|
|
printf "Chapter %03d", $section->number(); |
200
|
0
|
|
|
|
|
|
print "\n\n"; |
201
|
0
|
|
|
|
|
|
print $section->header(), "\n\n"; |
202
|
0
|
|
|
|
|
|
print $section->headless_data(), "\n\n"; |
203
|
|
|
|
|
|
|
} |
204
|
0
|
|
|
|
|
|
close($file); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 AUTHOR |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Leam Hall, C<< >> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 BUGS |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Please report any bugs or feature requests to L. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 SUPPORT |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
perldoc lib/Book/Collate/Book.pm |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
You can also look for information at: |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=over 4 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * GitHub Project Page |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Besides Larry Wall, you can blame the folks on IRC Libera#perl for this stuff existing. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This software is Copyright (c) 2021 by Leam Hall. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
This is free software, licensed under: |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
1; # End of Book |