Skip Menu |
 

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

Report information
The Basics
Id: 79947
Status: open
Priority: 0/
Queue: Perl-Tidy

People
Owner: Nobody in particular
Requestors: rjray [...] blackperl.com
Cc:
AdminCc:

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



Subject: Enhancement: Have "cuddled-else" logic applied to try/catch/finally blocks
Download (untitled) / with headers
text/plain 826b
Currently, try/catch/finally blocks are not recognized the way if/elsif/else blocks are, and lead to inconsistent line-breaks when --cuddled-else is set. It would be nice if they were cuddled as well. See the attached files: first file (t.pl) is a short example with both an if-block and a try-block. Second file (t.pl.tdy) is what it currently looks like after perltidy. Third file (t.pl.tdy2) is what I think it should look like. This could be tricky, as there are competing exception-handling packages on CPAN, some with slightly different syntax. Try::Tiny, for example, does not take a class name after "catch", and only offers try/catch/finally. Error, in contrast, takes a class name after "catch", and offers try, catch, except, otherwise and finally. Randy -- Randy J. Ray rjray@blackperl.com randy.j.ray@gmail.com
Subject: t.pl.tdy
Download t.pl.tdy
application/octet-stream 294b

Message body not shown because it is not plain text.

Subject: t.pl
Download t.pl
text/x-perl 286b
#!/usr/bin/env perl use strict; use warnings; use Error qw(:try); sub foo { if (1) { do_something(); } else { do_something_else(); } try { something(); } catch Error with { something_else(); } finally { foo(); } }
Subject: t.pl.tdy2
Download t.pl.tdy2
application/octet-stream 286b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #79947] Enhancement: Have "cuddled-else" logic applied to try/catch/finally blocks
Date: Tue, 2 Oct 2012 06:27:37 -0700
To: bug-Perl-Tidy [...] rt.cpan.org
From: Steven Hancock <perltidy [...] users.sourceforge.net>
Download (untitled) / with headers
text/plain 1.3k
Randy, Thanks, I'll look at it. Steve On Mon, Oct 1, 2012 at 10:50 AM, Randy J Ray via RT < bug-Perl-Tidy@rt.cpan.org> wrote: Show quoted text
> Mon Oct 01 13:50:51 2012: Request 79947 was acted upon. > Transaction: Ticket created by RJRAY > Queue: Perl-Tidy > Subject: Enhancement: Have "cuddled-else" logic applied to > try/catch/finally > blocks > Broken in: 20120714 > Severity: Wishlist > Owner: Nobody > Requestors: rjray@blackperl.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79947 > > > > Currently, try/catch/finally blocks are not recognized the way > if/elsif/else blocks are, and lead to inconsistent line-breaks when > --cuddled-else is set. It would be nice if they were cuddled as well. > See the attached files: first file (t.pl) is a short example with both an > if-block and a try-block. Second file (t.pl.tdy) is what it currently > looks like after perltidy. Third file (t.pl.tdy2) is what I think it > should look like. > > This could be tricky, as there are competing exception-handling packages > on CPAN, some with slightly different syntax. Try::Tiny, for example, > does not take a class name after "catch", and only offers > try/catch/finally. Error, in contrast, takes a class name after "catch", > and offers try, catch, except, otherwise and finally. > > Randy > -- > Randy J. Ray > rjray@blackperl.com > randy.j.ray@gmail.com >
From: ulrik.mikaelsson [...] gmail.com
Any progress on this? AFAICT, the original example is a bit flawed. Correct usage of the Error module is try { do_some_stuff(); } catch IO::Error with { # Oh noes! } finally { # Oh well }; <- semi-colon crucial or anything can happen Perltidy seems to handle this correctly. HOWEVER; The Error CPAN-module is no longer recommended, due to bugs in corner-cases. Recommended modules are now instead, for example TryCatch (http://search.cpan.org/perldoc?TryCatch) TryCatch does not expect the semi-colon and breaks with Perltidy. On Tue Oct 02 09:27:56 2012, SHANCOCK wrote: Show quoted text
> Randy, > Thanks, I'll look at it. > Steve > > On Mon, Oct 1, 2012 at 10:50 AM, Randy J Ray via RT < > bug-Perl-Tidy@rt.cpan.org> wrote: >
> > Mon Oct 01 13:50:51 2012: Request 79947 was acted upon. > > Transaction: Ticket created by RJRAY > > Queue: Perl-Tidy > > Subject: Enhancement: Have "cuddled-else" logic applied to > > try/catch/finally > > blocks > > Broken in: 20120714 > > Severity: Wishlist > > Owner: Nobody > > Requestors: rjray@blackperl.com > > Status: new > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79947 > > > > > > > Currently, try/catch/finally blocks are not recognized the way > > if/elsif/else blocks are, and lead to inconsistent line-breaks when > > --cuddled-else is set. It would be nice if they were cuddled as well. > > See the attached files: first file (t.pl) is a short example with both an > > if-block and a try-block. Second file (t.pl.tdy) is what it currently > > looks like after perltidy. Third file (t.pl.tdy2) is what I think it > > should look like. > > > > This could be tricky, as there are competing exception-handling packages > > on CPAN, some with slightly different syntax. Try::Tiny, for example, > > does not take a class name after "catch", and only offers > > try/catch/finally. Error, in contrast, takes a class name after "catch", > > and offers try, catch, except, otherwise and finally. > > > > Randy > > -- > > Randy J. Ray > > rjray@blackperl.com > > randy.j.ray@gmail.com > >
Download (untitled) / with headers
text/plain 707b
Greetings, I just bumped into this when using TryCatch and perltidy. Sample Code Block: try { croak "An Error!"; } catch ( $error ) { print STDERR $error . "\n"; } The error generated by perltidy was: 31: syntax error at ') {', didn't see one of: case elsif for foreach given if switch unless until when while I fixed this by making a minor change to %is_blocktype_with_paren in Perl/Tidy.pm (version 20150815) Line 4110 Before: @_ = qw(if elsif unless while until for foreach switch case given when); After: @_ = qw(if elsif unless while until for foreach switch case given when catch); Hopefully this is something that can be included in the next update, I'd welcome any feedback. Thanks!
Subject: Re: [rt.cpan.org #79947] Enhancement: Have "cuddled-else" logic applied to try/catch/finally blocks
Date: Tue, 23 Feb 2016 10:50:55 -0800
To: "bug-Perl-Tidy [...] rt.cpan.org" <bug-Perl-Tidy [...] rt.cpan.org>
From: Steven Hancock <perltidy [...] users.sourceforge.net>
Download (untitled) / with headers
text/plain 1007b
Thanks, it will be fixed in the next version. Steve On Tue, Feb 23, 2016 at 9:38 AM, Robert Stone via RT < bug-Perl-Tidy@rt.cpan.org> wrote: Show quoted text
> Queue: Perl-Tidy > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79947 > > > Greetings, > > I just bumped into this when using TryCatch and perltidy. > > Sample Code Block: > > try { > croak "An Error!"; > } > catch ( $error ) { > print STDERR $error . "\n"; > } > > The error generated by perltidy was: > 31: syntax error at ') {', didn't see one of: case elsif for foreach > given if switch unless until when while > > I fixed this by making a minor change to %is_blocktype_with_paren in > Perl/Tidy.pm (version 20150815) > Line 4110 > > Before: > @_ = qw(if elsif unless while until for foreach switch case given when); > > After: > @_ = qw(if elsif unless while until for foreach switch case given when > catch); > > Hopefully this is something that can be included in the next update, I'd > welcome any feedback. > > Thanks! >
Download (untitled) / with headers
text/plain 332b
This is fixed in version 20160301 On Tue Feb 23 13:51:07 2016, SHANCOCK wrote: Show quoted text
> Thanks, it will be fixed in the next version. > Steve > > On Tue, Feb 23, 2016 at 9:38 AM, Robert Stone via RT < > bug-Perl-Tidy@rt.cpan.org> wrote: >
> > Queue: Perl-Tidy > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79947 >
From: qsimpleq
Download (untitled) / with headers
text/plain 591b
additional fixes: add catch to default keywords for which space is introduced before an opening paren add catch to block types may have text between the keyword and opening curly Суб Фев 27 12:58:51 2016, SHANCOCK писал: Show quoted text
> This is fixed in version 20160301 > > On Tue Feb 23 13:51:07 2016, SHANCOCK wrote:
> > Thanks, it will be fixed in the next version. > > Steve > > > > On Tue, Feb 23, 2016 at 9:38 AM, Robert Stone via RT < > > bug-Perl-Tidy@rt.cpan.org> wrote: > >
> > > Queue: Perl-Tidy > > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79947 >
From: qsimpleq
Download (untitled) / with headers
text/plain 106b
add files Чтв Апр 28 03:33:24 2016, http://mrakobes86reg.id.bk.ru/ писал: Show quoted text
> additional fixes:
From: qsimpleq
Subject: try.diff
Download try.diff
text/x-diff 1.4k
--- Tidy.pm_old 2016-03-01 19:46:22.000000000 +0500 +++ Tidy.pm 2016-04-28 12:18:27.857379362 +0500 @@ -7718,7 +7718,7 @@ # default keywords for which space is introduced before an opening paren # (at present, including them messes up vertical alignment) @_ = qw(my local our and or err eq ne if else elsif until - unless while for foreach return switch case given when); + unless while for foreach return switch case given when catch); @space_after_keyword{@_} = (1) x scalar(@_); # first remove any or all of these if desired @@ -11773,7 +11773,7 @@ # curly. Note: 'else' does not, but must be included to allow trailing # if/elsif text to be appended. # patch for SWITCH/CASE: added 'case' and 'when' - @_ = qw(if elsif else unless while until for foreach case when); + @_ = qw(if elsif else unless while until for foreach case when catch); @is_if_elsif_else_unless_while_until_for_foreach{@_} = (1) x scalar(@_); } @@ -30007,7 +30007,7 @@ @_ = qw( BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue if elsif else unless do while until eval for foreach map grep sort - switch case given when catch); + switch case given when catch try finally); @is_code_block_token{@_} = (1) x scalar(@_); # I'll build the list of keywords incrementally @@ -30236,6 +30236,8 @@ when err say + + catch ); # patched above for SWITCH/CASE given/when err say
From: qsimpleq
Subject: test.pl
Download test.pl
text/x-perl 363b
#!/usr/bin/env perl use strict; use warnings; use Error qw(:try); sub foo { if (1) { do_something(); } else { do_something_else(); } try { something(); } catch Error with { something_else(); } finally { foo(); }; } try { croak "An Error ёбаный стыд!"; } catch($error) { print STDERR $error . "\n";};


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.