perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

[doc] Document exporting constants with Exporter

Open oalders opened this issue 3 years ago • 1 comments

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.

oalders avatar Sep 08 '22 18:09 oalders

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.

Grinnz avatar Sep 08 '22 19:09 Grinnz