Revision be5cae09
Von Sven Schöling vor fast 7 Jahren hinzugefügt
SL/Presenter/EscapedText.pm | ||
---|---|---|
10 | 10 |
|
11 | 11 |
use overload '""' => \&escaped_text; |
12 | 12 |
|
13 |
my %html_entities = ( |
|
14 |
'<' => '<', |
|
15 |
'>' => '>', |
|
16 |
'&' => '&', |
|
17 |
'"' => '"', |
|
18 |
"'" => ''', |
|
19 |
); |
|
20 |
|
|
13 | 21 |
# static constructors |
14 | 22 |
sub new { |
15 | 23 |
my ($class, %params) = @_; |
... | ... | |
17 | 25 |
return $params{text} if ref($params{text}) eq $class; |
18 | 26 |
|
19 | 27 |
my $self = bless {}, $class; |
20 |
$self->{text} = $params{is_escaped} ? $params{text} : $::locale->quote_special_chars('HTML', $params{text});
|
|
28 |
$self->{text} = $params{is_escaped} ? $params{text} : quote_html($params{text});
|
|
21 | 29 |
|
22 | 30 |
return $self; |
23 | 31 |
} |
24 | 32 |
|
33 |
sub quote_html { |
|
34 |
return undef unless defined $_[0]; |
|
35 |
(my $x = $_[0]) =~ s/(["'<>&])/$html_entities{$1}/ge; |
|
36 |
$x |
|
37 |
} |
|
38 |
|
|
25 | 39 |
sub escape { |
26 | 40 |
__PACKAGE__->new(text => $_[0]); |
27 | 41 |
} |
Auch abrufbar als: Unified diff
Presenter::EscapedText: quote_html nicht über $::locale laufen lassen
Die quote_html Liste in speacial_chars ist extrem langsam. Für HTML
Generierung lieber diese optimierte nehmen.