BEGIN {
@EXPORT = (qw/document p/);
sub _def {
my ($name, $sub) = @_;
no strict 'refs';
my $x = "LaTeX::Writer::Simple::$name";
*$x = $sub;
push @EXPORT, $name;
}
my @nl_commands = (qw/part chapter section
subsection subsubsection caption/);
for my $c (@nl_commands) {
_def($c, sub { _newcommand($c, @_)."\n" });
}
...
It is just wonderful. And what I really liked was that Test::Pod::Coverage detects those methods, and complains about their lack of coverage. Wonderful!
mmm, code generation (Score:1)
Perhaps you would enjoy Sub::Exporter [cpan.org].
rjbs
A few technical comments (Score:1)
First, why are you using @EXPORT rather than @EXPORT_OK? That warning in Exporter is there for a reason.
Second, why are you using a BEGIN block? This code is in a module, which means that there is an implicit BEGIN block on your code already. Therefore adding another one is just semantic noise. You certainly don't need it for the sake of Exporter, since Exporter's import method isn't called until afte
the _def function (Score:1)
Re: (Score:1)
Oh, and there is another reason about defining a _def. I am using this code to define functions in four or five different places. This makes it easier to maintain.
Sorry for the indirection ;)