1 package SL::Presenter::EscapedText;
 
   7 use overload '""' => \&escaped;
 
  10   my ($class, %params) = @_;
 
  12   return $params{text} if ref($params{text}) eq $class;
 
  14   my $self      = bless {}, $class;
 
  15   $self->{text} = $params{is_escaped} ? $params{text} : $::locale->quote_special_chars('HTML', $params{text});
 
  38 SL::Presenter::EscapedText - Thin proxy object around HTML-escaped strings
 
  42   use SL::Presenter::EscapedText;
 
  46     return SL::Presenter::EscapedText->new(text => $text);
 
  50     my $output_of_other_component = blackbox('Hello & Goodbye');
 
  52     # The following is safe, text will not be escaped twice:
 
  53     return SL::Presenter::EscapedText->new(text => $output_of_other_component);
 
  56   my $output = build_output();
 
  57   print "Yeah: $output\n";
 
  61 Sometimes it's nice to let a sub-component build its own
 
  62 representation. However, you always have to be very careful about
 
  63 whose responsibility escaping is. Only the building function knows
 
  64 enough about the structure to be able to HTML escape properly.
 
  66 But higher functions should not have to care if the output is already
 
  67 escaped -- they should be able to simply escape it again. Without
 
  68 producing stuff like '&'.
 
  70 Stringification is overloaded. It will return the same as L<escaped>.
 
  72 This works together with the template plugin
 
  73 L<SL::Template::Plugin::P> and its C<escape> method.
 
  81 Creates an instance of C<EscapedText>.
 
  83 The parameter C<text> is the text to escape. If it is already an
 
  84 instance of C<EscapedText> then C<$params{text}> is returned
 
  87 Otherwise C<text> is HTML-escaped and stored in the new instance. This
 
  88 can be overridden by setting C<$params{is_escaped}> to a trueish
 
  93 Returns the escaped string (not an instance of C<EscapedText> but an
 
 104 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>