Re: [Parseperl-discuss] Good way to determine if a certain bareword is used?
Brought to you by:
adamkennedy
|
From: Dan B. <mr....@gm...> - 2006-10-12 09:24:49
|
On 10/11/06, Torsten Schoenfeld <kaf...@gm...> 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?
A simpler (if not better) way would be to use PPIx::XPath like so:
use PPIx::XPath;
my @toks = PPIx::XPath->new($document)
->match('//PPI::Token::Word[.="Gtk2::Gdk::DisplayManager"]');
And that should return you the appropriate nodes.
HTH
Dan Brook
|