--- nfo/perl/scripts/shortcuts/rap.pl 2003/02/18 15:30:52 1.1 +++ nfo/perl/scripts/shortcuts/rap.pl 2003/03/27 15:58:08 1.4 @@ -1,9 +1,18 @@ #!/usr/bin/perl ## ------------------------------------------------------------------------- -## $Id: rap.pl,v 1.1 2003/02/18 15:30:52 joko Exp $ +## $Id: rap.pl,v 1.4 2003/03/27 15:58:08 joko Exp $ ## ------------------------------------------------------------------------- ## $Log: rap.pl,v $ +## Revision 1.4 2003/03/27 15:58:08 joko +## enhancement: now can execute perl-programs via 'do' here +## +## Revision 1.3 2003/02/20 21:39:49 joko +## - find_rules moved to Rap.pm +## +## Revision 1.2 2003/02/18 19:09:07 jonen +## + cwd for linux bootstrap +## ## Revision 1.1 2003/02/18 15:30:52 joko ## + initial commit ## @@ -13,9 +22,38 @@ use strict; use warnings; + +use File::Spec::Functions qw( splitpath splitdir catpath catdir ); + +sub popdir { + my $path = shift; + my $popcount = shift; + (my $volume, my $directory, my $file) = splitpath( $path ); + my @dir = splitdir($directory); + while ($popcount--) { + pop @dir; + } + #pop @dir; + + #my $base = catpath($volume, catdir(@dir)); + my $base = join('/', @dir); + $base = $volume . $base if $volume; + + return $base; +} + + + BEGIN { use FindBin qw($Bin); - use lib "$Bin/../../libs"; + #use lib "$Bin/../../libs"; + my $libpath = popdir($Bin, 2) . '/libs'; + #print "libpath: $libpath", "\n"; + #exit; + my $evs = "use lib '$libpath';"; + #print "evs: $evs", "\n"; + eval($evs); + die($@) if $@; } @@ -23,15 +61,20 @@ use Data::Dumper; use Data::Rap; -sub find_rules { - return '../etc/rap.xml'; -} sub main { my $argString = shift; - my $rulesfile = find_rules(); - my $rap = Data::Rap->new( filename => $rulesfile, target => $argString ); - $rap->start(); + + # check if target is a namespace-string (contains '::') + # TODO: move this logic/code to inside Data::Rap! + if ($argString =~ s/::/\//g) { + my $res = do "$argString"; + print $res, "\n" if $res; + } else { + my $rap = Data::Rap->new( target => $argString ); + $rap->start(); + #$rap->stop(); + } } my @args = @ARGV;