lib/CrashTest/Command/update.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Sun, 18 Dec 2016 21:11:27 +0100
changeset 122 8692800ec9ba
parent 96 716c0292967c
child 128 6b56182fd491
permissions -rw-r--r--
Use Dzil PkgVersion Add a newline after each package to make Dist::Zilla happy

# 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::Command::update;

use Mojo::Base 'Mojolicious::Command';
use Mojo::JSON::MaybeXS;
use Mojo::JSON qw/decode_json/;
use Mojo::Util qw/slurp/;
use File::Spec::Functions qw/catdir catfile/;
use File::Basename;

# Short description
has description => 'Update crash';

# Short usage message
has usage => <<EOF;
Usage: APPLICATION update file ...
EOF

sub run {
    my ($self, @args) = @_;

    if(scalar @args < 1) {
        say $self->usage;
        exit 0;
    }

    foreach my $jsonfile(@args) {
        my ($uuid,$path,$suffix) = fileparse($jsonfile, qw/.json/);

        my $dmp = undef;
        if(-e catfile($path, "$uuid.dmp")) {
            $dmp = slurp(catfile($path, "$uuid.dmp"));
        }

        eval {
            my $pjson = decode_json(slurp(catfile($path, "$uuid.json")));
            $self->app->crash_reports->update($uuid, $pjson, $pjson->{client_info}, $dmp);
        };
        warn $@ if $@;

    }

}

1;