Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the PPI CPAN distribution.

Report information
The Basics
Id: 38803
Status: open
Priority: 0/
Queue: PPI

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

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



Subject: How do I detect an anonymous subroutine?
I want to detect if a variable declaration is done inside a subroutine. So I wrote code like this: my $insub = 0; while( $elem = $elem->parent ) { $insub = 1 and last if $elem->isa("PPI::Statement::Sub"); } This works fine for named subroutines but does not work for anonymous subroutines. They are just PPI::Statement's. How do I detect that a given element is an anonymous subroutine declaration? Best I could come up with is $elem->first_element->content eq 'sub' leading to this complete solution... sub _is_in_subroutine { my $elem = shift; my $insub = 0; while( $elem = $elem->parent ) { if( _is_subroutine_declaration($elem) ) { $insub = 1; last; } } return $insub; } sub _is_subroutine_declaration { my $elem = shift; return 1 if $elem->isa("PPI::Statement::Sub"); return 1 if $elem->isa("PPI::Statement") and $elem->first_element and $elem->first_element->content eq 'sub'; return 0; } A PPI::Element method to answer if an element is inside a subroutine might be handy.
Subject: Re: [rt.cpan.org #38803] How do I detect an anonymous subroutine?
Date: Thu, 28 Aug 2008 19:57:15 -0500
To: bug-PPI [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On Aug 28, 2008, at 6:55 PM, Michael G Schwern via RT wrote: Show quoted text
> Thu Aug 28 19:55:09 2008: Request 38803 was acted upon. > Transaction: Ticket created by MSCHWERN > Queue: PPI > Subject: How do I detect an anonymous subroutine? > Broken in: (no value) > Severity: Wishlist > Owner: Nobody > Requestors: mschwern@cpan.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=38803 >
Alas, PPI doesn't support anonymous subs yet... Chris