Re: [Parseperl-discuss] Good way to determine if a certain bareword is used?
Brought to you by:
adamkennedy
|
From: Adam K. <ad...@ph...> - 2006-10-12 02:56:00
|
Torsten Schoenfeld wrote:
> Aloha,
>
> I recently started using PPI to begin work on a module that finds out
> which version of Gtk2/gtk+ a given bunch of code requires. To do that,
> I need to know if, for example, the bareword "Gtk2::Gdk::DisplayManager"
> is used anywhere. Here's what I came up with:
>
> $document->find_any(sub {
> $_[1]->isa ("PPI::Statement") and
> $_[1]->find_any(sub {
> $_[1]->isa ("PPI::Token::Word") and
> $_[1] eq "Gtk2::Gdk::DisplayManager"
> })
> });
>
> Is this a good way to express the requirements? Is it correct? Is
> there a better way?
If you are just looking for the word, then the top part isn't necesary.
Just this will be enough.
$document->find_any( sub {
$_[1]->isa('PPI::Token::Word')
and
$_[1] eq 'Gtk2::Gdk::DisplayManager'
} );
I'm not entirely sure why you have the PPI::Statement phrase there, but
if you've been copying code from Perl::Critic that might be some sort of
an optimisation hack?
Adam K
|