From 4c4451019153b54376792e97e87222d3c1b6cdbf Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Thu, 18 Nov 2004 19:47:10 +0000 Subject: [PATCH] Move plugin compile code into the Plugin module git-svn-id: https://svn.perl.org/qpsmtpd/trunk@341 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd.pm | 47 +------------------------------------------ lib/Qpsmtpd/Plugin.pm | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 192fdc5..17c3a52 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -121,51 +121,6 @@ sub _config_from_file { return wantarray ? @config : $config[0]; } -sub _compile { - my ($self, $plugin, $package, $file) = @_; - - my $sub; - open F, $file or die "could not open $file: $!"; - { - local $/ = undef; - $sub = ; - } - close F; - - my $line = "\n#line 1 $file\n"; - - if ($self->{_test_mode}) { - if (open(F, "t/plugin_tests/$plugin")) { - local $/ = undef; - $sub .= "#line 1 t/plugin_tests/$plugin\n"; - $sub .= ; - close F; - } - } - - my $eval = join( - "\n", - "package $package;", - 'use Qpsmtpd::Constants;', - "require Qpsmtpd::Plugin;", - 'use vars qw(@ISA);', - '@ISA = qw(Qpsmtpd::Plugin);', - ($self->{_test_mode} ? 'use Test::More;' : ''), - "sub plugin_name { qq[$plugin] }", - $line, - $sub, - "\n", # last line comment without newline? - ); - - #warn "eval: $eval"; - - $eval =~ m/(.*)/s; - $eval = $1; - - eval $eval; - die "eval $@" if $@; -} - sub load_plugins { my $self = shift; @@ -230,7 +185,7 @@ sub _load_plugins { my $package = "Qpsmtpd::Plugin::$plugin_name"; # don't reload plugins if they are already loaded - $self->_compile($plugin_name, $package, "$dir/$plugin") unless + Qpsmtpd::Plugin->compile($plugin_name, $package, "$dir/$plugin", $self->{_test_mode}) unless defined &{"${package}::register"}; my $plug = $package->new(); diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index 382814c..2225140 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -75,4 +75,49 @@ sub isa_plugin { push @{"${currentPackage}::ISA"}, $newPackage; } +sub compile { + my ($class, $plugin, $package, $file, $test_mode) = @_; + + my $sub; + open F, $file or die "could not open $file: $!"; + { + local $/ = undef; + $sub = ; + } + close F; + + my $line = "\n#line 1 $file\n"; + + if ($test_mode) { + if (open(F, "t/plugin_tests/$plugin")) { + local $/ = undef; + $sub .= "#line 1 t/plugin_tests/$plugin\n"; + $sub .= ; + close F; + } + } + + my $eval = join( + "\n", + "package $package;", + 'use Qpsmtpd::Constants;', + "require Qpsmtpd::Plugin;", + 'use vars qw(@ISA);', + '@ISA = qw(Qpsmtpd::Plugin);', + ($test_mode ? 'use Test::More;' : ''), + "sub plugin_name { qq[$plugin] }", + $line, + $sub, + "\n", # last line comment without newline? + ); + + #warn "eval: $eval"; + + $eval =~ m/(.*)/s; + $eval = $1; + + eval $eval; + die "eval $@" if $@; +} + 1;