Permalink
Browse files

munge namespace

  • Loading branch information...
1 parent ead3847 commit 1a855ad41230b3ef09da4d5cc7541e47bbe915c8 @acme committed Jul 9, 2009
Showing with 76 additions and 1 deletion.
  1. +76 −1 bin/build.pl
View
@@ -1,10 +1,13 @@
#!/home/acme/perl-5.10.0/bin//perl
use strict;
use warnings;
+use Cwd;
+use File::Find::Rule;
use LWP::Simple;
use Perl6::Say;
use Path::Class;
-use Cwd;
+use PPI;
+use PPI::Find;
my $thrift_trunk_dir = dir( cwd, 'thrift-trunk' );
my $thrift_trunk_configure = file( $thrift_trunk_dir, 'configure' );
@@ -17,6 +20,7 @@
= dir( cwd, 'cassandra-trunk', 'build', 'classes', 'org', 'apache',
'cassandra', 'service', 'CassandraDaemon.class' );
my $gen_perl_dir = dir( cwd, 'gen-perl' );
+my $perl_dir = dir( cwd, 'lib', 'Net', 'Cassandra', 'Backend' );
unless ( -d $thrift_trunk_dir ) {
say 'Fetching Thrift';
@@ -74,3 +78,74 @@
"$thrift_installed_dir/bin/thrift --gen perl $cassandra_trunk_dir/interface/cassandra.thrift";
die 'Failed to generate' unless -d $gen_perl_dir;
}
+
+unless ( -f $cassandra_class ) {
+ say 'Building Cassandra';
+ chdir $cassandra_trunk_dir;
+ system "ant";
+ die 'Failed to build' unless -f $cassandra_class;
+}
+
+# my $gen_perl_dir = dir( cwd, 'gen-perl' );
+# my $perl_dir = dir(cwd, 'lib', 'Net', 'Cassandra', 'Backend');
+
+unless ( -f "$perl_dir/Cassandra.pm" ) {
+ say 'Munging Cassandra Perl modules';
+
+ # first let's find the package names
+ my %packages;
+ foreach my $source ( File::Find::Rule->new->file->in($gen_perl_dir) ) {
+ say "$source";
+ my $document = PPI::Document->new($source);
+ my $find
+ = PPI::Find->new( sub { $_[0]->isa('PPI::Statement::Package') } );
+ $find->start($document) or die "Failed to execute search";
+ while ( my $package = $find->match ) {
+
+ # say $package;
+ $packages{ $package->namespace } = 1;
+ }
+ }
+ $packages{Types} = 1; # fake
+
+ # now fix up the new package names
+ foreach my $source ( File::Find::Rule->new->file->in($gen_perl_dir) ) {
+ my $destination = file( $perl_dir, file($source)->basename );
+ say "$source -> $destination";
+ my $document = PPI::Document->new($source);
+
+ # first change the words
+ my $find = PPI::Find->new( sub { $_[0]->isa('PPI::Token::Word') } );
+ $find->start($document) or die "Failed to execute search";
+ while ( my $word = $find->match ) {
+ my $namespace = $word->content;
+ if ( $packages{$namespace} ) {
+ $namespace = 'Net::Cassandra::Backend::' . $namespace;
+ $word->set_content($namespace);
+
+ #say "* $word";
+ } else {
+
+ #say $word;
+ }
+ }
+
+ # now try quotes
+ $find = PPI::Find->new( sub { $_[0]->isa('PPI::Token::Quote') } );
+ $find->start($document) or die "Failed to execute search";
+ while ( my $word = $find->match ) {
+ my $namespace = $word->content;
+ $namespace =~ s/^'//;
+ $namespace =~ s/'$//;
+ if ( $packages{$namespace} ) {
+ $namespace = 'Net::Cassandra::Backend::' . $namespace;
+ $word->set_content( "'" . $namespace . "'" );
+ say "** $word";
+ } else {
+ say "?? $word";
+ }
+ }
+ $document->save($destination);
+ }
+ die 'Failed to build' unless -f "$perl_dir/Cassandra.pm";
+}

0 comments on commit 1a855ad

Please sign in to comment.