Skip Menu |

This queue is for tickets about the Keyword-Declare CPAN distribution.

Report information
The Basics
Id: 123464
Status: rejected
Priority: 0/
Queue: Keyword-Declare

People
Owner: DCONWAY [...] cpan.org
Requestors: JEFFOBER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.001006
Fixed in: (no value)



Subject: Possible keyword expansion bug
I suspect that this is a bug in the way keywords are expanded... unless it is a misunderstanding on my part about how they are intended to behave. When declaring a keyword that expands into part of an expression, the debug output shows it being expanded correctly, but the expanded form does not appear to have replaced the keyword in the final code. Note that this happens not only with the example below, but with an array (e.g `keyword foo() {return '[1,2,3]'}`) and a simple string as well (`keyword foo() {return '"hello world"'}`). $ cat scratch.pl use Keyword::Declare {debug => 1}; keyword foo () { return q{('foo' => 'bar')};} my %param = foo; $ perl scratch.pl ##################################################### ### Installed keyword macro at scratch.pl line 3: ### ###foo ### ##################################################### ##################################################### ### Keyword macro defined at scratch.pl line 3: ### ### foo ### ### Converted code at scratch.pl line 7: ### ### foo ### ### Into: ### ### ('foo' => 'bar') ### ##################################################### syntax error at scratch.pl line 6, near "= foo" Execution of scratch.pl aborted due to compilation errors.
Subject: Re: [rt.cpan.org #123464] Possible keyword expansion bug
Date: Wed, 1 Nov 2017 06:07:34 +1100
To: bug-Keyword-Declare [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Jeff, Show quoted text
> I suspect that this is a bug in the way keywords are expanded... > unless it is a misunderstanding on my part about how they are intended > to behave.
It's the latter, I'm afraid. Though not so much "intended to behave" as "forced to behave". From the "BUGS AND LIMITATIONS" section of the module's documentation: The module currently relies on Keyword::Simple, so it is subject to all the limitations of that module. Most significantly, it can only create keywords that appear at the beginning of a statement (though you can almost always code around that limitation by wrapping the keyword in a C<do{...}> block. So, instead of: my %param = foo; you would need: my %param = do{ foo }; And, yes, it's extremely annoying. And, yes, it's arguably a bug in the module...or at least in the implementation of Perl's pluggable keywords mechanism. And, yes, I've discussed it with Lukas Mai (the author of Keyword::Simple), who has no solution for the problem either. :-( Damian
Subject: Re: [rt.cpan.org #123464] Possible keyword expansion bug
Date: Tue, 31 Oct 2017 15:49:37 -0400
To: "damian [...] conway.org via RT" <bug-Keyword-Declare [...] rt.cpan.org>, JEFFOBER [...] cpan.org
From: Jeff Ober <sysread [...] fastmail.fm>
Understood. Thank you for the explanation. -- Jeff Ober sysread@fastmail.fm Old programmers don't die; they just parse on... On Tue, Oct 31, 2017, at 03:08 PM, damian@conway.org via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=123464 > > > Hi Jeff, >
> > I suspect that this is a bug in the way keywords are expanded... > > unless it is a misunderstanding on my part about how they are intended > > to behave.
> > It's the latter, I'm afraid. Though not so much "intended to behave" as > "forced to behave". > From the "BUGS AND LIMITATIONS" section of the module's documentation: > > The module currently relies on Keyword::Simple, so it is subject to > all > the limitations of that module. Most significantly, it can only > create > keywords that appear at the beginning of a statement (though you can > almost always code around that limitation by wrapping the keyword in > a C<do{...}> block. > > So, instead of: > > my %param = foo; > > you would need: > > my %param = do{ foo }; > > And, yes, it's extremely annoying. And, yes, it's arguably a bug in the > module...or at least in the implementation of Perl's pluggable keywords > mechanism. And, yes, I've discussed it with Lukas Mai (the author of > Keyword::Simple), who has no solution for the problem either. :-( > > Damian