line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2014, 2015 Yon |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Permission to use, copy, modify, and distribute this software for any |
4
|
|
|
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above |
5
|
|
|
|
|
|
|
# copyright notice and this permission notice appear in all copies. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
8
|
|
|
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9
|
|
|
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
10
|
|
|
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
11
|
|
|
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
12
|
|
|
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
13
|
|
|
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# vim:sw=4:sts=4:expandtab |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Text::Frundis; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# as in the perlunicook |
20
|
3
|
|
|
3
|
|
80288
|
use utf8; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
13
|
|
21
|
3
|
|
|
3
|
|
93
|
use v5.12; |
|
3
|
|
|
|
|
7
|
|
22
|
3
|
|
|
3
|
|
8
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
50
|
|
23
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
69
|
|
24
|
3
|
|
|
3
|
|
378
|
use open qw(:std :utf8); |
|
3
|
|
|
|
|
844
|
|
|
3
|
|
|
|
|
13
|
|
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
3
|
|
2058
|
use Text::Frundis::Processing; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
97
|
|
27
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1300
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = "2.16"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
3
|
|
|
3
|
0
|
1300
|
my $class = shift; |
33
|
3
|
|
|
|
|
7
|
my $self = {}; |
34
|
3
|
|
|
|
|
10
|
bless $self, $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub process_source { |
38
|
60
|
|
|
60
|
1
|
100656
|
my ($self, %opts) = @_; |
39
|
|
|
|
|
|
|
|
40
|
60
|
|
100
|
|
|
186
|
$opts{use_carp} //= 1; |
41
|
|
|
|
|
|
|
croak("`target_format' parameter required") |
42
|
|
|
|
|
|
|
unless defined $opts{target_format} |
43
|
60
|
0
|
33
|
|
|
133
|
or $opts{script}; |
44
|
|
|
|
|
|
|
carp( |
45
|
|
|
|
|
|
|
"`all_in_one_file' parameter doesn't make sense when exporting to epub") |
46
|
|
|
|
|
|
|
unless $opts{script} |
47
|
60
|
50
|
66
|
|
|
427
|
or not($opts{all_in_one_file} and $opts{target_format} eq "epub"); |
|
|
|
33
|
|
|
|
|
48
|
60
|
50
|
66
|
|
|
256
|
if ( not $opts{script} |
|
|
|
66
|
|
|
|
|
49
|
|
|
|
|
|
|
and $opts{target_format} eq "epub" |
50
|
|
|
|
|
|
|
and not defined $opts{output_file}) |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
|
|
0
|
croak "when exporting to epub the ``output_file'' parameter is mandatory"; |
53
|
|
|
|
|
|
|
} |
54
|
60
|
50
|
66
|
|
|
321
|
if ( not $opts{script} |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
55
|
|
|
|
|
|
|
and $opts{target_format} eq "xhtml" |
56
|
|
|
|
|
|
|
and not $opts{all_in_one_file} |
57
|
|
|
|
|
|
|
and not defined $opts{output_file}) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
0
|
croak "when exporting to xhtml, unless ``all_in_one_file'' is specified, " |
60
|
|
|
|
|
|
|
. "``output_file'' is mandatory"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
60
|
|
|
|
|
80
|
my $macros = $self->{macros}; |
64
|
60
|
100
|
|
|
|
92
|
if (defined $macros) { |
65
|
1
|
|
|
|
|
4
|
foreach my $macro (keys %$macros) { |
66
|
|
|
|
|
|
|
$opts{user_macros}{$macro} = { |
67
|
|
|
|
|
|
|
perl => 1, |
68
|
|
|
|
|
|
|
lnum => 0, |
69
|
1
|
|
|
|
|
5
|
code => $macros->{$macro}, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
60
|
|
|
|
|
65
|
my $filters = $self->{filters}; |
74
|
60
|
100
|
|
|
|
82
|
if (defined $filters) { |
75
|
1
|
|
|
|
|
3
|
foreach my $filter (keys %$filters) { |
76
|
|
|
|
|
|
|
$opts{filters}{$filter} = { |
77
|
1
|
|
|
|
|
2
|
code => $filters->{$filter}, |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
60
|
|
|
|
|
171
|
Text::Frundis::Processing::process_frundis_source(\%opts); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub add_macro { |
86
|
1
|
|
|
1
|
1
|
10
|
my ($self, $macro, $code) = @_; |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
33
|
|
|
9
|
unless (defined $macro and $macro ne "") { |
89
|
0
|
|
|
|
|
0
|
carp "undefined macro name"; |
90
|
0
|
|
|
|
|
0
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
1
|
50
|
|
|
|
6
|
if ($macro =~ /\s/) { |
93
|
0
|
|
|
|
|
0
|
carp "macro name should not contain spaces"; |
94
|
0
|
|
|
|
|
0
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
1
|
50
|
33
|
|
|
7
|
unless (defined $code and ref($code) eq "CODE") { |
97
|
0
|
|
|
|
|
0
|
carp "a coderef is required"; |
98
|
0
|
|
|
|
|
0
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
10
|
$self->{macros}{$macro} = $code; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_filter { |
105
|
1
|
|
|
1
|
1
|
9
|
my ($self, $tag, $code) = @_; |
106
|
|
|
|
|
|
|
|
107
|
1
|
50
|
33
|
|
|
7
|
unless (defined $tag and $tag ne "") { |
108
|
0
|
|
|
|
|
0
|
carp "undefined tag name"; |
109
|
0
|
|
|
|
|
0
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
1
|
50
|
33
|
|
|
10
|
unless (defined $code and ref($code) eq "CODE") { |
112
|
0
|
|
|
|
|
0
|
carp "a coderef is required"; |
113
|
0
|
|
|
|
|
0
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
4
|
$self->{filters}{$tag} = $code; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |