| 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
Condition66%2/3
-e $dir and -d $dir
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
| |||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 21 | ▶ | opendir DD, $dir or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 63 | ▶ | my $name = "MKDoc::XML::Decode::$module"->can ('module_name') ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my $self = bless [ map { | ||||||||||||||||||||||||||||
| 62 | 96 | ▶ | $Modules{$_} ? $Modules{$_} : do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 5 | ▶ | warn "Could not expand &$char;" if ($WARN); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 105 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 105 | ▶ | my $data = join '', map { defined $_ ? $_ : () } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||