| 1 |
joko |
1.1 |
## ---------------------------------------------------------------------- |
| 2 |
|
|
## $Id: Ref.pm,v 1.1 2003/01/22 17:59:22 root Exp $ |
| 3 |
|
|
## ---------------------------------------------------------------------- |
| 4 |
|
|
## $Log: Ref.pm,v $ |
| 5 |
|
|
## ---------------------------------------------------------------------- |
| 6 |
|
|
|
| 7 |
|
|
|
| 8 |
|
|
package Data::Rap::Command; |
| 9 |
|
|
|
| 10 |
|
|
use strict; |
| 11 |
|
|
use warnings; |
| 12 |
|
|
|
| 13 |
|
|
|
| 14 |
|
|
use Data::Dumper; |
| 15 |
|
|
use Hash::Merge qw( merge ); |
| 16 |
|
|
use shortcuts qw( run_cmd ); |
| 17 |
|
|
use DesignPattern::Object; |
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
sub _exec { |
| 21 |
|
|
my $script = shift; |
| 22 |
|
|
my $task = shift; |
| 23 |
|
|
if ($script) { |
| 24 |
|
|
my @buf; |
| 25 |
|
|
foreach (keys %$task) { |
| 26 |
|
|
my $value = $task->{$_}; |
| 27 |
|
|
if ($value =~ /\s/) { |
| 28 |
|
|
$value = "\"$value\""; |
| 29 |
|
|
} |
| 30 |
|
|
push @buf, "--$_=$value"; |
| 31 |
|
|
} |
| 32 |
|
|
my $cmd = $script . ' ' . join(' ', @buf); |
| 33 |
|
|
run_cmd($cmd); |
| 34 |
|
|
} else { |
| 35 |
|
|
#$bizProcess->runSync($task); |
| 36 |
|
|
} |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
|
sub _echo { |
| 40 |
|
|
my $self = shift; |
| 41 |
|
|
my $args = shift; |
| 42 |
|
|
#print Dumper($args); |
| 43 |
|
|
my $message; |
| 44 |
|
|
my $level; |
| 45 |
|
|
|
| 46 |
|
|
if (ref $args eq 'HASH') { |
| 47 |
|
|
$message = $args->{message}; |
| 48 |
|
|
$level = $args->{level}; |
| 49 |
|
|
} else { |
| 50 |
|
|
my @buf = (); |
| 51 |
|
|
push @buf, $args; |
| 52 |
|
|
push @buf, @_; |
| 53 |
|
|
$message = join(' ', @buf); |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
$message ||= 'n/a'; |
| 57 |
|
|
$level ||= 'info'; |
| 58 |
|
|
|
| 59 |
|
|
$self->log($message, $level); |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
sub _context { |
| 63 |
|
|
my $self = shift; |
| 64 |
|
|
my $args = shift; |
| 65 |
|
|
#print Dumper($args); |
| 66 |
|
|
foreach my $task_command (keys %$args) { |
| 67 |
|
|
my $bunch = $args->{$task_command}; |
| 68 |
|
|
foreach my $task_args (@$bunch) { |
| 69 |
|
|
#print Dumper($task_args); |
| 70 |
|
|
$self->run_command($task_command, $task_args); |
| 71 |
|
|
} |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
# FIXME |
| 76 |
|
|
sub _id {} |
| 77 |
|
|
|
| 78 |
|
|
# FIXME |
| 79 |
|
|
sub _description {} |
| 80 |
|
|
|
| 81 |
|
|
sub _feed { |
| 82 |
|
|
my $self = shift; |
| 83 |
|
|
|
| 84 |
|
|
} |
| 85 |
|
|
|
| 86 |
|
|
sub _bootDatabases { |
| 87 |
|
|
my $self = shift; |
| 88 |
|
|
#print Dumper($self->{config}->{databases}); |
| 89 |
|
|
|
| 90 |
|
|
$self->log("Using Database(s): " . join(', ', @{$self->{use_databases}}), 'info'); |
| 91 |
|
|
|
| 92 |
|
|
my $dbcfg; |
| 93 |
|
|
my $container = DesignPattern::Object->fromPackage('Data::Storage::Container'); |
| 94 |
|
|
|
| 95 |
|
|
# just boot specified databases |
| 96 |
|
|
if (my $dbkeys = $self->{use_databases}) { |
| 97 |
|
|
foreach (@$dbkeys) { |
| 98 |
|
|
$dbcfg->{$_} = $self->{config}->{databases}->{$_}; |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
# boot all databases |
| 102 |
|
|
} else { |
| 103 |
|
|
$dbcfg = $self->{config}->{databases}; |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
foreach (keys %$dbcfg) { |
| 107 |
|
|
$container->addConfig($_, $dbcfg->{$_}); |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
$container->initLocators(); |
| 111 |
|
|
$container->initStorages(); |
| 112 |
|
|
|
| 113 |
|
|
foreach (keys %{$container->{storage}}) { |
| 114 |
|
|
$self->{storage}->{$_} = $container->{storage}->{$_}; |
| 115 |
|
|
} |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
sub _depends_old { |
| 119 |
|
|
my $self = shift; |
| 120 |
|
|
my $args = shift; |
| 121 |
|
|
#print Dumper($args); |
| 122 |
|
|
$self->performTarget($args); |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
sub _dump { |
| 126 |
|
|
my $self = shift; |
| 127 |
|
|
my $args = shift; |
| 128 |
|
|
my $name = $args->{name}; |
| 129 |
|
|
my $message = Dumper($self->{$name}); |
| 130 |
|
|
$self->rc('echo', $message, $args->{level}); |
| 131 |
|
|
} |
| 132 |
|
|
|
| 133 |
|
|
sub _plugin { |
| 134 |
|
|
my $self = shift; |
| 135 |
|
|
my $args = shift; |
| 136 |
|
|
if (my $name = $args->{name}) { |
| 137 |
|
|
$self->load($name); |
| 138 |
|
|
} |
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
|
|
sub _rapcall { |
| 142 |
|
|
my $self = shift; |
| 143 |
|
|
my $args = shift; |
| 144 |
|
|
if (my $command = $args->{command}) { |
| 145 |
|
|
$self->run_command($command, $args); |
| 146 |
|
|
} |
| 147 |
|
|
|
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
|
|
| 151 |
|
|
1; |
| 152 |
|
|
__END__ |