Skip to content

Commit

Permalink
Changed html_entity_filter_factory() in Template::Filters to only loo…
Browse files Browse the repository at this point in the history
…k for Apache::Utils and HTML::Entities once

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@1134 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information
abw committed Aug 6, 2008
1 parent ba784d4 commit 5be1f36
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions lib/Template/Filters.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use locale;
use base 'Template::Base';
use Template::Constants;

our $VERSION = 2.86;
our $VERSION = 2.86;
our $AVAILABLE = { };


#------------------------------------------------------------------------
Expand Down Expand Up @@ -378,25 +379,26 @@ sub html_line_break {

sub html_entity_filter_factory {
my $context = shift;

# if Apache::Util is installed then we use it
eval {
require Apache::Util;
Apache::Util::escape_html('');
};
return \&Apache::Util::escape_html
unless $@;

# otherwise if HTML::Entities is installed then we use that
eval {
require HTML::Entities;
};
return \&HTML::Entities::encode_entities
unless $@;

return (undef, Template::Exception->new( html_entity =>
'cannot locate Apache::Util or HTML::Entities' ));

my $haz;

# if Apache::Util is installed then we use escape_html
$haz = $AVAILABLE->{ HTML_ENTITY }
||= eval {
require Apache::Util;
Apache::Utils::escape_html('');
\&Apache::Util::escape_html
}
|| eval {
require HTML::Entities;
\&HTML::Entities::encode_entities
}
|| -1; # we use -1 for "not available" because it's a true value

return ref $haz eq 'CODE'
? $haz
: (undef, Template::Exception->new(
html_entity => 'cannot locate Apache::Util or HTML::Entities' )
);
}


Expand Down

0 comments on commit 5be1f36

Please sign in to comment.