| IO-Statistics documentation | Contained in the IO-Statistics distribution. |
IO::Statistics - Transparently perform statistics on IO handles
use IO::Statistics;
my ($read, $write) = (0, 0);
IO::Statistics->count (\$read, \$write, \*STDOUT);
# alternatively:
$ios = IO::Statistics->new (\$read, \$write);
$ios->via (\*STDOUT);
print "fooo";
print "bkzlfdlkf\n";
END {
print "read $read bytes read, wrote $write bytes\n";
}
This module allows you to count IO activity on a file handle transparently.
Using this IO layer on a global filehandle might result in segfault on
perl_destruct.
----------------------------------- ------ ------ ------ ------ ------ ------ File stmt branch cond sub time total ----------------------------------- ------ ------ ------ ------ ------ ------ blib/lib/IO/Statistics.pm 100.0 100.0 n/a 100.0 100.0 100.0 Total 100.0 100.0 n/a 100.0 100.0 100.0 ----------------------------------- ------ ------ ------ ------ ------ ------
Chia-liang Kao <clkao@clkao.org>
Copyright 2004 by Chia-liang Kao <clkao@clkao.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| IO-Statistics documentation | Contained in the IO-Statistics distribution. |
package IO::Statistics; use 5.008; use strict; use warnings; use PerlIO::via::dynamic '0.10'; our $VERSION = '0.12';
sub new { my ($class, $read, $write) = @_; my %map = (translate => $write, untranslate => $read); return PerlIO::via::dynamic->new ( use_read => 1, map { my $ref = $map{$_}; $ref ? ($_ => sub { $$ref += length ($_[1])}) : () } keys %map); } sub count { my ($class, $read, $write, @handle) = @_; my $ios = $class->new ($read, $write); die "more than one handle not supported yet" if $#handle > 0; $ios->via ($_) for @handle; }
1;