#!/usr/bin/perl
#use Mooix::Thing;
use Parse::RecDescent;
run sub ($) {
	my $this=shift;

	# Only compile the grammar if it is newer than the compiled form.
	my $gpm = $this->fieldfile("Grammar.pm");
	my $gra = $this->fieldfile("grammar");
	if (! $gpm || (stat($gpm))[9] < (stat($gra))[9]) {
		# Output to "myGrammar", then rename, so the update is atomic.
		Parse::RecDescent->Precompile(scalar $this->grammar, "myGrammar");
		rename("myGrammar.pm", "Grammar.pm") || die "rename: $!";
		# Mark it as a method. This prevents show from trying to display
		# the whole thing..
		chmod(0755, "Grammar.pm");
	}

	return 1;
}
