Changeset 304


Ignore:
Timestamp:
12/05/06 17:02:11 (17 years ago)
Author:
nanardon
Message:
  • split execution plugin code in its own function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • obsdata/trunk/ObsData/Repository.pm

    r299 r304  
    560560        # if regexp no match, @dataar is empty 
    561561        if (   @data 
    562             && ( @dataar         || !defined( $dataar[0] ) ) 
    563             && ( (!defined($pret)) || $pret ) ) 
     562            && ( @dataar             || !defined( $dataar[0] ) ) 
     563            && ( ( !defined($pret) ) || $pret ) ) 
    564564        { 
    565565            return ( $datatype, \@data, \@dataar, \%parg ); 
     
    602602        $self->logging( 0, "Found plugin %s for %s, running it", 
    603603            'match_plugin', $datatype, ); 
    604         my ( $exitstatus, @result ) = 
    605           $sub->( $self, 'match_plugin', $datafile, $datatype, @args, ); 
    606         if ($exitstatus) { 
    607             if ( @result % 2 == 0 ) { 
    608                 $self->logging( 0, "Plugin %s for %s exit with %s (%d values)", 
    609                     'match_plugin', $datatype, $exitstatus, scalar(@result), ); 
    610                 return ( 1, @result ); 
    611             } 
    612             else { 
    613                 $self->logging( 4, "Plugin %s for %s return impair values %d", 
    614                     $datatype, $exitstatus, scalar(@result), ); 
    615                 return undef; 
    616             } 
    617         } 
    618         else { 
    619             $self->logging( 0, "Plugin %s of %s exit with null, skipping", 
    620                 'match_plugin', $datatype, ); 
    621             return 0; 
    622         } 
     604 
     605        return $self->run_plugin( $sub, $datatype, $datafile, @args ); 
    623606    } 
    624607    else { 
    625608        return undef; 
     609    } 
     610} 
     611 
     612=head3 run_plugin( $sub, $datatype, $datafile, @args ) 
     613 
     614Run the plugin code for a datafile 
     615 
     616    $sub is the code ref 
     617    $datatype is type of data expect if any 
     618    $datafile is the filename in archive 
     619    @arg arbitrary information 
     620 
     621=cut 
     622 
     623sub run_plugin { 
     624    my ( $self, $sub, $datatype, $datafile, @args ) = @_; 
     625    my ( $exitstatus, @result ) = 
     626      $sub->( $self, 'match_plugin', $datafile, $datatype || "-", @args, ); 
     627    if ($exitstatus) { 
     628        if ( @result % 2 == 0 ) { 
     629            $self->logging( 0, "Plugin %s for %s exit with %s (%d values)", 
     630                'match_plugin', $datatype, $exitstatus, scalar(@result), ); 
     631            return ( 1, @result ); 
     632        } 
     633        else { 
     634            $self->logging( 4, "Plugin %s for %s return impair values %d", 
     635                $datatype, $exitstatus, scalar(@result), ); 
     636            return undef; 
     637        } 
     638    } 
     639    else { 
     640        $self->logging( 0, "Plugin %s of %s exit with null, skipping", 
     641            'match_plugin', $datatype, ); 
     642        return 0; 
    626643    } 
    627644} 
Note: See TracChangeset for help on using the changeset viewer.