| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use File::Copy qw/move/; |
| 7 |
use Parse::RecDescent 1.94; |
| 8 |
|
| 9 |
sub read_file { |
| 10 |
my $file = shift; |
| 11 |
local ( $/, *FH ); |
| 12 |
open( FH, $file ) or return undef; |
| 13 |
return <FH>; |
| 14 |
} |
| 15 |
|
| 16 |
build_parser( |
| 17 |
'lib/Mail/IMAPClient/BodyStructure/Parse.grammar', |
| 18 |
'Mail::IMAPClient::BodyStructure::Parse' |
| 19 |
); |
| 20 |
|
| 21 |
build_parser( 'lib/Mail/IMAPClient/Thread.grammar', |
| 22 |
'Mail::IMAPClient::Thread' ); |
| 23 |
|
| 24 |
sub build_parser { |
| 25 |
my ( $grammarfn, $package ) = @_; |
| 26 |
|
| 27 |
print("* building $package\n"); |
| 28 |
|
| 29 |
my $grammar = read_file($grammarfn) |
| 30 |
or die("cannot read grammar from $grammarfn: $!\n"); |
| 31 |
|
| 32 |
Parse::RecDescent->Precompile( $grammar, $package ); |
| 33 |
|
| 34 |
# clumpsy output by Parse::RecDescent |
| 35 |
my $outfn = $package . '.pm'; |
| 36 |
$outfn =~ s/.*\:\://; |
| 37 |
|
| 38 |
my $realfn = $grammarfn; |
| 39 |
$realfn =~ s/\.\w+$/.pm/; |
| 40 |
|
| 41 |
move( $outfn, $realfn ) |
| 42 |
or die("cannot move $outfn to $realfn: $!\n"); |
| 43 |
} |