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