Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: plugins and inheritance

by baku (Scribe)
on Feb 28, 2001 at 01:32 UTC ( #61181=note: print w/replies, xml ) Need Help??

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.)

Replies are listed 'Best First'.
Re: Re: plugins and inheritance
by idsfa (Vicar) on Aug 29, 2003 at 15:18 UTC
    Rather than manually parsing the files consider this snippet. Since perl already maintains a registry of installed modules (ExtUtils::Installed), why write your own?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://61181]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2019-07-18 09:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found