Added libextutils-xspp-perl
[pkg-perl] / deb-src / libextutils-xspp-perl / libextutils-xspp-perl-0.07 / inc / My / Build.pm
1 package My::Build;
2
3 use strict;
4 use warnings;
5 use base qw(Module::Build);
6 use File::Spec ();
7
8 sub ACTION_code {
9     my( $self ) = @_;
10
11     # Generate the parser using yapp
12     my $grammar_module = File::Spec->catfile(qw(lib ExtUtils XSpp Grammar.pm));
13     if( !$self->up_to_date( [ 'XSP.yp' ],
14                             [ $grammar_module ] ) ) {
15         $self->do_system( 'yapp', '-v', '-m', 'ExtUtils::XSpp::Grammar', '-s',
16                           '-o', $grammar_module, 'XSP.yp' );
17
18         # Replace the copy Parse::Yapp::Driver with a package in
19         # our own namespace hierarchy
20         open my $fh, '+<', $grammar_module
21           or die "Could not open file '$grammar_module' for rw: $!";
22         my @code = map {
23           s{(?<!Module )Parse::Yapp::Driver}
24            {ExtUtils::XSpp::Grammar::YappDriver}gx;
25           $_
26         } <$fh>;
27         seek $fh, 0, 0;
28         truncate $fh, 0;
29         print $fh @code;
30         close $fh or die "Updating grammar module failed: $!";
31     }
32
33     $self->SUPER::ACTION_code;
34 }
35
36 1;