X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FShredder%2FPlugin.pm;h=d612cc12c69c619dd63f6b7d35e14a0990d495d8;hp=60b5b183582f969c10772693ea09a97f766212a4;hb=187086c479a09629b7d180eec513fb7657f4e291;hpb=fc6209f398899f0211cfcedeb81a3cd65e04a941 diff --git a/rt/lib/RT/Shredder/Plugin.pm b/rt/lib/RT/Shredder/Plugin.pm index 60b5b1835..d612cc12c 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-2011 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -64,7 +64,7 @@ RT::Shredder::Plugin - interface to access shredder plugins my %plugins = RT::Shredder::Plugin->List; # load plugin by name - my $plugin = new RT::Shredder::Plugin; + my $plugin = RT::Shredder::Plugin->new; my( $status, $msg ) = $plugin->LoadByName( 'Tickets' ); unless( $status ) { print STDERR "Couldn't load plugin 'Tickets': $msg\n"; @@ -72,7 +72,7 @@ RT::Shredder::Plugin - interface to access shredder plugins } # load plugin by preformatted string - my $plugin = new RT::Shredder::Plugin; + my $plugin = RT::Shredder::Plugin->new; my( $status, $msg ) = $plugin->LoadByString( 'Tickets=status,deleted' ); unless( $status ) { print STDERR "Couldn't load plugin: $msg\n"; @@ -103,6 +103,7 @@ sub _Init my $self = shift; my %args = ( @_ ); $self->{'opt'} = \%args; + return; } =head2 List @@ -127,14 +128,17 @@ sub List push @files, glob $mask; } - my %res = map { $_ =~ m/([^\\\/]+)\.pm$/; $1 => $_ } reverse @files; + my %res; + for my $f (reverse @files) { + $res{$1} = $f if $f =~ /([^\\\/]+)\.pm$/; + } return %res unless $type; 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; } @@ -158,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