[Parseperl-discuss] Unique ID per PPI::Element
Brought to you by:
adamkennedy
From: Dan B. <mr....@gm...> - 2006-10-05 13:39:21
|
I'm currently going through the motions of going from a very development version of PPIx::Index to something useful in practice and I've hit a stage where I feel having a unique ID for each PPI::Element would be useful. My rationale behind this is that if someone has a PPI::Document they are iterating over and want to access the indexed information pertaining to a given node then they can just access that data using its unique id. This may very well be a X/Y Problem and I'm certainly open to suggestions but that's what my monkey brain has managed to scratch in the dirt. I haven't gotten around to implementing it yet but if I did it probably use some PPIx::XPath magic (cos I'm lazy like that) and look something like this: use Digest::MD5 'md5_hex'; sub PPI::Element::id { my $el = shift; return md5hex( PPIx::XPath->new($el)->xpath . $el->location->[0] ); } There are probably issues with that code, such as the fact that if you have recurring Elements on the same line you'd get the same ID (but that's fine for what I'm doing) and it probably needs the script path to be unique too, but I guess that's what you get for knocking out code off the cuff. So any thoughts, suggestions, criticisms on this ID idea or anything pertaining to indexing software would be very much appreciated. Thanks, Dan Brook aka broquaint |