lib/CrashTest/Helper/XmlEscape.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Wed, 04 Nov 2015 17:43:00 +0100
changeset 78 0ebef32c34af
parent 37 lib/CrashTest/Helpers/CrashTestHelpers.pm@013953be0f3b
child 122 8692800ec9ba
permissions -rw-r--r--
Refactor everything - change db access method, use Mojo::{Pg,SQLite,...} instead of DBIx::Class - use Minion as job queue - refactor into a non-Lite Mojolicious app

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package CrashTest::Helper::XmlEscape;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::ByteStream qw/b/;
use Mojo::Util qw/xml_escape/;

sub register {
  my ($self, $mojo, $params) = @_;

  $mojo->helper(xml_escape_block => sub { return $self->xml_escape_block(@_); });
}

sub xml_escape_block {
    my ($self, $c, $block) = @_;
    my $result = $block->();
    return b(xml_escape($result));
}

1;