| 1 | # ------------------------------------------------------------------------------------- | ||||||||||
| 2 | # MKDoc::XML::Encode | ||||||||||
| 3 | # ------------------------------------------------------------------------------------- | ||||||||||
| 4 | # Author : Jean-Michel Hiver. | ||||||||||
| 5 | # Copyright : (c) MKDoc Holdings Ltd, 2003 | ||||||||||
| 6 | # | ||||||||||
| 7 | # This modules encodes XML entities & > < " and '. | ||||||||||
| 8 | # | ||||||||||
| 9 | # This module is distributed under the same license as Perl itself. | ||||||||||
| 10 | # ------------------------------------------------------------------------------------- | ||||||||||
| 11 | package MKDoc::XML::Encode; | ||||||||||
| 12 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 6 | our %XML_Encode = ( | |||||||||
| 16 | '&' => 'amp', | ||||||||||
| 17 | '<' => 'lt', | ||||||||||
| 18 | '>' => 'gt', | ||||||||||
| 19 | '"' => 'quot', | ||||||||||
| 20 | "'" => 'apos', | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | 6 | our $XML_Encode_Pattern = join ("|", keys %XML_Encode); | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | sub process | ||||||||||
| 27 | 48 | ▶ | { | ||||||||
|
Subroutine
process: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 28 | 48 | ▶ | (@_ == 2) or warn "MKDoc::XML::Encode::process() should be called with two arguments"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 48 | my $class = shift; | |||||||||
| 31 | 48 | ▶ | my $data = join '', map { (defined $_) ? $_ : '' } @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 48 | $data =~ s/($XML_Encode_Pattern)/&$XML_Encode{$1};/go; | |||||||||
| 33 | 48 | return $data; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 6 | 1; | |||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | __END__ | ||||||||||