[Bps-public-commit] r15831 - PerlIO-via-dynamic/trunk
clkao at bestpractical.com
clkao at bestpractical.com
Mon Sep 8 07:18:54 EDT 2008
Author: clkao
Date: Mon Sep 8 07:18:54 2008
New Revision: 15831
Modified:
PerlIO-via-dynamic/trunk/ (props changed)
PerlIO-via-dynamic/trunk/CHANGES
PerlIO-via-dynamic/trunk/MANIFEST
PerlIO-via-dynamic/trunk/Makefile.PL
PerlIO-via-dynamic/trunk/dynamic.pm
Log:
r160 at mtl: clkao | 2004-09-06 19:49:04 +0800
PerlIO::via::dynamic 0.10.
Modified: PerlIO-via-dynamic/trunk/CHANGES
==============================================================================
--- PerlIO-via-dynamic/trunk/CHANGES (original)
+++ PerlIO-via-dynamic/trunk/CHANGES Mon Sep 8 07:18:54 2008
@@ -1,4 +1,9 @@
-[Changes for 0.01 - 17 Feb, 2004]
+[Changes for 0.10 - 6 Sep, 2004]
+
+* Add use_read option to use READ instead of FILL.
+* Make next layer autoflush on write.
+
+[Changes for 0.02 - 17 Feb, 2004]
Support cleanup for dynamic namespaces..
Modified: PerlIO-via-dynamic/trunk/MANIFEST
==============================================================================
--- PerlIO-via-dynamic/trunk/MANIFEST (original)
+++ PerlIO-via-dynamic/trunk/MANIFEST Mon Sep 8 07:18:54 2008
@@ -1,9 +1,21 @@
-MANIFEST
CHANGES
-README
-Makefile.PL
dynamic.pm
+inc/ExtUtils/AutoInstall.pm
+inc/Module/Install.pm
+inc/Module/Install/AutoInstall.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+Makefile.PL
+MANIFEST
+META.yml Module meta-data (added by MakeMaker)
+README
+SIGNATURE Public-key signature (added by MakeMaker)
t/1use.t
t/2basic.t
t/3gc.t
-META.yml Module meta-data (added by MakeMaker)
Modified: PerlIO-via-dynamic/trunk/Makefile.PL
==============================================================================
--- PerlIO-via-dynamic/trunk/Makefile.PL (original)
+++ PerlIO-via-dynamic/trunk/Makefile.PL Mon Sep 8 07:18:54 2008
@@ -1,16 +1,15 @@
#!/usr/bin/perl
-use ExtUtils::MakeMaker;
-WriteMakefile(
- AUTHOR => 'Chia-liang Kao (clkao at clkao.org)',
- ABSTRACT => 'Dynamic PerlIO layers',
- NAME => 'PerlIO::via::dynamic',
- VERSION_FROM => 'dynamic.pm',
- DISTNAME => 'PerlIO-via-dynamic',
+use inc::Module::Install;
+use 5.008;
- dist => {
- COMPRESS => 'gzip -9',
- SUFFIX => '.gz',
- },
-);
+name ('PerlIO-via-dynamic');
+author ('Chia-liang Kao <clkao at clkao.org>');
+abstract_from ('dynamic.pm');
+license ('perl');
+version_from ('dynamic.pm');
+include('ExtUtils::AutoInstall');
+auto_install();
+
+WriteAll( sign => 1 );
Modified: PerlIO-via-dynamic/trunk/dynamic.pm
==============================================================================
--- PerlIO-via-dynamic/trunk/dynamic.pm (original)
+++ PerlIO-via-dynamic/trunk/dynamic.pm Mon Sep 8 07:18:54 2008
@@ -1,6 +1,6 @@
package PerlIO::via::dynamic;
use strict;
-our $VERSION = '0.02';
+our $VERSION = '0.10';
=head1 NAME
@@ -19,21 +19,47 @@
=head1 DESCRIPTION
-PerlIO::via::dynamic is used for creating dynamic PerlIO layers. It is
-useful when the behavior or the layer depends on variables. You should
-not use this module as via layer directly (ie :via(dynamic)).
+C<PerlIO::via::dynamic> is used for creating dynamic L<PerlIO>
+layers. It is useful when the behavior or the layer depends on
+variables. You should not use this module as via layer directly (ie
+:via(dynamic)).
Use the constructor to create new layers, with two arguments:
-translate and untranslate. Then use C<$p-E<gt>via ($fh)> to wrap the
-handle.
+translate and untranslate. Then use C<$p->via ($fh)> to wrap the
+handle. Once <$fh> is destroyed, the temporary namespace for the IO
+layer will be removed.
Note that PerlIO::via::dynamic uses the scalar fields to reference to
-the object representing the dynamic namespace. If you
+the object representing the dynamic namespace.
+
+=head1 OPTIONS
+
+=over
+
+=item translate
+
+A function that translate buffer upon I<write>.
+
+=item untranslate
+
+A function that translate buffer upon I<read>.
+
+=item use_read
+
+Use C<READ> instead of C<FILL> for the layer. Useful when caller
+expect exact amount of data from read, and the C<untranslate> function
+might return different length.
+
+By default C<PerlIO::via::dynamic> creates line-based layer to make
+C<translate> implementation easier.
+
+=back
=cut
use Symbol qw(delete_package gensym);
use Scalar::Util qw(weaken);
+use IO::Handle;
sub PUSHED {
die "this should not be via directly"
@@ -54,16 +80,24 @@
sub untranslate {
}
-sub FILL {
+sub _FILL {
my $line = readline( $_[1] );
$_[0]->untranslate ($line) if defined $line;
$line;
}
+sub READ {
+ my $ret = read $_[3], $_[1], $_[2];
+ return $ret unless $ret > 0;
+ $_[0]->untranslate ($_[1]);
+ return length ($_[1]);
+}
+
sub WRITE {
my $buf = $_[1];
$_[0]->translate($buf);
- (print {$_[2]} $buf) ? length($buf) : -1;
+ $_[2]->autoflush (1);
+ (print {$_[2]} $buf) ? length ($buf) : -1;
}
sub SEEK {
@@ -82,6 +116,14 @@
| or die $@;
no strict 'refs';
+ unless ($arg{use_read}) {
+ *{"$package\::FILL"} = *PerlIO::via::dynamic::_FILL;
+ }
+ delete $arg{use_read};
+ if ($arg{no_gc}) {
+ $self->{nogc} = 1;
+ }
+ delete $arg{no_gc};
for (keys %arg) {
*{"$package\::$_"} = $arg{$_};
}
More information about the Bps-public-commit
mailing list