X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FShredder%2FPlugin.pm;h=78ea13188d31909fc7790e4e1cf61b1aee983386;hb=de9d037528895f7151a9aead6724ce2df95f9586;hp=e70d207ac452cee6fa30856338e15a36bdb23e04;hpb=43a06151e47d2c59b833cbd8c26d97865ee850b6;p=freeside.git diff --git a/rt/lib/RT/Shredder/Plugin.pm b/rt/lib/RT/Shredder/Plugin.pm index e70d207ac..78ea13188 100644 --- a/rt/lib/RT/Shredder/Plugin.pm +++ b/rt/lib/RT/Shredder/Plugin.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -103,6 +103,7 @@ sub _Init my $self = shift; my %args = ( @_ ); $self->{'opt'} = \%args; + return; } =head2 List @@ -137,7 +138,7 @@ sub List delete $res{'Base'}; foreach my $name( keys %res ) { my $class = join '::', qw(RT Shredder Plugin), $name; - unless( eval "require $class" ) { + unless( $class->require ) { delete $res{ $name }; next; } @@ -161,24 +162,26 @@ Other arguments are sent to the constructor of the plugin Returns C<$status> and C<$message>. On errors status is C value. +In scalar context, returns $status only. + =cut sub LoadByName { my $self = shift; my $name = shift or return (0, "Name not specified"); + $name =~ /^\w+(::\w+)*$/ or return (0, "Invalid plugin name"); - local $@; my $plugin = "RT::Shredder::Plugin::$name"; - eval "require $plugin" or return( 0, $@ ); - return( 0, "Plugin '$plugin' has no method new") unless $plugin->can('new'); + $plugin->require or return( 0, "Failed to load $plugin" ); + return wantarray ? ( 0, "Plugin '$plugin' has no method new") : 0 unless $plugin->can('new'); my $obj = eval { $plugin->new( @_ ) }; - return( 0, $@ ) if $@; - return( 0, 'constructor returned empty object' ) unless $obj; + return wantarray ? ( 0, $@ ) : 0 if $@; + return wantarray ? ( 0, 'constructor returned empty object' ) : 0 unless $obj; $self->Rebless( $obj ); - return( 1, "successfuly load plugin" ); + return wantarray ? ( 1, "successfuly load plugin" ) : 1; } =head2 LoadByString