http://www.perlmonks.org?node_id=61181


in reply to plugins and inheritance

My suggestion would be similar to the 'registry' idea, but rather than listing out the various plug-ins in a central file, which will have to be maintained in some way (RegClean is your friend), you could grab the first x bytes of each file and search for the @ISA and package declarations.

(You might also want to check the eol characters (\012 vs \015 vs \012\015), depending upon how much you trust your 'potentially naïve end users,' to borrow a Micros0ftian phrase.)

Depending upon local system configuration, &c., a 'chunk' size of 512 bytes or 4KB might be best. (iirc, 512 byte blocks are +/- standard on most Unices, MacOS, and ?Win/DOS?. 4KB is the size of Linux's read-ahead, and quite likely other OSen, so if you read 1 byte from a file, it's likely that 4KB are cached by the OS, you'd just as well use them.)

Regardless, parsing the package and @ISA elements in the first "chunk" of the file gives you a simple way to identify the parent class to be replaced, and the name of the class to import (assuming that the filename itself is likely to be truncated, modified, or generally abused.)