CrashTest.pl
changeset 37 013953be0f3b
parent 34 e0d6597078a5
child 41 f2292404519a
--- a/CrashTest.pl	Thu Aug 07 23:56:47 2014 +0200
+++ b/CrashTest.pl	Fri Aug 08 00:00:49 2014 +0200
@@ -15,15 +15,11 @@
 
 use Mojolicious::Lite;
 use UUID;
-use Mojo::JSON;
-use Mojo::ByteStream 'b';
-use Mojo::UserAgent;
 use lib 'lib';
 
-my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
-my $config = plugin 'Config';
-
-plugin 'TagHelpers::BootstrapPagination';
+use CrashTest::Models::Frame;
+use CrashTest::Models::Thread;
+use CrashTest::StackFilter;
 
 app->attr(storage => sub {
     my $self = shift;
@@ -53,54 +49,6 @@
     );
 });
 
-helper scm_file_link => sub {
-    my ($self, $file, $line) = @_;
-
-    return "" unless(defined($file));
-
-    if($file =~ qr{([a-z]+):([a-z/.]+):(.+):(\d+)})
-    {
-        my ($scm, $repo, $scmpath, $rev) = ($1, $2, $3, $4);
-        my $filename = File::Spec->splitpath($scmpath);
-        my $scmrepo = "$scm:$repo";
-        if(exists($config->{ScmLinks}->{$scmrepo})) {
-            return b($self->link_to("$filename:$line" =>
-                    $self->render(inline => $config->{ScmLinks}->{$scmrepo},
-                        repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1)
-                ));
-        }
-        #return $file;
-    }
-    my $filebase = (File::Spec->splitpath($file))[-1];
-    if(defined($line) && $line ne "") {
-        return "$filebase:$line";
-    }
-    return $filebase;
-};
-
-helper shorten_signature => sub {
-    my ($self, $signature) = @_;
-
-    return "" if(!defined($signature) || $signature eq "");
-
-    my $short_signature = $signature;
-    if($signature =~ qr{([^<]+)<.+>::([^()]+)\(.*\)(.*)}) {
-        # c++ with template
-        $short_signature = "$1<>::$2()$3";
-    } elsif($signature =~ qr{([^()]+)\(.*\)(.*)}) {
-        # c/c++
-        $short_signature = "$1()$2";
-    }
-    return b($self->t(span => (title => $signature, class => "shortened-signature") => $short_signature));
-};
-
-helper xml_escape_block => sub {
-    my ($c, $block) = @_;
-    my $result = $block->();
-    $result = xml_escape $result;
-    return Mojo::ByteStream->new($result);
-};
-
 get '/' => sub {
     my $self = shift;
     my $page = 1;
@@ -116,13 +64,32 @@
 
 get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
     my $self = shift;
-    $self->stash(processed_data => $self->app->storage->get_processed_data($self->param('uuid')));
+
+    my $data = $self->app->storage->get_processed_data($self->param('uuid'));
+    $self->stash(processed_data => $data);
+
+    my $stackfilter = CrashTest::StackFilter->new(config => $self->app->config, app => $self->app);
+
+    my $crashing_thread = CrashTest::Models::Thread->new($data->{crashing_thread});
+    $crashing_thread = $stackfilter->apply($crashing_thread);
+    $self->stash(crashing_thread => $crashing_thread);
+
+    my $threads = [];
+    foreach my $raw_thread(@{$data->{threads}}) {
+        my $thread = CrashTest::Models::Thread->new($raw_thread);
+        $thread = $stackfilter->apply($thread);
+        push $threads, $thread;
+    }
+    $self->stash(threads => $threads);
+
     $self->render('report/crash');
 } => 'report';
 
 post '/submit' => sub {
     my $self = shift;
 
+    #my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
+
     # save the dump in a file
     my $file = $self->req->upload('upload_file_minidump');
     my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
@@ -139,12 +106,17 @@
             $self->render(text => $pjson->{status});
         }
     );
-
-};
+} => 'submit';
 
 app->secrets([
     'My secret passphrase here'
 ]);
 
 push @{app->commands->namespaces}, 'CrashTest::Commands';
+push @{app->plugins->namespaces}, 'CrashTest::Helpers';
+
+plugin 'Config';
+plugin 'TagHelpers::BootstrapPagination';
+plugin 'CrashTestHelpers';
+
 app->start;