line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
27054
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
102
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
127
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Gwybodaeth::Escape; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Escape - Escape characters with XML escapes |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Escape; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $e = Escape->new(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$e->escape($string); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module escapes strings in preperation for putting in XML. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
15
|
use Carp qw(croak); |
|
3
|
|
|
|
|
24
|
|
|
3
|
|
|
|
|
751
|
|
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item new() |
32
|
|
|
|
|
|
|
Returns an instance of the Escape class. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
1
|
|
|
1
|
1
|
76
|
my $class = shift; |
38
|
1
|
|
|
|
|
2
|
my $self = {}; |
39
|
1
|
|
|
|
|
4
|
bless $self, $class; |
40
|
1
|
|
|
|
|
3
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item escape() |
44
|
|
|
|
|
|
|
Escapes strings with XML escapes. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub escape { |
49
|
3
|
50
|
|
3
|
1
|
456
|
ref(my $self = shift) or croak "instance variable needed"; |
50
|
3
|
|
|
|
|
5
|
my $string = shift; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# escape '&' chars. |
53
|
3
|
|
|
|
|
8
|
$string =~ s/& |
54
|
|
|
|
|
|
|
# an ampersand |
55
|
|
|
|
|
|
|
/\&/xg; |
56
|
3
|
|
|
|
|
9
|
$string =~ s/ |
57
|
|
|
|
|
|
|
# an ampersand |
58
|
|
|
|
|
|
|
\& |
59
|
|
|
|
|
|
|
/&/xg; |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
5
|
chomp($string); |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
17
|
return $string; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |