stas 02/01/28 23:55:56
Modified: t/response/TestApache compat2.pm
lib/Apache compat.pm
src/docs/2.0/user/compat compat.pod
Log:
- implement the compat layer for Apache::Util::size_string
- add tests
- document the compatibility layer
Revision Changes Path
1.2 +18 -1 modperl-2.0/t/response/TestApache/compat2.pm
Index: compat2.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestApache/compat2.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- compat2.pm 21 Jan 2002 08:32:46 -0000 1.1
+++ compat2.pm 29 Jan 2002 07:55:56 -0000 1.2
@@ -12,10 +12,19 @@
use Apache::compat ();
use Apache::Constants qw(OK);
+my %string_size = (
+ '-1' => " -",
+ 0 => " 0k",
+ 42 => " 1k",
+ 42_000 => " 41k",
+ 42_000_000 => "40.1M",
+ 42_000_000_000 => "40054.3M",
+);
+
sub handler {
my $r = shift;
- plan $r, tests => 28, todo => [23];
+ plan $r, tests => 34, todo => [23];
$r->send_http_header('text/plain');
@@ -144,6 +153,7 @@
"\$r->set_content_length($csize) w/ setting explicit size");
$r->set_content_length();
+ # TODO
ok t_cmp(0, # XXX: $r->finfo->csize is not available yet
$r->headers_out->{"Content-length"},
"\$r->set_content_length() w/o setting explicit size");
@@ -169,6 +179,13 @@
$r->set_last_modified($time);
ok t_cmp($time, $r->mtime, "\$r->set_last_modified(\$time)");
+ }
+
+ # Apache::Util::size_string
+ {
+ while (my($k, $v) = each %string_size) {
+ ok t_cmp($v, Apache::Util::size_string($k));
+ }
}
Apache::OK;
1.33 +27 -0 modperl-2.0/lib/Apache/compat.pm
Index: compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- compat.pm 20 Dec 2001 01:31:24 -0000 1.32
+++ compat.pm 29 Jan 2002 07:55:56 -0000 1.33
@@ -351,6 +351,33 @@
# the following functions now live in Apache::RequestRec
# * mtime
+package Apache::Util;
+
+sub size_string {
+ my ($size) = shift;
+
+ if (!$size) {
+ $size = " 0k";
+ }
+ elsif ($size == -1) {
+ $size = " -";
+ }
+ elsif ($size < 1024) {
+ $size = " 1k";
+ }
+ elsif ($size < 1048576) {
+ $size = sprintf "%4dk", ($size + 512) / 1024;
+ }
+ elsif (size < 103809024) {
+ $size = sprintf "%4.1fM", $size / 1048576.0;
+ }
+ else {
+ $size = sprintf "%4dM", ($size + 524288) / 1048576;
+ }
+
+ return $size;
+
+}
1;
__END__
1.8 +19 -3 modperl-docs/src/docs/2.0/user/compat/compat.pod
Index: compat.pod
===================================================================
RCS file: /home/cvs/modperl-docs/src/docs/2.0/user/compat/compat.pod,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- compat.pod 22 Jan 2002 16:37:40 -0000 1.7
+++ compat.pod 29 Jan 2002 07:55:56 -0000 1.8
@@ -77,17 +77,33 @@
at the server startup.
-=head2 gensym
+=head2 Apache::gensym
Since Perl 5.6.1 filehandlers are autovivified and there is no need
-for gensym() function, since now it can be done with:
+for C<Apache::gensym()> function, since now it can be done with:
open my $fh, "foo" or die $!;
The C function modperl_perl_gensym() is available for XS/C extension
writers, though.
-=head2 Apache::File
+=head1 Apache::File
+
+
+
+
+=head1 Apache::Util
+
+A few C<Apache::Util> functions have changed their interface.
+
+=head2 Apache::Util::size_string
+
+C<Apache::Util::size_string> has been replaced with
+C<APR::String::format_size>, which returns formatted strings of only 4
+characters long. See the C<APR::String> manpage for more information.
+
+
+
=head1 Miscellaneous
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]