Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: please review my first module

by VSarkiss (Monsignor)
on Jul 01, 2001 at 21:56 UTC ( [id://93040]=note: print w/replies, xml ) Need Help??


in reply to please review my first module

This may entail a lot of work for you, but you asked ;-)

I would suggest implementing the interface as a tied hash. As others have pointed out in this thread, you're exporting many sub names by default. Since all these values are logically related, it makes sense (to me, anyway) to collect them into a single data structure. That is, your caller would do something like this:

use AIX::Sysinfo; # depending on your decision to rename it tie %sysinfo, 'AIX::Sysinfo'; my $aix_hostname = $sysinfo{hostname}; # for example my $aix_version = $sysinfo{aix_version}; # for example
It may be less work than it appears; your module would only have to implement the "reading" functions of the hash, not the "writing" ones. Also, remember you can inherit from Tie::Hash to take care of a lot of the work.

Another suggestion is to cache up the values from the various exernal calls. As it stands, every time I ask for the aix_version, for example, the code will fork and exec to retrieve the same value. But if you make some room in the modeul, you can save the returned values once and re-use them for the life of the program. (It's OK to save these values once since none of them can change without at least rebooting the machine.)

Note that you can cache the values regardless of whether you use the tied-hash interface, but IMHO it would be nice to combine the two.

HTH

Update 7/2/01: Better link to man page courtesy of tye.

Replies are listed 'Best First'.
Re: Re: please review my first module
by blueflashlight (Pilgrim) on Jul 02, 2001 at 19:03 UTC
    thanks for the great suggestions. unfortunately, you've brought on *more* questions! :-)

    I think the idea of using a tied hash is very elegant; the problem is that, though I've read the manpage you've linked to, and also the Tied Variables chapter in my Camel-3rdEd book, my brain is in a total fog. Perhaps my problem is that I still don't really understand the object-oriented universe (no matter how hard I've tried!), and all of the examples in the manpage/book use OO syntax (which I've avoided.)

    Is it possible to implement the tied variable in my module without getting into the OO realm, or am I missing the point? (the point being that tied variables are fundamentally part of OO perl syntax.)

    Thanks again for the help; anything I can do to make this code better, I'm open to. Just not sure that my little brains is up for the task.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found