New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global variables in Exporter examples #16485
Comments
From @GrinnzThe docs for Exporter (https://metacpan.org/pod/Exporter) include several -Dan |
From @jkeenanOn Wed, 28 Mar 2018 21:36:14 GMT, grinnz@gmail.com wrote:
Please review patch attached. Thank you very much. |
From @jkeenan0001-Use-lexically-scoped-our-variables-in-POD-examples.patchFrom d8743f7fe069f62f5e506b74ac35f82897e4e88a Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Thu, 29 Mar 2018 09:36:57 -0400
Subject: [PATCH] Use lexically scoped ('our') variables in POD examples.
Per Dan Book recommendation, as this is code likely to be copied-and-pasted by
people new to Perl.
Keep podcheck happy.
For: RT # 133040
---
dist/Exporter/lib/Exporter.pm | 34 +++++++++++++++++-----------------
t/porting/known_pod_issues.dat | 1 +
2 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/dist/Exporter/lib/Exporter.pm b/dist/Exporter/lib/Exporter.pm
index 0b3db21..f9ccd26 100644
--- a/dist/Exporter/lib/Exporter.pm
+++ b/dist/Exporter/lib/Exporter.pm
@@ -9,7 +9,7 @@ require 5.006;
our $Debug = 0;
our $ExportLevel = 0;
our $Verbose ||= 0;
-our $VERSION = '5.72';
+our $VERSION = '5.73';
our (%Cache);
sub as_heavy {
@@ -106,14 +106,14 @@ In module F<YourModule.pm>:
package YourModule;
require Exporter;
- @ISA = qw(Exporter);
- @EXPORT_OK = qw(munge frobnicate); # symbols to export on request
+ our @ISA = qw(Exporter);
+ our @EXPORT_OK = qw(munge frobnicate); # symbols to export on request
or
package YourModule;
use Exporter 'import'; # gives you Exporter's import() method directly
- @EXPORT_OK = qw(munge frobnicate); # symbols to export on request
+ our @EXPORT_OK = qw(munge frobnicate); # symbols to export on request
In other files which wish to use C<YourModule>:
@@ -146,8 +146,8 @@ symbols can represent functions, scalars, arrays, hashes, or typeglobs.
The symbols must be given by full name with the exception that the
ampersand in front of a function is optional, e.g.
- @EXPORT = qw(afunc $scalar @array); # afunc is a function
- @EXPORT_OK = qw(&bfunc %hash *typeglob); # explicit prefix on &bfunc
+ our @EXPORT = qw(afunc $scalar @array); # afunc is a function
+ our @EXPORT_OK = qw(&bfunc %hash *typeglob); # explicit prefix on &bfunc
If you are only exporting function names it is recommended to omit the
ampersand, as the implementation is faster this way.
@@ -234,9 +234,9 @@ include :DEFAULT explicitly.
e.g., F<Module.pm> defines:
- @EXPORT = qw(A1 A2 A3 A4 A5);
- @EXPORT_OK = qw(B1 B2 B3 B4 B5);
- %EXPORT_TAGS = (T1 => [qw(A1 A2 B1 B2)], T2 => [qw(A1 A2 B3 B4)]);
+ our @EXPORT = qw(A1 A2 A3 A4 A5);
+ our @EXPORT_OK = qw(B1 B2 B3 B4 B5);
+ our %EXPORT_TAGS = (T1 => [qw(A1 A2 B1 B2)], T2 => [qw(A1 A2 B3 B4)]);
Note that you cannot use tags in @EXPORT or @EXPORT_OK.
@@ -279,8 +279,8 @@ import function:
package A;
- @ISA = qw(Exporter);
- @EXPORT_OK = qw($b);
+ our @ISA = qw(Exporter);
+ our @EXPORT_OK = qw($b);
sub import
{
@@ -293,8 +293,8 @@ inheritance, as it stands Exporter::import() will never get called.
Instead, say the following:
package A;
- @ISA = qw(Exporter);
- @EXPORT_OK = qw($b);
+ our @ISA = qw(Exporter);
+ our @EXPORT_OK = qw($b);
sub import
{
@@ -354,7 +354,7 @@ will give the module an opportunity to handle the situation before
generating an error. The Exporter will call an export_fail method
with a list of the failed symbols:
- @failed_symbols = $module_name->export_fail(@failed_symbols);
+ our @failed_symbols = $module_name->export_fail(@failed_symbols);
If the C<export_fail> method returns an empty list then no error is
recorded and all the requested symbols are exported. If the returned
@@ -374,7 +374,7 @@ Since the symbols listed within C<%EXPORT_TAGS> must also appear in either
C<@EXPORT> or C<@EXPORT_OK>, two utility functions are provided which allow
you to easily add tagged sets of symbols to C<@EXPORT> or C<@EXPORT_OK>:
- %EXPORT_TAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]);
+ our %EXPORT_TAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]);
Exporter::export_tags('foo'); # add aa, bb and cc to @EXPORT
Exporter::export_ok_tags('bar'); # add aa, cc and dd to @EXPORT_OK
@@ -391,7 +391,7 @@ useful to create the utility ":all" to simplify "use" statements.
The simplest way to do this is:
- %EXPORT_TAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]);
+ our %EXPORT_TAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]);
# add all the other ":class" tags to the ":all" class,
# deleting duplicates
@@ -460,7 +460,7 @@ variables C<@EXPORT_OK>, C<@EXPORT>, C<@ISA>, etc.
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(munge frobnicate);
-If backward compatibility for Perls under 5.6 is important,
+If backward compatibility for Perls B<under> 5.6 is important,
one must write instead a C<use vars> statement.
use vars qw(@ISA @EXPORT_OK);
diff --git a/t/porting/known_pod_issues.dat b/t/porting/known_pod_issues.dat
index 5856f80..e89d5c0 100644
--- a/t/porting/known_pod_issues.dat
+++ b/t/porting/known_pod_issues.dat
@@ -335,6 +335,7 @@ dist/data-dumper/dumper.pm ? Should you be using L<...> instead of 1
dist/devel-ppport/parts/inc/ppphdoc Unknown directive: =dontwarn 1
dist/devel-ppport/parts/inc/ppphdoc Unknown directive: =implementation 1
dist/devel-ppport/parts/inc/ppphdoc Unknown directive: =provides 1
+dist/exporter/lib/exporter.pm Verbatim line length including indents exceeds 79 by 2
dist/net-ping/lib/net/ping.pm Apparent broken link 1
ext/amiga-exec/exec.pm Verbatim line length including indents exceeds 79 by 1
ext/dynaloader/dynaloader.pm Verbatim line length including indents exceeds 79 by 1
--
2.7.4
|
The RT System itself - Status changed from 'new' to 'open' |
From @GrinnzThis mostly looks good to me, but I would leave the line about -Dan On Thu, Mar 29, 2018 at 9:54 AM, James E Keenan via RT <
|
From @jkeenanOn Thu, 29 Mar 2018 15:50:53 GMT, grinnz@gmail.com wrote:
Pushed to blead in commits -- |
@jkeenan - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#133040 (status was 'resolved')
Searchable as RT133040$
The text was updated successfully, but these errors were encountered: