Methode zum Auflisten bekannter Hintergrundjobklassen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 30 Oct 2012 12:41:26 +0000 (13:41 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 30 Oct 2012 12:41:26 +0000 (13:41 +0100)
SL/BackgroundJob/Base.pm
t/background_job/known_jobs.t [new file with mode: 0644]

index 27f6081..912fdc6 100644 (file)
@@ -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 (file)
index 0000000..c6b43f0
--- /dev/null
@@ -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';