| 1 | # Copyright (c) 2014, 2015 Yon <anaseto@bardinflor.perso.aquilenet.fr> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use v5.12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use open qw(:std :utf8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use Text::Frundis::Processing; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | our $VERSION = "2.16"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 60 | ▶ | sub process_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_source: called CC=18 SCAR=32.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 60 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 60 | ▶ | $opts{use_carp} //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"use_carp"} //= 1
MC/DC100%1/1
$opts{"use_carp"} //= 1
$opts{"use_carp"}
Truth table100%2/2
A
A= $opts{"use_carp"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | croak("`target_format' parameter required") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | unless defined $opts{target_format} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 60 | ▶ | or $opts{script}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"target_format"} or $opts{"script"}
MC/DC0%0/2
defined $opts{"target_format"} or $opts{"script"}
defined $opts{"target_format"}
$opts{"script"}
Truth table33%1/3
A or B
A= defined $opts{"target_format"}B= $opts{"script"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | carp( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | "`all_in_one_file' parameter doesn't make sense when exporting to epub") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | unless $opts{script} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 60 | ▶ | or not($opts{all_in_one_file} and $opts{target_format} eq "epub"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$opts{"script"} or not $opts{"all_in_one_file"} && $opts{"target_format"} eq "epub"
$opts{'all_in_one_file'} && $opts{'target_format'} eq 'epub'
MC/DC0%0/3
$opts{"script"} or not $opts{"all_in_one_file"} && $opts{"target_format"} eq "epub"
$opts{"script"}
$opts{'all_in_one_file'}
$opts{'target_format'} eq 'epub'
Truth table50%2/4
A or not(B && C)
A= $opts{"script"}B= $opts{'all_in_one_file'}C= $opts{'target_format'} eq 'epub'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 60 | ▶ | if ( not $opts{script} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $opts{"script"} and $opts{"target_format"} eq "epub" and not defined $opts{"output_file"}
not $opts{"script"} and $opts{"target_format"} eq "epub"
MC/DC0%0/3
not $opts{"script"} and $opts{"target_format"} eq "epub" and not defined $opts{"output_file"}
not $opts{"script"}
$opts{"target_format"} eq "epub"
not defined $opts{"output_file"}
Truth table50%2/4
not(A) and B and not(C)
A= not $opts{"script"}B= $opts{"target_format"} eq "epub"C= not defined $opts{"output_file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | and $opts{target_format} eq "epub" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | and not defined $opts{output_file}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | croak "when exporting to epub the ``output_file'' parameter is mandatory"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 60 | ▶ | if ( not $opts{script} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not $opts{"script"} and $opts{"target_format"} eq "xhtml" and not $opts{"all_in_one_file"} and not defined $opts{"output_file"}
not $opts{"script"} and $opts{"target_format"} eq "xhtml" and not $opts{"all_in_one_file"}
not $opts{"script"} and $opts{"target_format"} eq "xhtml"
MC/DC0%0/4
not $opts{"script"} and $opts{"target_format"} eq "xhtml" and not $opts{"all_in_one_file"} and not defined $opts{"output_file"}
not $opts{"script"}
$opts{"target_format"} eq "xhtml"
not $opts{"all_in_one_file"}
not defined $opts{"output_file"}
Truth table60%3/5
not(A) and B and not(C) and not(D)
A= not $opts{"script"}B= $opts{"target_format"} eq "xhtml"C= not $opts{"all_in_one_file"}D= not defined $opts{"output_file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | croak "when exporting to xhtml, unless ``all_in_one_file'' is specified, " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | . "``output_file'' is mandatory"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 60 | my $macros = $self->{macros}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 60 | ▶ | if (defined $macros) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | foreach my $macro (keys %$macros) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $opts{user_macros}{$macro} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | perl => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | lnum => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | code => $macros->{$macro}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 60 | my $filters = $self->{filters}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 60 | ▶ | if (defined $filters) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | foreach my $filter (keys %$filters) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $opts{filters}{$filter} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | code => $filters->{$filter}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 60 | Text::Frundis::Processing::process_frundis_source(\%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | sub add_macro { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_macro: called CC=6 SCAR=25.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my ($self, $macro, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | unless (defined $macro and $macro ne "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $macro and $macro ne ""
MC/DC0%0/2
defined $macro and $macro ne ""
defined $macro
$macro ne ""
Truth table33%1/3
A and B
A= defined $macroB= $macro ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | carp "undefined macro name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | if ($macro =~ /\s/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | carp "macro name should not contain spaces"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | unless (defined $code and ref($code) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $code and ref $code eq "CODE"
MC/DC0%0/2
defined $code and ref $code eq "CODE"
defined $code
ref $code eq "CODE"
Truth table33%1/3
A and B
A= defined $codeB= ref $code eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | carp "a coderef is required"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $self->{macros}{$macro} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | sub add_filter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_filter: called CC=5 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my ($self, $tag, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | unless (defined $tag and $tag ne "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $tag and $tag ne ""
MC/DC0%0/2
defined $tag and $tag ne ""
defined $tag
$tag ne ""
Truth table33%1/3
A and B
A= defined $tagB= $tag ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | carp "undefined tag name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | unless (defined $code and ref($code) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $code and ref $code eq "CODE"
MC/DC0%0/2
defined $code and ref $code eq "CODE"
defined $code
ref $code eq "CODE"
Truth table33%1/3
A and B
A= defined $codeB= ref $code eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | carp "a coderef is required"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $self->{filters}{$tag} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||