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
|
|
79730
|
use utf8; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
13
|
|
21
|
3
|
|
|
3
|
|
80
|
use v5.12; |
|
3
|
|
|
|
|
6
|
|
22
|
3
|
|
|
3
|
|
9
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
62
|
|
23
|
3
|
|
|
3
|
|
8
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
64
|
|
24
|
3
|
|
|
3
|
|
360
|
use open qw(:std :utf8); |
|
3
|
|
|
|
|
780
|
|
|
3
|
|
|
|
|
12
|
|
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
3
|
|
1999
|
use Text::Frundis::Processing; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
87
|
|
27
|
3
|
|
|
3
|
|
13
|
use Carp; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
1333
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = "2.15"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
3
|
|
|
3
|
0
|
1236
|
my $class = shift; |
33
|
3
|
|
|
|
|
5
|
my $self = {}; |
34
|
3
|
|
|
|
|
8
|
bless $self, $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub process_source { |
38
|
60
|
|
|
60
|
1
|
60935
|
my ($self, %opts) = @_; |
39
|
|
|
|
|
|
|
|
40
|
60
|
|
100
|
|
|
216
|
$opts{use_carp} //= 1; |
41
|
|
|
|
|
|
|
croak("`target_format' parameter required") |
42
|
|
|
|
|
|
|
unless defined $opts{target_format} |
43
|
60
|
0
|
33
|
|
|
154
|
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
|
|
|
412
|
or not($opts{all_in_one_file} and $opts{target_format} eq "epub"); |
|
|
|
33
|
|
|
|
|
48
|
60
|
50
|
66
|
|
|
278
|
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
|
|
|
360
|
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
|
|
|
|
|
85
|
my $macros = $self->{macros}; |
64
|
60
|
100
|
|
|
|
105
|
if (defined $macros) { |
65
|
1
|
|
|
|
|
2
|
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
|
|
|
|
111
|
if (defined $filters) { |
75
|
1
|
|
|
|
|
2
|
foreach my $filter (keys %$filters) { |
76
|
|
|
|
|
|
|
$opts{filters}{$filter} = { |
77
|
1
|
|
|
|
|
3
|
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
|
6
|
my ($self, $macro, $code) = @_; |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
33
|
|
|
6
|
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
|
|
|
5
|
unless (defined $code and ref($code) eq "CODE") { |
97
|
0
|
|
|
|
|
0
|
carp "a coderef is required"; |
98
|
0
|
|
|
|
|
0
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
6
|
$self->{macros}{$macro} = $code; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_filter { |
105
|
1
|
|
|
1
|
1
|
6
|
my ($self, $tag, $code) = @_; |
106
|
|
|
|
|
|
|
|
107
|
1
|
50
|
33
|
|
|
5
|
unless (defined $tag and $tag ne "") { |
108
|
0
|
|
|
|
|
0
|
carp "undefined tag name"; |
109
|
0
|
|
|
|
|
0
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
1
|
50
|
33
|
|
|
6
|
unless (defined $code and ref($code) eq "CODE") { |
112
|
0
|
|
|
|
|
0
|
carp "a coderef is required"; |
113
|
0
|
|
|
|
|
0
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
3
|
$self->{filters}{$tag} = $code; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |