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