lib/CrashTest/Helper/Backtrace.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Sat, 29 Oct 2016 13:20:07 +0200
changeset 114 1f67942c76c9
parent 78 0ebef32c34af
child 122 8692800ec9ba
permissions -rw-r--r--
Fixes for Mojolicious 7

# 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::Backtrace;
use Mojo::Base 'Mojolicious::Plugin';

sub register {
    my ($self, $app, $conf) = @_;

    $app->helper(module_warnings => sub { $self->_bt_warning("module_warnings", @_) } );
    $app->helper(frame_warnings  => sub { $self->_bt_warning("frame_warnings", @_) } );
}

sub _bt_warning {
    my ($self, $type, $c, $frame) = @_;

    my $warnings;
    if($type eq "frame_warnings") {
        $warnings = $frame->frame_warnings;
    } elsif($type eq "module_warnings") {
        $warnings = $frame->module_warnings;
    }

    return "" if(!$warnings);

    my @ret;
    foreach my $warning (@{$warnings}) {
        push @ret, scalar $c->render_to_string('report/backtrace/warning', tooltip_text => $warning);
    }

    return Mojo::ByteStream->new(join "", @ret);
}

1;