1 |
#!/usr/bin/perl |
2 |
|
3 |
## ------------------------------------------------------------------------- |
4 |
## $Id: rap.pl,v 1.4 2003/03/27 15:58:08 joko Exp $ |
5 |
## ------------------------------------------------------------------------- |
6 |
## $Log: rap.pl,v $ |
7 |
## Revision 1.4 2003/03/27 15:58:08 joko |
8 |
## enhancement: now can execute perl-programs via 'do' here |
9 |
## |
10 |
## Revision 1.3 2003/02/20 21:39:49 joko |
11 |
## - find_rules moved to Rap.pm |
12 |
## |
13 |
## Revision 1.2 2003/02/18 19:09:07 jonen |
14 |
## + cwd for linux bootstrap |
15 |
## |
16 |
## Revision 1.1 2003/02/18 15:30:52 joko |
17 |
## + initial commit |
18 |
## |
19 |
## ------------------------------------------------------------------------- |
20 |
|
21 |
|
22 |
use strict; |
23 |
use warnings; |
24 |
|
25 |
|
26 |
use File::Spec::Functions qw( splitpath splitdir catpath catdir ); |
27 |
|
28 |
sub popdir { |
29 |
my $path = shift; |
30 |
my $popcount = shift; |
31 |
(my $volume, my $directory, my $file) = splitpath( $path ); |
32 |
my @dir = splitdir($directory); |
33 |
while ($popcount--) { |
34 |
pop @dir; |
35 |
} |
36 |
#pop @dir; |
37 |
|
38 |
#my $base = catpath($volume, catdir(@dir)); |
39 |
my $base = join('/', @dir); |
40 |
$base = $volume . $base if $volume; |
41 |
|
42 |
return $base; |
43 |
} |
44 |
|
45 |
|
46 |
|
47 |
BEGIN { |
48 |
use FindBin qw($Bin); |
49 |
#use lib "$Bin/../../libs"; |
50 |
my $libpath = popdir($Bin, 2) . '/libs'; |
51 |
#print "libpath: $libpath", "\n"; |
52 |
#exit; |
53 |
my $evs = "use lib '$libpath';"; |
54 |
#print "evs: $evs", "\n"; |
55 |
eval($evs); |
56 |
die($@) if $@; |
57 |
} |
58 |
|
59 |
|
60 |
# ------------------------------------ main ------------ |
61 |
use Data::Dumper; |
62 |
use Data::Rap; |
63 |
|
64 |
|
65 |
sub main { |
66 |
my $argString = shift; |
67 |
|
68 |
# check if target is a namespace-string (contains '::') |
69 |
# TODO: move this logic/code to inside Data::Rap! |
70 |
if ($argString =~ s/::/\//g) { |
71 |
my $res = do "$argString"; |
72 |
print $res, "\n" if $res; |
73 |
} else { |
74 |
my $rap = Data::Rap->new( target => $argString ); |
75 |
rap_boot(); |
76 |
$rap->start(); |
77 |
#$rap->stop(); |
78 |
} |
79 |
} |
80 |
|
81 |
sub rap_boot { |
82 |
# check for another environment-variable: 'RAPBIN' |
83 |
# FIXME: what about 'topic.basedir'??? implement this here! |
84 |
# enhance infrastructure to have per-topic basedirs!!! |
85 |
chdir $ENV{RAPBIN} if $ENV{RAPBIN}; |
86 |
} |
87 |
|
88 |
my @args = @ARGV; |
89 |
@args = () if not @args; |
90 |
main(join(' ', @args)); |
91 |
|
92 |
|
93 |
1; |
94 |
__END__ |