Skip to content

Commit

Permalink
and munge thrift too
Browse files Browse the repository at this point in the history
  • Loading branch information
acme committed Jul 10, 2009
1 parent 1a855ad commit f26330e
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions bin/build.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
my $cassandra_class
= 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' );
my $gen_perl_dir = dir( cwd, 'gen-perl' );
my $perl_dir = dir( cwd, 'lib', 'Net', 'Cassandra', 'Backend' );
my $thrift_perl_dir = dir( cwd, 'thrift-trunk', 'lib', 'perl', 'lib' );

unless ( -d $thrift_trunk_dir ) {
say 'Fetching Thrift';
Expand Down Expand Up @@ -94,24 +95,34 @@

# first let's find the package names
my %packages;
foreach my $source ( File::Find::Rule->new->file->in($gen_perl_dir) ) {
say "$source";
foreach my $source ( File::Find::Rule->new->file->name('*.pm')
->in( $gen_perl_dir, $thrift_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;
#say $package;
$packages{ $package->namespace } = 1;
}
}
$packages{Types} = 1; # fake
$packages{Types} = 1; # fake
$packages{Thrift} = 1; # fake

# now fix up the new package names
foreach my $source ( File::Find::Rule->new->file->in($gen_perl_dir) ) {
foreach my $source ( File::Find::Rule->new->file->name('*.pm')
->in( $gen_perl_dir, $thrift_perl_dir ) )
{
my $destination = file( $perl_dir, file($source)->basename );
if ( $source =~ m{/Thrift/} ) {
$destination =~ s{/([^/]+?)$}{/Thrift/$1};
}
say "$source -> $destination";

my $document = PPI::Document->new($source);

# first change the words
Expand All @@ -125,6 +136,14 @@

#say "* $word";
} else {
my ( $pre, $post ) = split( '::', $namespace, 2 );
if ( $packages{$pre} ) {
$namespace
= 'Net::Cassandra::Backend::' . $pre . '::' . $post;
$word->set_content($namespace);

#say "* $word";
}

#say $word;
}
Expand All @@ -140,11 +159,14 @@
if ( $packages{$namespace} ) {
$namespace = 'Net::Cassandra::Backend::' . $namespace;
$word->set_content( "'" . $namespace . "'" );
say "** $word";

#say "** $word";
} else {
say "?? $word";

#say "?? $word";
}
}
dir($destination)->parent->mkpath;
$document->save($destination);
}
die 'Failed to build' unless -f "$perl_dir/Cassandra.pm";
Expand Down

0 comments on commit f26330e

Please sign in to comment.