1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
package HTML::Escape;
use strict;
use warnings;
use 5.008005;
our $VERSION = '1.11';
use parent qw/Exporter/;
my $use_xs = 0;
if(!exists $INC{'HTML/Escape/PurePerl.pm'}) {
my $pp = $ENV{PERL_ONLY};
if (!$pp) {
eval {
require XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);
$use_xs = 1;
};
}
if (!__PACKAGE__->can('escape_html')) {
## no critic.
require 'HTML/Escape/PurePerl.pm' # not to create the namespace
}
}
sub USE_XS () { $use_xs }
our @EXPORT = qw/escape_html/;
1;
__END__
=encoding utf8
=head1 NAME
HTML::Escape - Extremely fast HTML escaping
=head1 SYNOPSIS
use HTML::Escape qw/escape_html/;
my $escaped = escape_html("<^o^>");
=head1 DESCRIPTION
This modules provides a function which escapes HTML's special characters. It
performs a similar function to PHP's htmlspecialchars. It escapes the
following characters:
" & ' < > ` { }
This module uses XS for better performance, but it also provides a pure perl
version.
=head1 FAQ
=over 4
=item Is there also an unescape_html?
No. Unescaping HTML requires a lot of code, and we don't want to do it.
Please use L<HTML::Entities> for it.
=back
=head1 BENCHMARK
Rate HTML::Entities HTML::Escape
HTML::Entities 14.0/s -- -91%
HTML::Escape 150/s 975% --
=head1 AUTHOR
Goro Fuji
Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF@ GMAIL COME<gt>
=head1 SEE ALSO
L<Text::Xslate>, L<HTML::Entities>
=head1 LICENSE
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|