|XP is just a number|
Line-oriented input processing is easy in Perl, thanks to readline and its angle bracket syntax as in $line = <STDIN>. However, these popular constructs lack control over the size of what is returned, as has been lamented on several occasions. Such control would be beneficial where data from unreliable sources has to be handled. File::GetLineMaxLength, availiable on CPAN, created by our fellow monk robmueller, addresses this issue. This review discusses version 1.00.
Development stage: a - Alpha testing
The module works only in very special cases, has some serious implementation flaws and documentation issues. I'll elaborate below.
Language used: p - Pure Perl
Support level: d - Developer
Interface style: O - Object oriented
Public License: p - Standard-Perl
File::GetLineMaxLength adds a layer of buffering to an already opened file connection. To read lines, you have to create an object that will hold the state of everything, and repeatedly call the object's getline method.
The constructor new takes an existing filehandle and an optional buffer size. The input record terminator is taken from $/ at the time of object creation -- I had rather expected either an explicit parameter or the behaviour of IO::Handle, which uses $/ dynamically at the time of each getline call.
The getline method takes a non-negative integer size limit and optionally a variable. This variable will be set by the method to 1 in case the size limit is hit and 0 otherwise. A limit of zero means no limit. The return value is a string and always defined. After reading to the end of file it is (supposed to be) empty. There is no distinction between normal end of file and error conditions. For the size limitation, line terminator characters are not counted.
If the number of input characters before a line terminator exceeds the given limit, the returned string will have exactly limit characters and no line terminator, the overflow flag will be set, and the next getline call will continue where the previous one broke off.
ConclusionFile::GetLineMaxLength populates an important and often underestimated niche: tools aiding in interface robustness. It could become useful if it were developed a bit further.
Update: Changed wording about documentation issues. Why has this section no preview button?