perl5
perl5 copied to clipboard
[doc] Document exporting constants with Exporter
Where
Exporter.pm
Description
The Exporter docs state:
Exporting variables is not a good idea. They can change under the hood, provoking horrible effects at-a-distance that are too hard to track and to fix. Trust me: they are not worth it.
However, the docs don't mention how to export constants, which can be something as simple as:
package Foo;
use Const::Fast qw( const );
use Exporter qw( import );
const our $HTTP_OK => 200;
@EXPORT_OK = ( '$HTTP_OK' );
1;
If this seems reasonable to document, I can put a doc patch together.
Const::Fast isn't core so I'm not sure the value of referencing it here. Core constants are subroutines which of course are easy to export like any other subroutine, so that might be useful to mention.