File Coverage

blib/lib/PYX/Utils.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 4 4 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             package PYX::Utils;
2              
3 6     6   75839 use base qw(Exporter);
  6         38  
  6         793  
4 6     6   42 use strict;
  6         7  
  6         116  
5 6     6   37 use warnings;
  6         31  
  6         242  
6              
7 6     6   3357 use HTML::Entities qw(decode_entities);
  6         44899  
  6         475  
8 6     6   3313 use Readonly;
  6         23806  
  6         1596  
9              
10             # Constants.
11             Readonly::Array our @EXPORT_OK => qw(decode encode entity_decode entity_encode);
12             Readonly::Hash our %ENTITIES => (
13             '<' => '<',
14             q{&} => '&',
15             q{"} => '"',
16             );
17             Readonly::Scalar our $ENTITIES => join q{}, keys %ENTITIES;
18              
19             our $VERSION = 0.05;
20              
21             # Decode chars.
22             sub decode {
23 1     1 1 86 my $text = shift;
24 1         6 $text =~ s/\n/\\n/gms;
25 1         3 return $text;
26             }
27              
28             # Encode chars.
29             sub encode {
30 1     1 1 93 my $text = shift;
31 1         5 $text =~ s/\\n/\n/gms;
32 1         4 return $text;
33             }
34              
35             # Decode entities.
36             sub entity_decode {
37 4     4 1 1941 my $text = shift;
38 4         34 return decode_entities($text);
39             }
40              
41             # Encode some chars for HTML/XML/SGML.
42             sub entity_encode {
43 4     4 1 1924 my $text = shift;
44 4         62 $text =~ s/([$ENTITIES])/$ENTITIES{$1}/gms;
45 4         58 return $text;
46             }
47              
48             1;
49              
50             __END__