lib/HTML/Mason/Escapes.pm

filter: Statementstmt 100% 29 / 29 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 93.3% 42 / 45 CC 4 SCAR 4.8
CC
4
Cov
91%
basic_html_escape
2.0
html_entities_escape
2.0
url_escape
2.0
CRAP 1.6
« lib/HTML/Mason/Component/Subcomponent.pm ↑ Summary lib/HTML/Mason/ComponentSource.pm »
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 33 $HTML::Mason::Escapes::VERSION = '1.60';
11 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 33 ▶use HTML::Entities ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 33 my %html_escape = ('&' => '&amp;', '>'=>'&gt;', '<'=>'&lt;', '"'=>'&quot;');
18 33 my $html_escape = qr/([&<>"])/;
19  
20 sub basic_html_escape
21 34 ▶{
Subroutine basic_html_escape: called CC=2 SCAR=7.0
Pod documented
22 34 ▶ return unless defined ${ $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless defined ${$_[0];} 0 34 34
23  
24 34 ${ $_[0] } =~ s/$html_escape/$html_escape{$1}/mg;
25 }
26  
27 sub html_entities_escape
28 16 ▶{
Subroutine html_entities_escape: called CC=2 SCAR=7.0
Pod documented
29 16 ▶ return unless defined ${ $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless defined ${$_[0];} 0 16 16
30  
31 16 HTML::Entities::encode_entities( ${ $_[0] } );
32 }
33  
34 sub url_escape
35 5 ▶{
Subroutine url_escape: called CC=2 SCAR=7.0
Pod documented
36 5 ▶ return unless defined ${ $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless defined ${$_[0];} 0 5 5
37  
38 33 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 5 ${ $_[0] } =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
40 }
41  
42  
43 33 1;
44  
45 __END__
« lib/HTML/Mason/Component/Subcomponent.pm ↑ Summary lib/HTML/Mason/ComponentSource.pm »