File Coverage

blib/lib/XML/Smart/Entity.pm
Criterion Covered Total %
statement 31 34 91.1
branch 7 12 58.3
condition n/a
subroutine 6 6 100.0
pod n/a
total 44 52 84.6


line stmt bran cond sub pod time code
1             #############################################################################
2             ## Name: Entity.pm
3             ## Purpose: XML::Smart::Entity - Handle entities
4             ## Author: Graciliano M. P.
5             ## Modified by: Harish Madabushi
6             ## Created: 28/09/2003
7             ## RCS-ID:
8             ## Copyright: (c) 2003 Graciliano M. P.
9             ## Licence: This program is free software; you can redistribute it and/or
10             ## modify it under the same terms as Perl itself
11             #############################################################################
12              
13             package XML::Smart::Entity ;
14              
15 11     11   58 use strict ;
  11         18  
  11         348  
16 11     11   57 use warnings ;
  11         21  
  11         457  
17              
18             require Exporter ;
19              
20 11     11   59 use XML::Smart::Shared qw( _unset_sig_warn _reset_sig_warn ) ;
  11         34  
  11         6760  
21              
22             our ($VERSION , @ISA) ;
23             $VERSION = '0.03' ;
24              
25             @ISA = qw(Exporter) ;
26              
27             our @EXPORT = qw(_parse_basic_entity _add_basic_entity) ;
28             our @EXPORT_OK = @EXPORT ;
29              
30              
31              
32             #######################
33             # _PARSE_BASIC_ENTITY #
34             #######################
35              
36             sub _parse_basic_entity {
37              
38 3396     3396   4484 my $entity = $_[0] ;
39 3396 100       6022 if( $entity ) {
40 3374         6218 $_[0] =~ s/</
41 3374         4993 $_[0] =~ s/>/>/gs ;
42 3374         5049 $_[0] =~ s/&/&/gs ;
43 3374         5181 $_[0] =~ s/'/'/gs ;
44 3374         4622 $_[0] =~ s/"/"/gs ;
45            
46 3374 0       5367 $_[0] =~ s/&#(\d+);/ $1 > 255 ? pack("U",$1) : pack("C",$1)/egs ;
  0         0  
47 3374         5080 $_[0] =~ s/&#x([a-fA-F\d]+);/pack("U",hex($1))/egs ;
  0         0  
48             }
49            
50 3396         8552 return( $entity ) ;
51             }
52              
53             #####################
54             # _ADD_BASIC_ENTITY #
55             #####################
56              
57             sub _add_basic_entity {
58              
59 1133     1133   1734 my $entity = $_[0] ;
60 1133 100       2149 if( $entity ) {
61 1097 50       1872 $_[0] =~ s/(&(?:\w+;)?)/{_is_amp($1) or $1}/sgex ;
  15         23  
  15         47  
62 1097         1593 $_[0] =~ s/
63 1097         1648 $_[0] =~ s/>/>/gs ;
64             }
65              
66 1133         2149 return( $entity ) ;
67             }
68            
69             ###########
70             # _IS_AMP #
71             ###########
72              
73             sub _is_amp {
74              
75 15     15   44 my $entity = $_[0] ;
76 15 50       41 if( $entity ) {
77 15 50       46 if($entity eq '&') {
78 15         86 return( '&' ) ;
79             }
80             }
81              
82 0           return( undef ) ;
83              
84             }
85              
86             #######
87             # END #
88             #######
89              
90             1;
91              
92