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

Owner: Nobody in particular
Requestors: mschwern [...]

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

Subject: How do I detect an anonymous subroutine?
Download (untitled) / with headers
text/plain 1.1k
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: [ #38803] How do I detect an anonymous subroutine?
Date: Thu, 28 Aug 2008 19:57:15 -0500
To: bug-PPI [...]
From: Chris Dolan <chris [...]>
Download (untitled) / with headers
text/plain 490b
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: > Status: new > Ticket <URL: >
Alas, PPI doesn't support anonymous subs yet... Chris

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

Please report any issues with to