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