--- nfo/perl/libs/Data/Rap/Command.pm 2003/03/29 07:10:42 1.6 +++ nfo/perl/libs/Data/Rap/Command.pm 2003/05/13 07:52:14 1.7 @@ -1,7 +1,12 @@ ## ---------------------------------------------------------------------- -## $Id: Command.pm,v 1.6 2003/03/29 07:10:42 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: '' @@ -70,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) { @@ -86,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 { @@ -127,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}); @@ -198,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->$_(); + } + } } } @@ -223,6 +260,7 @@ 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); #print Dumper($container); @@ -230,8 +268,14 @@ } # trace - #print Dumper($args); + #print Dumper($args); + # 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; @@ -253,6 +297,15 @@ #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()) { @@ -272,9 +325,25 @@ 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 { @@ -293,5 +362,23 @@ } +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__