Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Tidy-Sweetened CPAN distribution.

Report information
The Basics
Id: 85076
Status: resolved
Priority: 0/
Queue: Perl-Tidy-Sweetened

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

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



Subject: method ( ... ) returns ( .. ) { unsupported
The following 2 patterns don't appear to work presently :

    method open_file ( File :$file! ) returns(Bool) {
    }

and

     method can_compute_size returns(Bool) {
     }

As both are transformed into the form

     sub foo returns(whatever) {
     }

82:    expecting ':' or ';' or '{' after definition or declaration of sub 'open_file' but saw 'returns'

82: sub open_file  returns (Bool) { #__METHOD ( File :$file! )

167:    expecting ':' or ';' or '{' after definition or declaration of sub 'can_compute_size' but saw 'returns'

167: sub can_compute_size returns (Bool){ #__METHOD

Thanks.
Hrm, looking at the code, and trying to implement it myself, the returns() structure needlessly complicates the code, due to the storing of the signatures in a comment in the interim.

It /may/ be nicer to simply have a hash and a numerical incremented value, and store the signatures there, and just add the number of the signature in the comment, ie:

instead of
method foo ( asdf ) {
}
=>
sub foo {  # __METHOD ( asdf )
do
$i++;
%hash{$i} = '(asdf)';
sub foo {  # __METHOD NUM $i

It may interest you to look at my experimental hacking

https://github.com/kentfredric/Perl-Tidy-Sweetened/commits/master

But I'm not sure if the changes I'm making are interesting to you or not.

ie: I refactored the logic into a more unified class that allows generic keyword generation, for things users may add later with their own custom names other than 'func' and 'method',

https://github.com/kentfredric/Perl-Tidy-Sweetened/commit/d3f26653cb8164709e495f7db1ac59664f1b636b

And I've tested that locally working as a substitute for the existing Sweetened.pm, and it works for both 'func' and 'method'

my $func = Perl::Tidy::Sweetened::Keyword::SubSignature->new( keyword => 'func', marker => 'FUNC');

sub prefilter { $func->prefilter( $_[0] ) } ... etc.

And additionally, https://github.com/kentfredric/Perl-Tidy-Sweetened/commit/07b575bef8f8b17f84505e08886607e04407b840 makes it easier to chain multiple keyword filters together.

use Perl::Tidy::Sweetened::Keyword::SubSignature;
use Perl::Tidy::Sweetened::Pluggable;

my $plugins = Perl::Tidy::Sweetened::Pluggable->new();
$plugins->add_filter( Perl::Tidy::Sweetened::Keyword::SubSignature->new( keyword => 'func', marker => 'FUNC') );
$plugins->add_filter( Perl::Tidy::Sweetened::Keyword::SubSignature->new( keyword => 'method',marker => 'METHOD' ) );


sub prefilter {
    return $plugins->prefilter( $_[0] );
}

sub postfilter {
    return $plugins->postfilter( $_[0] );
}

# ^ All working.
 

I just don't know the regex well enough to fix it up >_<

Kent, This is great. I love the pluggable filters and your idea to move signature storage out of the comments and into a hash. I've dealt with the returns() bug, added some docs and made the regex a bit more clear (hopefully). I'll release a new version shortly. Thanks, Mark