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
|
|
2344474
|
use utf8; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
20
|
|
21
|
3
|
|
|
3
|
|
106
|
use v5.12; |
|
3
|
|
|
|
|
11
|
|
22
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
69
|
|
23
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
99
|
|
24
|
3
|
|
|
3
|
|
770
|
use open qw(:std :utf8); |
|
3
|
|
|
|
|
1171
|
|
|
3
|
|
|
|
|
19
|
|
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
3
|
|
3350
|
use Text::Frundis::Processing; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
123
|
|
27
|
3
|
|
|
3
|
|
33
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
2064
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = "2.14"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
3
|
|
|
3
|
0
|
2120
|
my $class = shift; |
33
|
3
|
|
|
|
|
9
|
my $self = {}; |
34
|
3
|
|
|
|
|
11
|
bless $self, $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub process_source { |
38
|
60
|
|
|
60
|
1
|
966231
|
my ($self, %opts) = @_; |
39
|
|
|
|
|
|
|
|
40
|
60
|
|
100
|
|
|
327
|
$opts{use_carp} //= 1; |
41
|
|
|
|
|
|
|
croak("`target_format' parameter required") |
42
|
|
|
|
|
|
|
unless defined $opts{target_format} |
43
|
60
|
0
|
33
|
|
|
264
|
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
|
|
|
735
|
or not($opts{all_in_one_file} and $opts{target_format} eq "epub"); |
|
|
|
33
|
|
|
|
|
48
|
60
|
50
|
66
|
|
|
496
|
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
|
|
|
609
|
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
|
|
|
|
|
130
|
my $macros = $self->{macros}; |
64
|
60
|
100
|
|
|
|
172
|
if (defined $macros) { |
65
|
1
|
|
|
|
|
5
|
foreach my $macro (keys %$macros) { |
66
|
|
|
|
|
|
|
$opts{user_macros}{$macro} = { |
67
|
|
|
|
|
|
|
perl => 1, |
68
|
|
|
|
|
|
|
lnum => 0, |
69
|
1
|
|
|
|
|
8
|
code => $macros->{$macro}, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
60
|
|
|
|
|
126
|
my $filters = $self->{filters}; |
74
|
60
|
100
|
|
|
|
171
|
if (defined $filters) { |
75
|
1
|
|
|
|
|
3
|
foreach my $filter (keys %$filters) { |
76
|
|
|
|
|
|
|
$opts{filters}{$filter} = { |
77
|
1
|
|
|
|
|
5
|
code => $filters->{$filter}, |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
60
|
|
|
|
|
286
|
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
|
|
|
|
5
|
if ($macro =~ /\s/) { |
93
|
0
|
|
|
|
|
0
|
carp "macro name should not contain spaces"; |
94
|
0
|
|
|
|
|
0
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
1
|
50
|
33
|
|
|
10
|
unless (defined $code and ref($code) eq "CODE") { |
97
|
0
|
|
|
|
|
0
|
carp "a coderef is required"; |
98
|
0
|
|
|
|
|
0
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
9
|
$self->{macros}{$macro} = $code; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_filter { |
105
|
1
|
|
|
1
|
1
|
10
|
my ($self, $tag, $code) = @_; |
106
|
|
|
|
|
|
|
|
107
|
1
|
50
|
33
|
|
|
8
|
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
|
|
|
|
|
5
|
$self->{filters}{$tag} = $code; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |