From 73b2054db136b7f6dc43d4c9368d654ea0c78a8e Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Thu, 28 May 2020 16:00:57 -0400 Subject: [PATCH] optimize away empty signature; prevents syntax error on 5.10.1 --- lib/Babble/Plugin/CoreSignatures.pm | 5 ++++- t/plugin-coresignatures.t | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Babble/Plugin/CoreSignatures.pm b/lib/Babble/Plugin/CoreSignatures.pm index a93160d..b36f44b 100644 --- a/lib/Babble/Plugin/CoreSignatures.pm +++ b/lib/Babble/Plugin/CoreSignatures.pm @@ -93,7 +93,10 @@ sub transform_to_plain { push @sig_text, $part; } - my $sig_text = 'my ('.(join ', ', @sig_text).') = @_;'; + my $sig_text = + @sig_text + ? 'my ('.(join ', ', @sig_text).') = @_;' + : ''; my $code = join ' ', $sig_text, @defaults; $s->{body}->transform_text(sub { s/^{/{ ${code}/ }); if ($proto) { diff --git a/t/plugin-coresignatures.t b/t/plugin-coresignatures.t index 9add7eb..3fb0d94 100644 --- a/t/plugin-coresignatures.t +++ b/t/plugin-coresignatures.t @@ -57,10 +57,16 @@ my @cand = ( 'sub foo ($) { my ($sig) = @_; }', ], [ 'sub foo :Foo :prototype($) ($sig) { }', 'sub foo ($) :Foo { my ($sig) = @_; }', ], + [ 'sub foo : Foo prototype($) ($sig) { }', 'sub foo ($) : Foo { my ($sig) = @_; }', ], [ 'sub foo :prototype($) Foo ($sig) { }', 'sub foo ($) :Foo { my ($sig) = @_; }', ], + + [ 'sub foo : Foo prototype($) () { }', + 'sub foo ($) : Foo { }', ], + [ 'sub foo :prototype($) Foo () { }', + 'sub foo ($) :Foo { }', ], [ 'use Mojo::Base -base, -signatures;', 'use Mojo::Base qw(-base);' ], [ 'use Mojo::Base -signatures;',