--- nfo/perl/libs/Data/Rap/Command.pm 2003/02/20 19:37:09 1.2 +++ nfo/perl/libs/Data/Rap/Command.pm 2003/05/13 07:52:14 1.7 @@ -1,7 +1,26 @@ ## ---------------------------------------------------------------------- -## $Id: Command.pm,v 1.2 2003/02/20 19:37:09 joko Exp $ +## $Id: Command.pm,v 1.7 2003/05/13 07:52:14 joko Exp $ ## ---------------------------------------------------------------------- ## $Log: Command.pm,v $ +## Revision 1.7 2003/05/13 07:52:14 joko +## enhanced: *hierarchical* containers for context handling +## making methods from foreign context(s) available +## started: import of targets from foreign topics +## +## Revision 1.6 2003/03/29 07:10:42 joko +## + sub _script: +## new rap-command: '' +## +## Revision 1.5 2003/03/27 15:31:04 joko +## fixes to modules regarding new namespace(s) below Data::Mungle::* +## +## Revision 1.4 2003/02/22 16:48:58 joko +## modified rapcall behaviour +## +## Revision 1.3 2003/02/21 07:39:13 joko +## modified 'rapcall' processing +## modified merging of options/arguments in there +## ## Revision 1.2 2003/02/20 19:37:09 joko ## renamed modules ## - removed command 'exec' @@ -26,7 +45,7 @@ use Hash::Merge qw( merge ); use DesignPattern::Object; -use Data::Transform::Deep qw( merge_to ); +use Data::Mungle::Transform::Deep qw( merge_to ); use shortcuts qw( run_cmd ); @@ -56,7 +75,7 @@ sub _context { my $self = shift; my $args = shift; - print Dumper($args); + print "_context-args: ", Dumper($args); foreach my $task_command (keys %$args) { my $bunch = $args->{$task_command}; foreach my $task_args (@$bunch) { @@ -72,10 +91,18 @@ # FIXME sub _description {} +# NEW [2003-05-08]: Hierarchical handling (stack push/pop instead of set/get). +# TODO: Named Containers. sub _container { my $self = shift; my $args = shift; - $self->setContainer($args); + $self->pushContainer($args); +} + +sub _container_end { + my $self = shift; + my $args = shift; + $self->popContainer(); } sub _sync { @@ -113,6 +140,7 @@ sub _plugin { my $self = shift; my $args = shift; + my $content = shift; if (my $instance = $args->{instance}) { #$self->{$instance} = DesignPattern::Object->fromPackage($args->{module}); @@ -184,11 +212,34 @@ $container->load($name); # 3. methods - run object methods + + # payload inside $content is the $args to the $method + # convert xml-style payload inside $content to trivial (not-nested) perl hash + # using just encapsulated text of the nodes as hash values + my $method_args; + foreach (@$content) { + my $key = $_->{name}; + my $value = $_->{content}->[0]->{content}; + $method_args->{$key} = $value; + } + # convert hashref to arrayref + $method_args = [ %$method_args ] if ref $method_args eq 'HASH'; + if (my $methods = $args->{methods}) { my @methods = split(/,|,\s/, $methods); foreach (@methods) { $self->log("Running method '$_'.", 'info'); - $container->$_() if $container->can($_); + #print Dumper($method_args); + # check for existance of method + if ($container->can($_)) { + # dispatch call by being with or without arguments + print "method_args: ", Dumper($method_args); + if ($method_args) { + $container->$_(@$method_args); + } else { + $container->$_(); + } + } } } @@ -209,22 +260,35 @@ my $self = shift; my $args = shift; + # merge container arguments to local ones if desired/requested/forced if (my $container = $self->getContainer()) { - my $opts = merge($container, $args); - if ($opts->{executable}) { - $self->run_executable($opts); - } + #my $opts = merge($container, $args); + #print Dumper($container); + merge_to($args, $container, { init => 1 }); + } + + # trace + #print Dumper($args); - #print Dumper($opts); + # action dispatcher, either do: + # - run an executable program [ext] + # - call a command (?) [rap] + # - a rap target [rap] + # - a code method [ext] + + if ($args->{executable}) { + $self->run_executable($args); return; } if (my $command = $args->{command}) { $self->perform_command($command, $args); + return; } if (my $target = $args->{target}) { $self->performTarget($target, $args); + return; } if (my $method = $args->{method}) { @@ -233,11 +297,23 @@ #eval($namespace . '::' . $method . '();'); #die($@) if $@; #print Dumper($self); + + #if ($args->{args} && lc $args->{args} eq 'array') { + #print Dumper($args); + #print Dumper($self); + #} + + # V1 - no arguments were being propagated + #$self->{$refkey}->$method(); + # V2 - trying this.... $self->{$refkey}->$method(); } elsif (my $ref = $self->getInstance()) { $ref->$method(); } + + return; + } } @@ -249,11 +325,60 @@ sub _use { my $self = shift; my $args = shift; - my $name = $args->{name}; - $self->log("Switching to '$name'.", 'info'); - $self->setInstance($self->{$name}) if $args->{type} eq 'instance'; + + # new of ~2003-04-15: making methods from foreign context(s) available + if (my $name = $args->{name}) { + $args->{type} ||= ''; + $self->log("Switching to $args->{type} '$name'.", 'info'); + $self->setInstance($self->{$name}) if $args->{type} eq 'instance'; + } + + # new of ~2003-04-15: making methods from foreign context(s) available + if (exists $args->{method_prefix}) { + #print "YAI", "\n"; + #print Dumper($args); + $self->set_property( { name => 'core.method_prefix', value => $args->{method_prefix} } ); + } + + # TODO: (possible feature) + # check for $args->{export_rap_commands} to export core rap-commands + # from rap engine's scope to the worker's + } +sub _script { + my $self = shift; + my $args = shift; + my $content = shift; + + # trace + #print Dumper($args); + #print Dumper($content); + + my $code = $content->[0]->{content}; + $code ||= ''; + + $self->run_script($args, $code); + +} + +sub _import { + my $self = shift; + my $args = shift; + #my $content = shift; + + if (!$args->{topic}) { + $self->log("Please specify topic.", 'warning'); + return; + } + + $self->log("Importing all targets from topic '$args->{topic}'.", 'info'); + + #print Dumper($self); + # FIXME: This was started off, but not finished! + print "registry: ", Dumper($Data::Rap::registry); + +} 1; __END__