[Melbourne-pm] IO::File with Capture for Quota
scottp at dd.com.au
Wed Oct 15 20:52:31 PDT 2008
----- "Toby Corkindale" <toby.corkindale at strategicdata.com.au> wrote:
> fstat() works upon filehandles directly, avoiding the needing to keep
> the filename around. Might make life easier for you, and also allow
> to work with temporary files that were created and unlinked after
Sorry I forgot to mention the problem. If someone uses undef $fh; - which is the norm. or close $fh which is also common - then the file handle is closed before it gets to DESTORY, and I can't use fstat.
That is why $fh->close works, but undef $fh and close $fh does not, until I kept a copy of the filename.
> > 2) What else would you change - in functions, calls and purpose to
> make this a useful CPAN module
> The name of the module implies that it is meant to be performing quota
> management, but the actual action seems to be more like performing a
> generic call-back upon close..
> If you're actually looking to enforce quotas, wouldn't you need to
> the data written at every write, rather than upon close?
Yes :-) this is lazy quota :-) (p.s. don't worry about the quota side - it is horrible but must be the way it is).
I agree about the name, it might be something like IO::File::Hook::Size - or something similar. Maybe IO::File::Stat if I can get more info.
> In that case, rather than use '-s' (or fstat()) to get the size, you
> could use the return from fnprintf() or similar, which gives you the
> number of bytes written.. then you can do something like:
> die "Quota exceeded!" unless ($bytes_written <= $remaining_quota);
> $remaining_quota -= $bytes_written;
Unfortunately after the open I have no control over the code. If it uses print, fprintf, or syswrite or what ever I am not sure. It may even pass the file handle to a C library to do the work. All I have is the open call.
More information about the Melbourne-pm