Frundis.pm

filter: Statementstmt 80.3% 49 / 61 Branchbran 59.0% 13 / 22 Conditioncond 55.2% 21 / 38 MC/DCmcdc 4.7% 1 / 21 Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 62.4% 98 / 157 CC 27 SCAR 27.4
CC
27
Cov
69%
process_source
24.6
add_macro
12.5
add_filter
9.3
CRAP 15.5
« Frundis/Processing.pm ↑ Summary Frundis/Object.pm »
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
l!l
4911
MC/DC100%1/1
$opts{"use_carp"} //= 1
$opts{"use_carp"}
Truth table100%2/2
A
A= $opts{"use_carp"}
Aresult
11
00
41 croak("`target_format' parameter required")
42 unless defined $opts{target_format}
43 60 ▶ or $opts{script};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"target_format"} or $opts{"script"} 0 60 60
Condition33%1/3
defined $opts{"target_format"} or $opts{"script"}
l!l&&r!l&&!r
6000
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"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $opts{"script"} or not $opts{"all_in_one_file"} && $opts{"target_format"} eq "epub" 0 60 60
Condition50%3/6
$opts{"script"} or not $opts{"all_in_one_file"} && $opts{"target_format"} eq "epub"
l!l&&r!l&&!r
0600
$opts{'all_in_one_file'} && $opts{'target_format'} eq 'epub'
!ll&&!rl&&r
7530
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'
ABCresult
1XX1
00X1
0101
0110
48 60 ▶ if ( not $opts{script}
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts{"script"} and $opts{"target_format"} eq "epub" and not defined $opts{"output_file"}) 0 60 60
Condition66%4/6
not $opts{"script"} and $opts{"target_format"} eq "epub" and not defined $opts{"output_file"}
!ll&&!rl&&r
5730
not $opts{"script"} and $opts{"target_format"} eq "epub"
!ll&&!rl&&r
0573
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"}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if (not $opts{"script"} and $opts{"target_format"} eq "xhtml" and not $opts{"all_in_one_file"} and not defined $opts{"output_file"}) 0 60 60
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"}
!ll&&!rl&&r
5730
not $opts{"script"} and $opts{"target_format"} eq "xhtml" and not $opts{"all_in_one_file"}
!ll&&!rl&&r
30273
not $opts{"script"} and $opts{"target_format"} eq "xhtml"
!ll&&!rl&&r
03030
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"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
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
BranchTrueFalseTotal
if (defined $macros) 1 59 60
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
BranchTrueFalseTotal
if (defined $filters) 1 59 60
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
BranchTrueFalseTotal
unless (defined $macro and $macro ne "") 0 1 1
Condition33%1/3
defined $macro and $macro ne ""
!ll&&!rl&&r
001
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 ""
ABresult
0X0
100
111
89 0 carp "undefined macro name";
90 0 return;
91 }
92 1 ▶ if ($macro =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($macro =~ /\s/u) 0 1 1
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
BranchTrueFalseTotal
unless (defined $code and ref $code eq "CODE") 0 1 1
Condition33%1/3
defined $code and ref $code eq "CODE"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless (defined $tag and $tag ne "") 0 1 1
Condition33%1/3
defined $tag and $tag ne ""
!ll&&!rl&&r
001
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 ""
ABresult
0X0
100
111
108 0 carp "undefined tag name";
109 0 return;
110 }
111 1 ▶ unless (defined $code and ref($code) eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code and ref $code eq "CODE") 0 1 1
Condition33%1/3
defined $code and ref $code eq "CODE"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
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__
« Frundis/Processing.pm ↑ Summary Frundis/Object.pm »