Re: [Parseperl-discuss] Unique ID per PPI::Element
Brought to you by:
adamkennedy
From: Dan B. <mr....@gm...> - 2006-10-05 15:04:21
|
On 10/5/06, Chris Dolan <ch...@cl...> wrote: > I just looked at PPIx::Index. My first comment is a non-technical > one. I recommend you change all mention of "script" to "file" or > "program". Script is a very diminishing word that psychologically > reduces the significance of the work. See: > http://www.nntp.perl.org/group/perl.module-authors/4765 Yep, sounds good. > After that, I see this issue with your 0.0.1_1 code: you return > hashes of variables, pkgs, etc., which precludes you using the same > name twice in code. For example, consider this silly code: I'm using hashes because the indexer is only indexing where things are declared, not where they're used. However, if I was to index where things are used, which I may do at some point, I'd definitely take that route. > Note that $line is used twice lexically, but your hash-based API can > only return the first of them. Furthermore, why not return the > actual token instead of the line number? The line number is used instead of the token itself because only the line number is the only relevant information to the indexer and it also makes the indexed data language agnostic. > For that matter, you could even have two subs with the same name per > file. This can happen if you have multiple "package" declarations. > Or, the name could be '' if it's an anonymous sub declaration. so > probably you should go to an array of subs: All subs are indexed by their fully qualified name, so there's no worry with multiple subs and anonymous subs are just bound to whatever variable they're assigned to. > By returning the element itself instead of just the line number, I > think you remove the need for any ID at all. I perhaps should've elaborated on the fact that I need an ID for backend usage too (i.e a database) so that it can be consistently referred to both in code and in the database. Again, I don't know if this is the best solution, but it's what I've managed to come up with. Thanks for your thoughts! Dan |