Skip Menu |

This queue is for tickets about the Function-Parameters CPAN distribution.

Report information
The Basics
Id: 88261
Status: resolved
Priority: 0/
Queue: Function-Parameters

People
Owner: Nobody in particular
Requestors: mst [...] shadowcat.co.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.0202
Fixed in: 1.0301



Subject: Wishlist: method keyword takes effect at runtime
Date: Thu, 29 Aug 2013 14:17:21 +0000
To: bugs-Function-Parameters [...] rt.cpan.org
From: Matt S Trout <mst [...] shadowcat.co.uk>
15:01 <@mauke> sub method {} # you're screwed 15:01 <@mst> well, yes, that's why Method::Signatures::Simple (for example) only installs it at runtime 15:01 -!- bluescreen [~mariano@151.193.220.27] has joined #p5p 15:01 <@mst> the only example I can think of that lifts it to compile time is schwern's, because I couldn't get him to understand that that broke things 15:02 <@ilmari_> the only reason to define methods at compile time is so that you can consume roles that require them before defining them 15:02 <@mauke> what does it break? 15:03 -!- bluescreen [~mariano@151.193.220.27] has quit [Remote host closed the connection] 15:03 -!- bluescreen_ [~mariano@151.193.220.27] has joined #p5p 15:03 <@mst> mauke: things like 'method has' become a disaster 15:04 <@mst> mauke: 'sub' being compile time really isn't a feature for modules 15:04 <@mauke> how common is this? 15:04 <@mauke> I mean, there's a trivial workaround: *has = method ($thing) { ... }; 15:05 <@mst> yes. but not having to use the ugly workaround is one of the reasons I use Method::Signatures::Simple sometimes 15:05 <@mst> in fact, it's why I uploaded that module at all 15:06 <@mst> when Method::Signatures switched to compile time installation it was no longer interesting to me 15:06 <@mst> fixing the precedence order annoyances of 'sub' actually turned out to be just as important to me as signatures themselves 15:07 <@ilmari_> s/for modules/for classes/ # I think 15:08 <@ilmari_> otherwise Sub::StrictDecl would only work for imported subs 15:08 <@mst> I was under the impression that Function::Parameters made 'fun' compile time for consistency with 'sub', and 'method' run time for consistency with every other method keyword 15:08 <@mauke> no, F:P is always compile time 15:08 <+purl> okay, mauke. 15:08 <@mst> mauke: any chance of an import() option to fix that? 15:09 <@mauke> I didn't know the runtimeness was supposed to be a feature 15:09 <@mauke> mst: I'm currently looking at how Sub::Name works 15:09 <@mauke> mst: feel free to report a wishlist bug so I don't forget about it -- Matt S Trout - Shadowcat Systems - Perl consulting with a commit bit and a clue http://shadowcat.co.uk/blog/matt-s-trout/ http://twitter.com/shadowcat_mst/ Email me now on mst (at) shadowcat.co.uk and let's chat about how our CPAN commercial support, training and consultancy packages could help your team.
Here's an example that this would break... use v5.12; use strict; use warnings; BEGIN { package Foo; use Function::Parameters; use Moo::Role; requires '_foo_config'; method foo () { my %config = %{ $self->_foo_config }; say $config{flibble}; } }; BEGIN { package Boo; use Function::Parameters; use Moo; with 'Foo'; method _foo_config () { my %config = (flibble => "Hello"); return \%config; } }; Boo->new->foo;
On Thu Aug 29 10:17:38 2013, mst@shadowcat.co.uk wrote: Show quoted text
> 15:08 <@mst> mauke: any chance of an import() option to fix that?
This is now possible with 'use Function::Parameters { method => { defaults => 'method', runtime => 1 } };'.
On Mon Sep 16 03:08:10 2013, TOBYINK wrote: Show quoted text
> Here's an example that this would break... > > use v5.12; > use strict; > use warnings; > > BEGIN { > package Foo; > use Function::Parameters; use Moo::Role; > > requires '_foo_config'; > > method foo () { > my %config = %{ $self->_foo_config }; > say $config{flibble}; > } > }; > > > BEGIN { > package Boo; > use Function::Parameters; use Moo; > > with 'Foo'; > > method _foo_config () { > my %config = (flibble => "Hello"); > return \%config; > } > }; > > Boo->new->foo;
True, but you'd have the same problem with something like: { package Boo; use Moo; with 'Foo'; has '_foo_config' => (is => 'ro'); } With 'runtime => 1', 'method' turns (from a declaration) into a normal executable statement, like 'with', 'has', 'extends', etc. The workaround is to define your methods (including attributes) before composing roles: method _foo_config() {} # or has '_foo_config', ... with 'Foo'; Or you could 'use Function::Parameters { method => { defaults => 'method', runtime => 0 } }' to get the old (that is, current) behavior, even if I decide to switch 'runtime' on by default. In conclusion, this is a real issue but I think it's not a big problem. I'll keep it in mind for the future.
On 2013-09-16T09:15:06+01:00, MAUKE wrote: Show quoted text
> Or you could 'use Function::Parameters > { method => { defaults => 'method', runtime => 0 } }' > to get the old (that is, current) behavior, even if > I decide to switch 'runtime' on by default.
Indeed - my example was just a response to your request in the pod... "If this would break your code, please send me a note or file a bug on RT."
Subject: Re: [rt.cpan.org #88261] Wishlist: method keyword takes effect at runtime
Date: Mon, 16 Sep 2013 15:12:35 +0000
To: Toby Inkster via RT <bug-Function-Parameters [...] rt.cpan.org>
From: Matt S Trout <mst [...] shadowcat.co.uk>
On Mon, Sep 16, 2013 at 09:19:26AM -0400, Toby Inkster via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=88261 > > > On 2013-09-16T09:15:06+01:00, MAUKE wrote:
> > Or you could 'use Function::Parameters > > { method => { defaults => 'method', runtime => 0 } }' > > to get the old (that is, current) behavior, even if > > I decide to switch 'runtime' on by default.
> > Indeed - my example was just a response to your request in the pod... > > "If this would break your code, please send me a note or file a bug on RT."
I think mauke was looking to understand the level of -impact- - he did specifically say 'if this would break your code', and I think the word 'your' was important there. Your example is an obvious down side of the change, but the interesting question here (at least to me) if how prevalent said downside is in the real world compared to the advantages of having everything happen in order. -- Matt S Trout - Shadowcat Systems - Perl consulting with a commit bit and a clue http://shadowcat.co.uk/blog/matt-s-trout/ http://twitter.com/shadowcat_mst/ Email me now on mst (at) shadowcat.co.uk and let's chat about how our CPAN commercial support, training and consultancy packages could help your team.