File Coverage

blib/lib/HTML/Mason/Escapes.pm
Criterion Covered Total %
statement 25 25 100.0
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 38 41 92.6


line stmt bran cond sub pod time code
1             # Copyright (c) 1998-2005 by Jonathan Swartz. All rights reserved.
2             # This program is free software; you can redistribute it and/or modify it
3             # under the same terms as Perl itself.
4              
5             #
6             # A library of escape subroutines to be used for substitution escaping
7             #
8              
9             package HTML::Mason::Escapes;
10             $HTML::Mason::Escapes::VERSION = '1.58';
11 33     33   43278 use strict;
  33         95  
  33         922  
12 33     33   168 use warnings;
  33         61  
  33         913  
13              
14 33     33   9610 use HTML::Entities ();
  33         157860  
  33         5519  
15              
16              
17             my %html_escape = ('&' => '&', '>'=>'>', '<'=>'<', '"'=>'"');
18             my $html_escape = qr/([&<>"])/;
19              
20             sub basic_html_escape
21             {
22 34 50   34 1 4035 return unless defined ${ $_[0] };
  34         61  
23              
24 34         39 ${ $_[0] } =~ s/$html_escape/$html_escape{$1}/mg;
  34         243  
25             }
26              
27             sub html_entities_escape
28             {
29 16 50   16 1 522 return unless defined ${ $_[0] };
  16         41  
30              
31 16         26 HTML::Entities::encode_entities( ${ $_[0] } );
  16         50  
32             }
33              
34             sub url_escape
35             {
36 5 50   5 1 449 return unless defined ${ $_[0] };
  5         22  
37              
38 33     33   13769 use bytes;
  33         431  
  33         230  
39 5         10 ${ $_[0] } =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
  5         29  
  49         146  
40             }
41              
42              
43             1;
44              
45             __END__