2 |
## $Id$ |
## $Id$ |
3 |
## ---------------------------------------------------------------------- |
## ---------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.9 2004/06/19 01:50:24 joko |
6 |
|
## disabled debugging statement |
7 |
|
## |
8 |
|
## Revision 1.8 2004/06/07 16:45:56 joko |
9 |
|
## now propagates args to "rapcall method" |
10 |
|
## |
11 |
|
## Revision 1.7 2003/05/13 07:52:14 joko |
12 |
|
## enhanced: *hierarchical* containers for context handling |
13 |
|
## making methods from foreign context(s) available |
14 |
|
## started: import of targets from foreign topics |
15 |
|
## |
16 |
## Revision 1.6 2003/03/29 07:10:42 joko |
## Revision 1.6 2003/03/29 07:10:42 joko |
17 |
## + sub _script: |
## + sub _script: |
18 |
## new rap-command: '<script language="msdos/bat|bash|...">...</script>' |
## new rap-command: '<script language="msdos/bat|bash|...">...</script>' |
81 |
sub _context { |
sub _context { |
82 |
my $self = shift; |
my $self = shift; |
83 |
my $args = shift; |
my $args = shift; |
84 |
print Dumper($args); |
print "_context-args: ", Dumper($args); |
85 |
foreach my $task_command (keys %$args) { |
foreach my $task_command (keys %$args) { |
86 |
my $bunch = $args->{$task_command}; |
my $bunch = $args->{$task_command}; |
87 |
foreach my $task_args (@$bunch) { |
foreach my $task_args (@$bunch) { |
97 |
# FIXME |
# FIXME |
98 |
sub _description {} |
sub _description {} |
99 |
|
|
100 |
|
# NEW [2003-05-08]: Hierarchical handling (stack push/pop instead of set/get). |
101 |
|
# TODO: Named Containers. |
102 |
sub _container { |
sub _container { |
103 |
my $self = shift; |
my $self = shift; |
104 |
my $args = shift; |
my $args = shift; |
105 |
$self->setContainer($args); |
$self->pushContainer($args); |
106 |
|
} |
107 |
|
|
108 |
|
sub _container_end { |
109 |
|
my $self = shift; |
110 |
|
my $args = shift; |
111 |
|
$self->popContainer(); |
112 |
} |
} |
113 |
|
|
114 |
sub _sync { |
sub _sync { |
146 |
sub _plugin { |
sub _plugin { |
147 |
my $self = shift; |
my $self = shift; |
148 |
my $args = shift; |
my $args = shift; |
149 |
|
my $content = shift; |
150 |
|
|
151 |
if (my $instance = $args->{instance}) { |
if (my $instance = $args->{instance}) { |
152 |
#$self->{$instance} = DesignPattern::Object->fromPackage($args->{module}); |
#$self->{$instance} = DesignPattern::Object->fromPackage($args->{module}); |
218 |
$container->load($name); |
$container->load($name); |
219 |
|
|
220 |
# 3. methods - run object methods |
# 3. methods - run object methods |
221 |
|
|
222 |
|
# payload inside $content is the $args to the $method |
223 |
|
# convert xml-style payload inside $content to trivial (not-nested) perl hash |
224 |
|
# using just encapsulated text of the nodes as hash values |
225 |
|
my $method_args; |
226 |
|
foreach (@$content) { |
227 |
|
my $key = $_->{name}; |
228 |
|
my $value = $_->{content}->[0]->{content}; |
229 |
|
$method_args->{$key} = $value; |
230 |
|
} |
231 |
|
# convert hashref to arrayref |
232 |
|
$method_args = [ %$method_args ] if ref $method_args eq 'HASH'; |
233 |
|
|
234 |
if (my $methods = $args->{methods}) { |
if (my $methods = $args->{methods}) { |
235 |
my @methods = split(/,|,\s/, $methods); |
my @methods = split(/,|,\s/, $methods); |
236 |
foreach (@methods) { |
foreach (@methods) { |
237 |
$self->log("Running method '$_'.", 'info'); |
$self->log("Running method '$_'.", 'info'); |
238 |
$container->$_() if $container->can($_); |
#print Dumper($method_args); |
239 |
|
# check for existance of method |
240 |
|
if ($container->can($_)) { |
241 |
|
# dispatch call by being with or without arguments |
242 |
|
#print "method_args: ", Dumper($method_args); |
243 |
|
if ($method_args) { |
244 |
|
$container->$_(@$method_args); |
245 |
|
} else { |
246 |
|
$container->$_(); |
247 |
|
} |
248 |
|
} |
249 |
} |
} |
250 |
} |
} |
251 |
|
|
266 |
my $self = shift; |
my $self = shift; |
267 |
my $args = shift; |
my $args = shift; |
268 |
|
|
269 |
|
# merge container arguments to local ones if desired/requested/forced |
270 |
if (my $container = $self->getContainer()) { |
if (my $container = $self->getContainer()) { |
271 |
#my $opts = merge($container, $args); |
#my $opts = merge($container, $args); |
272 |
#print Dumper($container); |
#print Dumper($container); |
274 |
} |
} |
275 |
|
|
276 |
# trace |
# trace |
277 |
#print Dumper($args); |
#print Dumper($args); |
278 |
|
|
279 |
|
# action dispatcher, either do: |
280 |
|
# - run an executable program [ext] |
281 |
|
# - call a command (?) [rap] |
282 |
|
# - a rap target [rap] |
283 |
|
# - a code method [ext] |
284 |
|
|
285 |
if ($args->{executable}) { |
if ($args->{executable}) { |
286 |
$self->run_executable($args); |
$self->run_executable($args); |
287 |
return; |
return; |
303 |
#eval($namespace . '::' . $method . '();'); |
#eval($namespace . '::' . $method . '();'); |
304 |
#die($@) if $@; |
#die($@) if $@; |
305 |
#print Dumper($self); |
#print Dumper($self); |
306 |
$self->{$refkey}->$method(); |
|
307 |
|
#if ($args->{args} && lc $args->{args} eq 'array') { |
308 |
|
#print Dumper($args); |
309 |
|
#print Dumper($self); |
310 |
|
#} |
311 |
|
|
312 |
|
# V1 - no arguments were being propagated |
313 |
|
#$self->{$refkey}->$method(); |
314 |
|
# V2 - trying this.... |
315 |
|
$self->{$refkey}->$method($args->{args}); |
316 |
|
|
317 |
} elsif (my $ref = $self->getInstance()) { |
} elsif (my $ref = $self->getInstance()) { |
318 |
$ref->$method(); |
$ref->$method($args->{args}); |
319 |
} |
} |
320 |
|
|
321 |
return; |
return; |
331 |
sub _use { |
sub _use { |
332 |
my $self = shift; |
my $self = shift; |
333 |
my $args = shift; |
my $args = shift; |
334 |
my $name = $args->{name}; |
|
335 |
$self->log("Switching to '$name'.", 'info'); |
# new of ~2003-04-15: making methods from foreign context(s) available |
336 |
$self->setInstance($self->{$name}) if $args->{type} eq 'instance'; |
if (my $name = $args->{name}) { |
337 |
|
$args->{type} ||= ''; |
338 |
|
$self->log("Switching to $args->{type} '$name'.", 'info'); |
339 |
|
$self->setInstance($self->{$name}) if $args->{type} eq 'instance'; |
340 |
|
} |
341 |
|
|
342 |
|
# new of ~2003-04-15: making methods from foreign context(s) available |
343 |
|
if (exists $args->{method_prefix}) { |
344 |
|
#print "YAI", "\n"; |
345 |
|
#print Dumper($args); |
346 |
|
$self->set_property( { name => 'core.method_prefix', value => $args->{method_prefix} } ); |
347 |
|
} |
348 |
|
|
349 |
|
# TODO: (possible feature) |
350 |
|
# check for $args->{export_rap_commands} to export core rap-commands |
351 |
|
# from rap engine's scope to the worker's |
352 |
|
|
353 |
} |
} |
354 |
|
|
355 |
sub _script { |
sub _script { |
368 |
|
|
369 |
} |
} |
370 |
|
|
371 |
|
sub _import { |
372 |
|
my $self = shift; |
373 |
|
my $args = shift; |
374 |
|
#my $content = shift; |
375 |
|
|
376 |
|
if (!$args->{topic}) { |
377 |
|
$self->log("Please specify topic.", 'warning'); |
378 |
|
return; |
379 |
|
} |
380 |
|
|
381 |
|
$self->log("Importing all targets from topic '$args->{topic}'.", 'info'); |
382 |
|
|
383 |
|
#print Dumper($self); |
384 |
|
# FIXME: This was started off, but not finished! |
385 |
|
print "registry: ", Dumper($Data::Rap::registry); |
386 |
|
|
387 |
|
} |
388 |
|
|
389 |
1; |
1; |
390 |
__END__ |
__END__ |