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

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

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

revision 1.2 by joko, Thu Feb 20 19:37:09 2003 UTC revision 1.8 by joko, Mon Jun 7 16:45:56 2004 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.8  2004/06/07 16:45:56  joko
6    ##  now propagates args to "rapcall method"
7    ##
8    ##  Revision 1.7  2003/05/13 07:52:14  joko
9    ##  enhanced: *hierarchical* containers for context handling
10    ##  making methods from foreign context(s) available
11    ##  started: import of targets from foreign topics
12    ##
13    ##  Revision 1.6  2003/03/29 07:10:42  joko
14    ##  + sub _script:
15    ##    new rap-command: '<script language="msdos/bat|bash|...">...</script>'
16    ##
17    ##  Revision 1.5  2003/03/27 15:31:04  joko
18    ##  fixes to modules regarding new namespace(s) below Data::Mungle::*
19    ##
20    ##  Revision 1.4  2003/02/22 16:48:58  joko
21    ##  modified rapcall behaviour
22    ##
23    ##  Revision 1.3  2003/02/21 07:39:13  joko
24    ##  modified 'rapcall' processing
25    ##  modified merging of options/arguments in there
26    ##
27  ##  Revision 1.2  2003/02/20 19:37:09  joko  ##  Revision 1.2  2003/02/20 19:37:09  joko
28  ##  renamed modules  ##  renamed modules
29  ##  - removed command 'exec'  ##  - removed command 'exec'
# Line 26  use Data::Dumper; Line 48  use Data::Dumper;
48  use Hash::Merge qw( merge );  use Hash::Merge qw( merge );
49    
50  use DesignPattern::Object;  use DesignPattern::Object;
51  use Data::Transform::Deep qw( merge_to );  use Data::Mungle::Transform::Deep qw( merge_to );
52  use shortcuts qw( run_cmd );  use shortcuts qw( run_cmd );
53    
54    
# Line 56  sub _echo { Line 78  sub _echo {
78  sub _context {  sub _context {
79    my $self = shift;    my $self = shift;
80    my $args = shift;    my $args = shift;
81    print Dumper($args);    print "_context-args: ", Dumper($args);
82    foreach my $task_command (keys %$args) {    foreach my $task_command (keys %$args) {
83      my $bunch = $args->{$task_command};      my $bunch = $args->{$task_command};
84      foreach my $task_args (@$bunch) {      foreach my $task_args (@$bunch) {
# Line 72  sub _id {} Line 94  sub _id {}
94  # FIXME  # FIXME
95  sub _description {}  sub _description {}
96    
97    # NEW [2003-05-08]: Hierarchical handling (stack push/pop instead of set/get).
98    # TODO: Named Containers.
99  sub _container {  sub _container {
100    my $self = shift;    my $self = shift;
101    my $args = shift;    my $args = shift;
102    $self->setContainer($args);    $self->pushContainer($args);
103    }
104    
105    sub _container_end {
106      my $self = shift;
107      my $args = shift;
108      $self->popContainer();
109  }  }
110    
111  sub _sync {  sub _sync {
# Line 113  sub _dump { Line 143  sub _dump {
143  sub _plugin {  sub _plugin {
144    my $self = shift;    my $self = shift;
145    my $args = shift;    my $args = shift;
146      my $content = shift;
147    
148    if (my $instance = $args->{instance}) {    if (my $instance = $args->{instance}) {
149      #$self->{$instance} = DesignPattern::Object->fromPackage($args->{module});      #$self->{$instance} = DesignPattern::Object->fromPackage($args->{module});
# Line 184  sub _plugin { Line 215  sub _plugin {
215        $container->load($name);        $container->load($name);
216    
217      # 3. methods - run object methods          # 3. methods - run object methods    
218    
219          # payload inside $content is the $args to the $method
220          # convert xml-style payload inside $content to trivial (not-nested) perl hash
221          # using just encapsulated text of the nodes as hash values
222          my $method_args;
223          foreach (@$content) {
224            my $key = $_->{name};
225            my $value = $_->{content}->[0]->{content};
226            $method_args->{$key} = $value;
227          }
228          # convert hashref to arrayref
229          $method_args = [ %$method_args ] if ref $method_args eq 'HASH';
230    
231        if (my $methods = $args->{methods}) {        if (my $methods = $args->{methods}) {
232          my @methods = split(/,|,\s/, $methods);          my @methods = split(/,|,\s/, $methods);
233          foreach (@methods) {          foreach (@methods) {
234            $self->log("Running method '$_'.", 'info');            $self->log("Running method '$_'.", 'info');
235            $container->$_() if $container->can($_);            #print Dumper($method_args);
236              # check for existance of method
237              if ($container->can($_)) {
238                # dispatch call by being with or without arguments
239                print "method_args: ", Dumper($method_args);
240                if ($method_args) {
241                  $container->$_(@$method_args);
242                } else {
243                  $container->$_();
244                }
245              }
246          }          }
247        }        }
248                
# Line 209  sub _rapcall { Line 263  sub _rapcall {
263    my $self = shift;    my $self = shift;
264    my $args = shift;    my $args = shift;
265    
266      # merge container arguments to local ones if desired/requested/forced
267    if (my $container = $self->getContainer()) {    if (my $container = $self->getContainer()) {
268      my $opts = merge($container, $args);      #my $opts = merge($container, $args);
269      if ($opts->{executable}) {      #print Dumper($container);
270        $self->run_executable($opts);      merge_to($args, $container, { init => 1 });
271      }    }
272      
273      # trace
274      #print Dumper($args);
275    
276      #print Dumper($opts);    # action dispatcher, either do:
277      #   - run an executable program [ext]
278      #   - call a command (?) [rap]
279      #   - a rap target [rap]
280      #   - a code method [ext]
281      
282      if ($args->{executable}) {
283        $self->run_executable($args);
284      return;      return;
285    }    }
286    
287    if (my $command = $args->{command}) {    if (my $command = $args->{command}) {
288      $self->perform_command($command, $args);      $self->perform_command($command, $args);
289        return;
290    }    }
291    
292    if (my $target = $args->{target}) {    if (my $target = $args->{target}) {
293      $self->performTarget($target, $args);      $self->performTarget($target, $args);
294        return;
295    }    }
296    
297    if (my $method = $args->{method}) {    if (my $method = $args->{method}) {
# Line 233  sub _rapcall { Line 300  sub _rapcall {
300        #eval($namespace . '::' . $method . '();');        #eval($namespace . '::' . $method . '();');
301        #die($@) if $@;        #die($@) if $@;
302        #print Dumper($self);        #print Dumper($self);
303        $self->{$refkey}->$method();        
304          #if ($args->{args} && lc $args->{args} eq 'array') {
305            #print Dumper($args);
306            #print Dumper($self);
307          #}
308          
309          # V1 - no arguments were being propagated
310          #$self->{$refkey}->$method();
311          # V2 - trying this....
312          $self->{$refkey}->$method($args->{args});
313    
314      } elsif (my $ref = $self->getInstance()) {      } elsif (my $ref = $self->getInstance()) {
315        $ref->$method();        $ref->$method($args->{args});
316      }      }
317        
318        return;
319    
320    }    }
321        
322  }  }
# Line 249  sub _exit { Line 328  sub _exit {
328  sub _use {  sub _use {
329    my $self = shift;    my $self = shift;
330    my $args = shift;    my $args = shift;
331    my $name = $args->{name};    
332    $self->log("Switching to '$name'.", 'info');    # new of ~2003-04-15: making methods from foreign context(s) available
333    $self->setInstance($self->{$name}) if $args->{type} eq 'instance';    if (my $name = $args->{name}) {
334        $args->{type} ||= '';
335        $self->log("Switching to $args->{type} '$name'.", 'info');
336        $self->setInstance($self->{$name}) if $args->{type} eq 'instance';
337      }
338      
339      # new of ~2003-04-15: making methods from foreign context(s) available
340      if (exists $args->{method_prefix}) {
341        #print "YAI", "\n";
342        #print Dumper($args);
343        $self->set_property( { name => 'core.method_prefix', value => $args->{method_prefix} } );
344      }
345      
346      # TODO: (possible feature)
347      # check for $args->{export_rap_commands} to export core rap-commands
348      # from rap engine's scope to the worker's
349      
350    }
351    
352    sub _script {
353      my $self = shift;
354      my $args = shift;
355      my $content = shift;
356      
357      # trace
358      #print Dumper($args);
359      #print Dumper($content);
360    
361      my $code = $content->[0]->{content};
362      $code ||= '';
363    
364      $self->run_script($args, $code);
365      
366  }  }
367    
368    sub _import {
369      my $self = shift;
370      my $args = shift;
371      #my $content = shift;
372    
373      if (!$args->{topic}) {
374        $self->log("Please specify topic.", 'warning');
375        return;
376      }
377    
378      $self->log("Importing all targets from topic '$args->{topic}'.", 'info');
379      
380      #print Dumper($self);
381      # FIXME: This was started off, but not finished!
382      print "registry: ", Dumper($Data::Rap::registry);
383      
384    }
385    
386  1;  1;
387  __END__  __END__

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

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