Show quoted text> By the way, thanks also for Perl Best Practices. We use Perl for
> automated testing of remote systems, and our code base has become a
> mess. We're using your book to restructure stuff now.
I'm glad you're finding it valuable.
Show quoted text> Actually, on the topic of Perl Best Practices, how do you deal with
> publishing constant values?
>
> That is, I've got a boatload of named constant values that pass over
> the wire, and I'd like to put them in one central module and use them
> everywhere. However, it seems like the natural interface would be
> package variables (or, more accurately, Readonly package variables),
> which goes against the recommendations in the book.
>
> At the moment, we use two different approaches in different
> "constants" modules. One publishes them as "sub Foo { return
> '000001234' }" and one of them publishes them as "our $foo = new
> FooObject(@args)".
>
> Do you have a recommendation?
PBP recommends using the Readonly module to create variables that represent
constants. However, the book also recommends not exporting variables as part
of an interface. Which creates something of an impasse when it comes to
exporting constants.
To resolve this conflict, we have to consider the *reason* PBP cautions
against variables in interfaces: that changes to those variables are global in
effect. However, constants, by their very nature cannot be changed, so the
problem is no longer a problem.
That being the case, I'd suggest using Readonly'd variables to store
constants, and exporting from the module.
Hope that helps,
Damian