lib/MKDoc/XML/Decode.pm

filter: Statementstmt 94.6% 71 / 75 Branchbran 65.0% 13 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 14 / 14 Podpod 33.3% 1 / 3 totaltotal 87.1% 102 / 117 CC 8 SCAR 7.9
CC
8
Cov
88%
entity_to_char
4.0
new
3.4
process
3.1
CRAP 2.2
« lib/MKDoc/XML/Encode.pm ↑ Summary blib/lib/MKDoc/XML.pm »
1 # -------------------------------------------------------------------------------------
2 # MKDoc::XML::Decode
3 # -------------------------------------------------------------------------------------
4 # Author : Jean-Michel Hiver
5 # Copyright : (c) MKDoc Holdings Ltd, 2003
6 #
7 # This modules expands XML entities & > < " and '.
8 #
9 # This module is distributed under the same license as Perl itself.
10 # -------------------------------------------------------------------------------------
11 package MKDoc::XML::Decode;
12 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 7 our %Modules = ();
17  
18 7 our $WARN = 0;
19  
20  
21 # import all plugins once
22 7 foreach my $include_dir (@INC)
23 {
24 63 my $dir = "$include_dir/MKDoc/XML/Decode";
25 63 ▶ if (-e $dir and -d $dir)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $dir and -d $dir) 21 42 63
Condition66%2/3
-e $dir and -d $dir
!ll&&!rl&&r
42021
MC/DC50%1/2
-e $dir and -d $dir
-e $dir -d $dir
Truth table66%2/3
A and B
A= -e $dirB= -d $dir
ABresult
0X0
100
111
26 {
27 21 ▶ opendir DD, $dir or do {
Branch: 1 branch
BranchTrueFalseTotal
opendir DD, $dir or do { warn "Cannot open directory $dir. Reason: $!"; next } 21 0 21
28 0 warn "Cannot open directory $dir. Reason: $!";
29 0 next;
30 };
31
32 21 my @modules = map { s/\.pm$//; $_ }
33 grep /\.pm$/,
34 grep !/^\./,
35 readdir (DD);
36  
37 21 closedir DD;
38
39 21 foreach my $module (@modules)
40 {
41 63 $module =~ /^(\w+)$/;
42 63 $module = $1;
43 7 ▶ eval "use MKDoc::XML::Decode::$module";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
44 63 ▶ $@ and warn "Cannot import module $module. Reason: $@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and warn "Cannot import module $module. Reason: $@" 0 63 63
45
46 63 ▶ my $name = "MKDoc::XML::Decode::$module"->can ('module_name') ?
Branch: 1 branch
BranchTrueFalseTotal
("MKDoc::XML::Decode::$module")->can('module_name') ? : 21 42 63
47 "MKDoc::XML::Decode::$module"->module_name() :
48 lc ($module);
49
50 63 $Modules{$name} = "MKDoc::XML::Decode::$module";
51 }
52 }
53 }
54  
55  
56 sub new
57 96 ▶{
Subroutine new: called CC=3 SCAR=12.3
Pod documented
58 96 my $class = shift;
59 96 ▶ @_ = sort keys %Modules unless (scalar @_);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 96 96
60
61 my $self = bless [ map {
62 96 ▶ $Modules{$_} ? $Modules{$_} : do {
Branch: 1 branch
BranchTrueFalseTotal
$MKDoc::XML::Decode::Modules{$_} ? : 98 0 98
63 0 warn "Module $_ not found - Ignoring";
64 0 ();
65 } } @_ ], $class;
66  
67 96 return $self;
68 }
69  
70  
71 sub entity_to_char
72 12 ▶{
Subroutine entity_to_char: called CC=4 SCAR=13.9
Pod undocumented
73 12 my $self = shift;
74 12 my $char = shift;
75 12 for (@{$self}) {
76 12 my $res = $_->process ($char);
77 12 ▶ return $res if (defined $res);
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 7 5 12
78 };
79
80 5 ▶ warn "Could not expand &$char;" if ($WARN);
Branch: 1 branch
BranchTrueFalseTotal
if $MKDoc::XML::Decode::WARN 0 5 5
81 5 return "&$char;";
82 }
83  
84  
85 sub process
86 105 ▶{
Subroutine process: called CC=3 SCAR=11.2
Pod undocumented
87 105 ▶ (@_ == 2) or warn "MKDoc::XML::Encode::process() should be called with two arguments";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or warn "MKDoc::XML::Encode::process() should be called with two arguments" 105 0 105
88  
89 105 my $self = shift;
90 105 ▶ my $data = join '', map { defined $_ ? $_ : () } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 105 0 105
91 105 $data =~ s/&(#?[0-9A-Za-z]+);/$self->entity_to_char ($1)/eg;
92 105 return $data;
93 }
94  
95  
96 7 1;
97  
98  
99 __END__
« lib/MKDoc/XML/Encode.pm ↑ Summary blib/lib/MKDoc/XML.pm »