lib/CrashTest/StackFilter.pm
changeset 78 0ebef32c34af
parent 77 e408da1419cd
child 79 4ae8bb6f8a96
--- a/lib/CrashTest/StackFilter.pm	Sun Sep 27 22:45:40 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-# 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::StackFilter;
-use Mojo::Base -base;
-use Mojo::Loader qw/load_class find_modules/;
-
-has [ qw/config app filters/ ];
-
-sub new {
-    my $self = shift->SUPER::new(@_);
-
-    if(defined($self->config->{StackFilters})) {
-        $self->load_plugins($self->config->{StackFilters});
-    } else {
-        $self->find_stackfilters_plugins();
-    }
-
-    return $self;
-}
-
-sub apply {
-    my ($self, $thread) = @_;
-
-    foreach my $filter(@{$self->filters}) {
-        #say "apply filter $filter";
-        $thread = $filter->apply($thread);
-    }
-
-    return $thread;
-}
-
-sub load_plugins {
-    my ($self, $modules) = @_;
-
-    my @filters = ();
-    for my $module (@$modules) {
-        my $e = load_class($module);
-        die qq{Loading "$module" failed: $e} if ref $e;
-
-        #say "loading $module";
-        push @filters, $module->new(config => $self->config, app => $self->app);
-    }
-
-    $self->filters(\@filters);
-}
-
-sub find_stackfilters_plugins {
-    my ($self) = @_;
-
-    my @modules = ();
-
-    # Find modules in a namespace
-    for my $module (find_modules('CrashTest::StackFilters')) {
-        my $e = load_class($module);
-        warn qq{Loading "$module" failed: $e} and next if ref $e;
-
-        push @modules, [ $module, $module->priority ];
-    }
-
-    # sort by prio
-    @modules = sort { $b->[1] <=> $a->[1] } @modules;
-
-    # instanciate
-    my @filters = map { $_->[0]->new(config => $self->config, app => $self->app) } @modules;
-
-    $self->filters(\@filters);
-}
-
-1;