/[cvs]/nfo/perl/libs/Data/Rap/Engine.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Rap/Engine.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by joko, Thu Mar 27 15:03:03 2003 UTC revision 1.9 by joko, Fri Apr 4 17:23:11 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.9  2003/04/04 17:23:11  joko
6    ##  minor update: debugging output
7    ##
8    ##  Revision 1.8  2003/03/29 07:11:54  joko
9    ##  modified: sub run_executable
10    ##  new: sub run_script
11    ##
12    ##  Revision 1.7  2003/03/28 07:02:56  joko
13    ##  modified structure around '$wrapper_program'
14    ##
15    ##  Revision 1.6  2003/03/27 15:31:05  joko
16    ##  fixes to modules regarding new namespace(s) below Data::Mungle::*
17    ##
18  ##  Revision 1.5  2003/03/27 15:03:03  joko  ##  Revision 1.5  2003/03/27 15:03:03  joko
19  ##  enhanced 'sub run_executable'  ##  enhanced 'sub run_executable'
20  ##  ##
# Line 34  use Hash::Merge qw( merge ); Line 47  use Hash::Merge qw( merge );
47  use Iterate;  use Iterate;
48    
49  use shortcuts qw( run_cmd );  use shortcuts qw( run_cmd );
50  use Data::Code::Ref qw( ref_slot );  use Data::Mungle::Code::Ref qw( ref_slot );
51  use Data::Transform::Deep qw( expand );  use Data::Mungle::Transform::Deep qw( expand deep_copy );
52    use File::Temp qw/ tempfile tempdir /;
53    
54    
55  sub performTarget {  sub performTarget {
# Line 50  sub perform_target { Line 64  sub perform_target {
64    
65    my $header = ("- " x 12) . "   " . $targetname . "   " . ("- " x 6);    my $header = ("- " x 12) . "   " . $targetname . "   " . ("- " x 6);
66        
67      # V1
68    #$self->log("- " x 35, 'notice');    #$self->log("- " x 35, 'notice');
69    #$self->log("Performing Target '$targetname'.", 'notice');    #$self->log("Performing Target '$targetname'.", 'notice');
70    
71    $self->log($header, 'notice');    # V2
72      #$self->log($header, 'notice');
73    
74      # V3
75      $self->log("- " x 20, 'info');
76      $self->log("Performing Target '$targetname'.", 'notice');
77    
78    #exit;    #exit;
79    
# Line 96  sub perform_details { Line 116  sub perform_details {
116    foreach my $entry (@{$target->{content}}) {    foreach my $entry (@{$target->{content}}) {
117      my $command = $entry->{name};      my $command = $entry->{name};
118      my $args = $entry->{attrib};      my $args = $entry->{attrib};
119      $self->perform_command($command, $args);      my $content = $entry->{content};
120        $self->perform_command($command, $args, $content);
121      # check recursiveness      # check recursiveness
122      if ($entry->{content} && ref $entry->{content}) {      if ($entry->{content} && ref $entry->{content}) {
123        $self->perform_details($entry);        $self->perform_details($entry);
# Line 112  sub rc { Line 133  sub rc {
133  sub perform_command {  sub perform_command {
134    my $self = shift;    my $self = shift;
135    my $command = shift;    my $command = shift;
136      my $args_list = shift;
137      my $content = shift;
138    
139    if (!$command) {    if (!$command) {
140      $self->log("Command was empty!", 'debug');      $self->log("Command was empty!", 'debug');
# Line 121  sub perform_command { Line 144  sub perform_command {
144    # FIXME: make '__PACKAGE__' go one level deeper properly!    # FIXME: make '__PACKAGE__' go one level deeper properly!
145    $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug');    $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug');
146        
   my $args_list = shift;  
147    my $args = {};    my $args = {};
148    #print Dumper($args_list);    #print Dumper($args_list);
149    if ($args_list) {    if ($args_list) {
# Line 141  sub perform_command { Line 163  sub perform_command {
163    $container ||= $self;    $container ||= $self;
164        
165    if ($container->can($command)) {    if ($container->can($command)) {
166      $container->$command($args);      $container->$command($args, $content);
167    } else {    } else {
168      $self->log("Command '$command' not implemented.", "warning");      $self->log("Command '$command' not implemented.", "warning");
169    }    }
# Line 294  sub run_executable { Line 316  sub run_executable {
316    my $self = shift;    my $self = shift;
317    my $opts = shift;    my $opts = shift;
318    
319      my $meta = deep_copy($opts);
320    
321      delete $opts->{caption};
322      delete $opts->{async};
323    
324      #print Dumper($meta);
325    
326    if ($opts->{executable}) {    if ($opts->{executable}) {
327    
328      my $program = $opts->{executable};      my $program = $opts->{executable};
329      delete $opts->{executable};      delete $opts->{executable};
330    
331      # determine execution method      # determine execution method
     my $method = 'run_cmd';  
332      my $wrapper_program = '';      my $wrapper_program = '';
333            
334      # check if program is a namespace-string (contains '::') - use 'do' in this case!      # check if program is a namespace-string (contains '::') - use 'do' in this case!
335      if ($program =~ /::/) {      if ($program =~ /::/) {
336      #if ($program =~ s/::/\\/g) {        #$wrapper_program = 'rap.pl';
337        #$program = '.\\' . $program;        $wrapper_program = $0;
       #$method = 'require';  
       #do "$program";  
       #return;  
       #$method = 'rap.';  
         
       $wrapper_program = 'rap.pl';  
         
338      }      }
339    
340      # prepare arguments      # prepare arguments
# Line 337  sub run_executable { Line 358  sub run_executable {
358      }      }
359    
360      # build {program} & {arguments}        # build {program} & {arguments}  
361      my $cmd = join(' ', $wrapper_program, $program) . ' ' . join(' ', @buf);      my $cmd = ($wrapper_program ? $wrapper_program . ' ' : '') . $program . ' ' . join(' ', @buf);
362            
363      # trace      # trace
364        #print "command: $cmd", "\n";        #print "command: $cmd", "\n";
# Line 351  sub run_executable { Line 372  sub run_executable {
372                
373        #print Dumper(%ENV);        #print Dumper(%ENV);
374                
375        print "command: '$cmd'", "\n";        #print "command: '$cmd'", "\n";
376    
377        # V1 - basic        # V1 - basic
378        #run_cmd($cmd);        #run_cmd($cmd);
379    
380        # V1.b - enhanced: variable local method        # V1.b - enhanced: variable local method
381        my $evalstr = "$method('$cmd');";        $meta->{caption} ||= '';
382          $meta->{async} ||= 0;
383          my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async} });";
384        eval($evalstr);        eval($evalstr);
385        #my $res = do "$cmd";        #my $res = do "$cmd";
386        #print $res, "\n" if $res;        #print $res, "\n" if $res;
# Line 367  sub run_executable { Line 390  sub run_executable {
390    
391        # V2: via IPC::Run        # V2: via IPC::Run
392        # ....  (TODO)        # ....  (TODO)
393              
394            
395    }    }
396        
397  }  }
398    
399    
400    sub run_script {
401    
402      my $self = shift;
403      my $args = shift;
404      my $code = shift;
405    
406      if ($args->{language} eq 'msdos/bat') {
407        
408        #print "code: $code", "\n";
409        
410        # reporting
411        $self->log("Executing some arbitrary unsigned code (probably unsafe). [language=$args->{language}]", 'info');
412        $self->log("\n<code>\n$code\n</code>", 'info');
413        
414        # create temporary intermediate file to execute code
415        my $tmpdir = '/tmp/rap';
416        mkdir $tmpdir;
417        (my $fh, my $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.bat' );
418        print $fh $code, "\n";
419        run_cmd( $filename, '', { async => 1 } );
420        
421        # FIXME: DELETE code inside temp-files as soon as possible!
422        #print $fh '';
423        
424        # TODO: delete FILE completely!
425        # required for this: wait until execution has finished, then unlink....
426        # but: "how to wait until execution is finished"?
427        # i believe the best is to spawn *another* process directly from here,
428        # let's call it 'watcher-agent'.
429        # This one should monitor a certain running process and delete its
430        # executable file after it has finished execution.
431        # Possible extensions could be:
432        #   keep track of all stuff sent to STDOUT or STDERR and
433        #   send that stuff to the task-owner indirectly (not via shell/console)
434        #   (e.g. via email, by posting report to a newsgroup or publishing on a specified web-page: use mod-dav!)
435        
436      } elsif ($args->{language} eq 'bash') {
437        $self->log("FIXME: - - - - - -- - - --  BASH -  - -    -  - -   -    --   - ", 'error');
438        
439      } else {
440        $self->log("FIXME: Script language '$args->{language}' not implemented.", 'error');
441        
442      }
443    
444    }
445    
446  1;  1;
447  __END__  __END__

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.9

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed