From f2b0613517ee267a475695ee26457691ab3e48e6 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 30 Oct 2012 13:41:26 +0100 Subject: [PATCH] Methode zum Auflisten bekannter Hintergrundjobklassen --- SL/BackgroundJob/Base.pm | 7 +++++++ t/background_job/known_jobs.t | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 t/background_job/known_jobs.t diff --git a/SL/BackgroundJob/Base.pm b/SL/BackgroundJob/Base.pm index 27f608129..912fdc6fd 100644 --- a/SL/BackgroundJob/Base.pm +++ b/SL/BackgroundJob/Base.pm @@ -4,7 +4,14 @@ use strict; use parent qw(Rose::Object); +use IO::Dir; use SL::DB::BackgroundJob; +use SL::System::Process; + +sub get_known_job_classes { + tie my %dir_h, 'IO::Dir', File::Spec->catdir(File::Spec->splitdir(SL::System::Process->exe_dir), 'SL', 'BackgroundJob'); + return sort map { s/\.pm$//; $_ } grep { m/\.pm$/ && !m/(?: ALL | Base) \.pm$/x } keys %dir_h; +} sub create_standard_job { my $self_or_class = shift; diff --git a/t/background_job/known_jobs.t b/t/background_job/known_jobs.t new file mode 100644 index 000000000..c6b43f0e6 --- /dev/null +++ b/t/background_job/known_jobs.t @@ -0,0 +1,13 @@ +use Test::More tests => 4; + +use lib 't'; + +use Support::TestSetup; + +use_ok 'SL::BackgroundJob::Base'; + +my @expected_known_job_classes = qw(CleanBackgroundJobHistory CreatePeriodicInvoices SelfTest Test); +is_deeply [ SL::BackgroundJob::Base->get_known_job_classes ], \@expected_known_job_classes, 'get_known_job_classes called as class method'; + +my $job = new_ok 'SL::BackgroundJob::Base'; +is_deeply [ $job->get_known_job_classes ], \@expected_known_job_classes, 'get_known_job_classes called as instance method'; -- 2.20.1