braden has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to precompile a Parse::RecDescent grammar as part of building my module. In Build.PL I have:
use Module::Build; use Parse::RecDescent; my $class = Module::Build->subclass(code => <<'EOF'); sub ACTION_build { my $self = shift; open FILE, "grammar" or die "could not open \"grammar\": $!"; my $grammar; { local $/; $grammar = <FILE>; } Parse::RecDescent->Precompile($grammar, "My::Grammar"); $self->SUPER::ACTION_build; } EOF

Build is generated without incident; but when it is run I get:

Can't locate object method "Precompile" via package "Parse::RecDescent +" (perhaps you forgot to load "Parse::RecDescent"?) at /home/braden/s +rc/endoframe/literally/trunk/_build/lib/MyModuleBuilder.pm line 13, < +FILE> line 1.
What's the proper way to tell Module::Build about Parse::RecDescent?

Replies are listed 'Best First'.
Re: Using other modules with Module::Build
by ikegami (Patriarch) on Apr 10, 2006 at 23:02 UTC

    As I understand things, the module needs to be loaded for the ./Build step, but you are loading it during the perl Build.PL step. I think the following will do the trick:

    my $class = Module::Build->subclass(code => <<'EOF'); sub ACTION_build { require Parse::RecDescent; ... } EOF

    I think this will also work:

    my $class = Module::Build->subclass(code => <<'EOF'); use Parse::RecDescent; sub ACTION_build { ... } EOF
      Indeed. Thanks!