| 1 | package PYX::Utils; | ||
| 2 | |||
| 3 | 6 | ▶ | use base qw(Exporter); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 6 | ▶ | use HTML::Entities qw(decode_entities); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 6 | ▶ | use Readonly; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | # Constants. | ||
| 11 | 6 | Readonly::Array our @EXPORT_OK => qw(decode encode entity_decode entity_encode); | |
| 12 | 6 | Readonly::Hash our %ENTITIES => ( | |
| 13 | '<' => '<', | ||
| 14 | q{&} => '&', | ||
| 15 | q{"} => '"', | ||
| 16 | ); | ||
| 17 | 6 | Readonly::Scalar our $ENTITIES => join q{}, keys %ENTITIES; | |
| 18 | |||
| 19 | 6 | our $VERSION = 0.05; | |
| 20 | |||
| 21 | # Decode chars. | ||
| 22 | sub decode { | ||
| 23 | 1 | ▶ | my $text = shift; |
|
Subroutine
decode: called CC=1 SCAR=0.0
Pod
documented
| |||
| 24 | 1 | $text =~ s/\n/\\n/gms; | |
| 25 | 1 | return $text; | |
| 26 | } | ||
| 27 | |||
| 28 | # Encode chars. | ||
| 29 | sub encode { | ||
| 30 | 1 | ▶ | my $text = shift; |
|
Subroutine
encode: called CC=1 SCAR=0.0
Pod
documented
| |||
| 31 | 1 | $text =~ s/\\n/\n/gms; | |
| 32 | 1 | return $text; | |
| 33 | } | ||
| 34 | |||
| 35 | # Decode entities. | ||
| 36 | sub entity_decode { | ||
| 37 | 4 | ▶ | my $text = shift; |
|
Subroutine
entity_decode: called CC=1 SCAR=0.0
Pod
documented
| |||
| 38 | 4 | return decode_entities($text); | |
| 39 | } | ||
| 40 | |||
| 41 | # Encode some chars for HTML/XML/SGML. | ||
| 42 | sub entity_encode { | ||
| 43 | 4 | ▶ | my $text = shift; |
|
Subroutine
entity_encode: called CC=1 SCAR=0.0
Pod
documented
| |||
| 44 | 4 | $text =~ s/([$ENTITIES])/$ENTITIES{$1}/gms; | |
| 45 | 4 | return $text; | |
| 46 | } | ||
| 47 | |||
| 48 | 6 | 1; | |
| 49 | |||
| 50 | __END__ | ||