Net::SFTP
So, I’ve started on Net::SFTP. I was originally planning to just refactor the original implementation out of Net::SSH 0.1.0, but after reacquainting myself with the code, I decided a rewrite was in order. Yah, I frequently find myself disgusted with code that I wrote only months before, but I suppose that’s a good thing, since it means I’m always learning better ways of doing things.
So, what’s wrong with the original implementation? Plenty.
The entire SFTP protocol was implemented in a single class. (With the exception of one auxiliary class, anyway, but the auxiliary class was more of a glorified structure, with only a tiny bit of protocol-specific logic in it.) That alone may or may not sound bad to you, but if you consider that the class also supported three different versions of the SFTP protocol simultaneously... yah. You’re picturing it, I think. Lots of if
, case
and unless
statements, sprinkled at seeming random throughout the code.
The new version is not yet checked into CVS, but is coming along nicely. I’ve separated it into two layers: the SFTP protocol layer (which implements the low-level protocol itself), and the interface layer (which implements a more user-friendly presentation of the SFTP operations).
The protocol layer is split into 5 different pieces, one for each existing version of the protocol. (Yup, Net::SFTP will support, in its nascent release, all 5 existing versions of the protocol!) This turned out pretty slick (if I do say so myself). Each subsequent protocol version inherits from the previous, extending and modifying as needed. It made for a very natural, very extendible implementation of the protocol spec. (This means that when version 6 of the SFTP protocol is solidified, it should be almost trivial to add to Net::SFTP.) It is still not a complete implementation of the specification, but it covers all the major operations. Certainly enough for an initial release.
All told, the new version consists of about 20 classes, just in the protocol layer. I’m a bit more pleased with the architecture this time around.
What is more, the protocol layer is completely unit-tested, with 100% code coverage. (I love dependency injection!) Over 1,500 individual tests! (I love code generation!)
I’ve got about 30% of the interface layer written, with plans to work on it some more tonight (if I have time after setting up the Christmas tree). With any luck, I’ll have version 0.5.0 of Net::SFTP finished by the end of the week. With a little more luck, that may include a first pass at user manual. I may need to release an update to Net::SSH simultaneously, if I can’t get Net::SFTP implemented as I’d like with the existing 0.5.0 release. We’ll see.