Authors,
I have a design issue with a module I'm writing. I posted a question on
Perlmonks a while back and got nothing useful, which perhaps indicates
that the question was poorly phrased. So I'll try again here.
I have a series of associations in a file:
FOO 1
BAR 2
QUUX 3
It's easy enough to produce a C header:
#define FOO 1
#define BAR 2
#define QUUX 3
that is included in an XS file; and a perl file:
use constant FOO => 1;
use constant BAR => 2;
use constant QUUX => 3;
that is required by a .pm file. I (now) know how to do that with rules
that I add to the Makefile.PL script.
The problem is that these associations are private to the XS and Perl
module. The client code does not need to know about them, and in fact
shouldn't. So I don't want client code to know the file exists, and
people won't go around trying to include it. So the Perl file has to go.
So what I really want to have a way of embedding the generated constants
in my module, as it wends its way to the blib/lib directory:
package P;
use constant FOO => 1;
use constant BAR => 2;
use constant QUUX => 3;
sub new {
...
}
As a bonus, the module avoids a failure mode that would occur when some
bright spark deletes the .pl file. I could do something like a
P.template file that contains
package P;
#INCLUDE_CONSTANTS#
sub new {
...
}
and have some code that does an s/#INCLUDE_CONSTANTS#/$some_string/ on
the file, to produce a P.pm file. Also note that the associations are
fixed: there aren't going to be any more or less on any machines due to
local differences.
Sort of like hint files, in a way. What I really want to know is whether
someone has already encountered this problem, and how they solved it.
I'd like to be able to profit from the experience, and I figure if I
structure things the same way, it will be a Best Practice, and people
will more readily understand what's going on, which is a win all round.
Thanks,
David
--
Much of the propaganda that passes for news in our own society is given
to immobilising and pacifying people and diverting them from the idea
that they can confront power. -- John Pilger