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
Attribute::Handlers not fully functional at runtime #8672
Comments
From johnpc@xs4all.nlCreated by johnpc@xs4all.nlWhen subroutine attributes are used at "runtime", for example This can be worked around by doing the require inside a BEGIN As an example, the attached code produces: $ perl -w test.pl test.pl and bar.pl can also be downloaded from test.pl contains: package LoudDecl; sub Loud :ATTR { print STDERR "($referent), ", ref($referent), " "; package main; use strict; sub foo :Loud(Boe) # this works only if inside a BEGIN block: print foo("hi"), "\n", bar("boo"), "\nDone\n"; and bar.pl contains: 1; Perl Info
|
From @rgarciaOn 07/11/06, via RT johnpc @ xs4all. nl <perlbug-followup@perl.org> wrote:
Can't this be also solved by declaring the attribute handler as being |
The RT System itself - Status changed from 'new' to 'open' |
From jkahrman@mathworks.comI created a patch to try to support this case better. It doesn't provide quite the right semantics for the phases, and it doesn't resolve the issue for attributes tagged for 'END' phases, but it ensures that the attributes for the 'CHECK' (default) and 'INIT' phases aren't silently ignored just because 'Attribute::Handlers' was loaded after the initial compilation phase. |
From jkahrman@mathworks.comAttrHand_require.rt40695.patch--- perl5.20.2/dist/Attribute-Handlers/lib/Attribute/Handlers.pm 2016-11-03 00:16:14.000000000 -0400
+++ perl5.20.2_patch/dist/Attribute-Handlers/lib/Attribute/Handlers.pm 2016-11-03 00:16:14.000000000 -0400
@@ -1,5 +1,5 @@
package Attribute::Handlers;
-use 5.006;
+use v5.14;
use Carp;
use warnings;
use strict;
@@ -35,14 +35,19 @@
my %raw;
my %phase;
my %sigil = (SCALAR=>'$', ARRAY=>'@', HASH=>'%');
-my $global_phase = 0;
+
+# Union of possible values of ${^GLOBAL_PHASE} and @global_phases
my %global_phases = (
- BEGIN => 0,
- CHECK => 1,
- INIT => 2,
- END => 3,
+ CONSTRUCT => -1,
+ START => 0,
+ BEGIN => 0,
+ CHECK => 1,
+ INIT => 2,
+ RUN => 3,
+ END => 4,
+ DESTRUCT => 9,
);
-my @global_phases = qw(BEGIN CHECK INIT END);
+my @global_phases = qw(BEGIN CHECK INIT END); # valid phases as args to ATTR
sub _usage_AH_ {
croak "Usage: use $_[0] autotie => {AttrName => TieClassName,...}";
@@ -174,9 +179,9 @@
$raw{$handler}, $phase{$handler}, $filename, $linenum];
foreach my $gphase (@global_phases) {
_apply_handler_AH_($decl,$gphase)
- if $global_phases{$gphase} <= $global_phase;
+ if $global_phases{$gphase} <= $global_phases{${^GLOBAL_PHASE}};
}
- if ($global_phase != 0) {
+ if ($global_phases{${^GLOBAL_PHASE}} != 0) {
# if _gen_handler_AH_ is being called after
# CHECK it's for a lexical, so make sure
# it didn't want to run anything later
@@ -235,7 +240,6 @@
{
no warnings 'void';
CHECK {
- $global_phase++;
_resolve_lastattr if _delayed_name_resolution;
foreach my $decl (@declarations) {
_apply_handler_AH_($decl, 'CHECK');
@@ -243,7 +247,6 @@
}
INIT {
- $global_phase++;
foreach my $decl (@declarations) {
_apply_handler_AH_($decl, 'INIT');
}
@@ -251,7 +254,6 @@
}
END {
- $global_phase++;
foreach my $decl (@declarations) {
_apply_handler_AH_($decl, 'END');
}
|
From @jkeenanOn Wed, 06 Jun 2018 17:21:31 GMT, jkahrman@mathworks.com wrote:
Thank you for the patch. My hunch is that we won't be able to use this patch as is, for two reasons: 1. You've drawn the patch against the version of Attribute::Handlers distributed with perl-5.20.2 -- approximately version 0.96. But since in the core distribution A::H is up to version 1.01, the patch probably wouldn't apply cleanly. Would it be possible to re-draw the patch against perl 5 blead, i.e., against a git checkout? 2. While A::H is now maintained by Perl 5 Porters in the core distribution ("blead-upstream"), it is expected to get independent releases to CPAN to make it available to older versions of Perl. Your patch bumps the minimum version of Perl needed for the module from 5.6 to 14.0. That means that any perl installation of 5.8, 5.10 or 5.12 would be unable to use the module. I suspect that won't fly, but the determination on that would have to be made by the module's listed CPAN maintainer, Steffen Mueller. As to the patch's actual content, I don't yet have an informed opinion. Thank you very much. |
Migrated from rt.perl.org#40695 (status was 'open')
Searchable as RT40695$
The text was updated successfully, but these errors were encountered: