Skip Menu |

This queue is for tickets about the Method-Signatures-Simple CPAN distribution.

Report information
The Basics
Id: 83136
Status: rejected
Priority: 0/
Queue: Method-Signatures-Simple

People
Owner: Nobody in particular
Requestors: melo [...] cpan.org
Cc:
AdminCc:

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



Subject: Allow fund () to act as sub {}
Hi, I don't know the internals of Method::Signatures::Simple or Devel::Declare one bit, so ignore me if this is not possible at all. If I define a sub like this: sub t (&) { ... } I can call it like this t { ... }; # or t sub { ... }; But I cannot do this: t func ($v) { ... }; It complains with Type of arg 1 to main::t must be block or sub {} (not subroutine entry) Any change of massing the output of anonymous func () {} to act like a sub {}? Thanks!
Subject: Re: [rt.cpan.org #83136] Allow fund () to act as sub {}
Date: Wed, 06 Feb 2013 02:29:56 +0100
To: bug-Method-Signatures-Simple [...] rt.cpan.org
From: Rhesa Rozendaal <rhesa [...] cpan.org>
On 02/05/2013 04:51 PM, Pedro Melo via RT wrote: Show quoted text
> Tue Feb 05 10:51:03 2013: Request 83136 was acted upon. > Transaction: Ticket created by MELO > Queue: Method-Signatures-Simple > Subject: Allow fund () to act as sub {} > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: melo@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=83136 > > > > Hi, > > I don't know the internals of Method::Signatures::Simple or Devel::Declare one bit, so ignore > me if this is not possible at all. > > If I define a sub like this: > > sub t (&) { ... } > > I can call it like this > > t { ... }; # or > t sub { ... }; > > But I cannot do this: > > t func ($v) { ... }; > > It complains with > > Type of arg 1 to main::t must be block or sub {} (not subroutine entry) > > Any change of massing the output of anonymous func () {} to act like a sub {}? > > Thanks! >
I don't actually know what a subroutine entry is, precisely, but consider these two one-liners: perl -MMethod::Signatures::Simple -E ' sub t (&) { $_[0]->() } my $x = sub { 1 }; say t $x; say t func ($v) { 2 }; ' Type of arg 1 to main::t must be block or sub {} (not private variable) at -e line 4, near "$x;" Type of arg 1 to main::t must be block or sub {} (not subroutine entry) at -e line 5, near "};" Execution of -e aborted due to compilation errors. and: perl -MMethod::Signatures::Simple -E ' sub t (&) { $_[0]->() } my $x = sub { 1 }; say t \&$x; say t \&{ func ($v) { 2 } }; ' 1 2 So there's some symmetry there. I don't see myself using this syntax though, so unless you feel strongly enough about it to attempt a fix, I'd recommend dropping the prototype on sub t, or some other workaround. rhesa
On Tue Feb 05 20:30:11 2013, RHESA wrote: Show quoted text
> I don't actually know what a subroutine entry is, precisely, but > consider these two one-liners: > > perl -MMethod::Signatures::Simple -E ' > sub t (&) { $_[0]->() } > my $x = sub { 1 }; > say t $x; > say t func ($v) { 2 }; > ' > Type of arg 1 to main::t must be block or sub {} (not private > variable) > at -e line 4, near "$x;" > Type of arg 1 to main::t must be block or sub {} (not subroutine > entry) > at -e line 5, near "};" > Execution of -e aborted due to compilation errors. > > and: > > perl -MMethod::Signatures::Simple -E ' > sub t (&) { $_[0]->() } > my $x = sub { 1 }; > say t \&$x; > say t \&{ func ($v) { 2 } }; > ' > 1 > 2 > > So there's some symmetry there. > > I don't see myself using this syntax though, so unless you feel > strongly > enough about it to attempt a fix, I'd recommend dropping the prototype > on sub t, or some other workaround.
I see what you mean. Given that fund () works like a safe source filter, I was expecting that it would be translated to sub { ... } and so I was expecting this to work. But yes, the cases you point out are similar. I can't drop the (&) prototype in this case because usually the function is called as t { }; (with a bare block). Using func() was only a bit of sugar to hide the my ($param) = @_;, so not terrible important, and certainly not enough for me to go down that particular rabbit hole and try to understand how to improve on this. Thanks for your time,