r43225 - in /trunk/libsysadm-install-perl: Changes META.yml README debian/changelog lib/Sysadm/Install.pm t/014utf8.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Sat Aug 29 12:50:30 UTC 2009
Author: jawnsy-guest
Date: Sat Aug 29 12:50:24 2009
New Revision: 43225
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=43225
Log:
* New upstream release
+ utf8 handling is configurable instead of using sneaky
capability detection
Modified:
trunk/libsysadm-install-perl/Changes
trunk/libsysadm-install-perl/META.yml
trunk/libsysadm-install-perl/README
trunk/libsysadm-install-perl/debian/changelog
trunk/libsysadm-install-perl/lib/Sysadm/Install.pm
trunk/libsysadm-install-perl/t/014utf8.t
Modified: trunk/libsysadm-install-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libsysadm-install-perl/Changes?rev=43225&op=diff
==============================================================================
--- trunk/libsysadm-install-perl/Changes (original)
+++ trunk/libsysadm-install-perl/Changes Sat Aug 29 12:50:24 2009
@@ -2,7 +2,11 @@
Revision history for Sysadm::Install
########################################
-0.30 2009/08/27
+0.32 2009/08/28
+ (ms) Made utf8 handling configurable instead of sneaky capability
+ detection, after all, there's apps using different encodings.
+
+0.31 2009/08/27
(ms) nhandler(at)ubuntu.com provided a patch to resolve pod2man errors:
https://rt.cpan.org/Public/Bug/Display.html?id=47525
(ms) slurp() and blurt() now use utf8 mode by default if available
Modified: trunk/libsysadm-install-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libsysadm-install-perl/META.yml?rev=43225&op=diff
==============================================================================
--- trunk/libsysadm-install-perl/META.yml (original)
+++ trunk/libsysadm-install-perl/META.yml Sat Aug 29 12:50:24 2009
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Sysadm-Install
-version: 0.31
+version: 0.32
version_from: lib/Sysadm/Install.pm
installdirs: site
requires:
Modified: trunk/libsysadm-install-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libsysadm-install-perl/README?rev=43225&op=diff
==============================================================================
--- trunk/libsysadm-install-perl/README (original)
+++ trunk/libsysadm-install-perl/README Sat Aug 29 12:50:24 2009
@@ -1,5 +1,5 @@
######################################################################
- Sysadm::Install 0.31
+ Sysadm::Install 0.32
######################################################################
NAME
@@ -144,6 +144,11 @@
Works with one or more file names.
+ If the files are known to contain UTF-8 encoded data, and you want
+ it to be read/written as a Unicode strings, use the "utf8" option:
+
+ pie(sub { s/foo/bar/g; $_; }, "test.dat", { utf8 => 1 });
+
"plough($coderef, $filename, ...)"
Simulate "perl -ne 'do something' file". Iterates over all lines of
all input files and calls the subroutine provided as the first
@@ -156,23 +161,41 @@
Works with one or more file names.
- "my $data = slurp($file)"
+ If the files are known to contain UTF-8 encoded data, and you want
+ it to be read into Unicode strings, use the "utf8" option:
+
+ plough(sub { print if /foobar/ }, "test.dat", { utf8 => 1 });
+
+ "my $data = slurp($file, $options)"
Slurps in the file and returns a scalar with the file's content. If
called without argument, data is slurped from STDIN or from any
files provided on the command line (like <> operates).
+
+ If the file is known to contain UTF-8 encoded data and you want to
+ read it in as a Unicode string, use the "utf8" option:
+
+ my $unicode_string = slurp( $file, {utf8 => 1} );
"blurt($data, $file, $append)"
Opens a new file, prints the data in $data to it and closes the
file. If $append is set to a true value, data will be appended to
the file. Default is false, existing files will be overwritten.
- "blurt_atomic($data, $file)"
+ If the string is a Unicode string, use the "utf8" option:
+
+ blurt( $unicode_string, $file, {utf8 => 1} );
+
+ "blurt_atomic($data, $file, $options)"
Write the data in $data to a file $file, guaranteeing that the
operation will either complete fully or not at all. This is
accomplished by first writing to a temporary file which is then
rename()ed to the target file.
Unlike in "blurt", there is no $append mode in "blurt_atomic".
+
+ If the string is a Unicode string, use the "utf8" option:
+
+ blurt_atomic( $unicode_string, $file, {utf8 => 1} );
"($stdout, $stderr, $exit_code) = tap($cmd, @args)"
Run a command $cmd in the shell, and pass it @args as args. Capture
Modified: trunk/libsysadm-install-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libsysadm-install-perl/debian/changelog?rev=43225&op=diff
==============================================================================
--- trunk/libsysadm-install-perl/debian/changelog (original)
+++ trunk/libsysadm-install-perl/debian/changelog Sat Aug 29 12:50:24 2009
@@ -1,3 +1,11 @@
+libsysadm-install-perl (0.32-1) UNRELEASED; urgency=low
+
+ * New upstream release
+ + utf8 handling is configurable instead of using sneaky
+ capability detection
+
+ -- Jonathan Yu <frequency at cpan.org> Sat, 29 Aug 2009 04:48:20 -0400
+
libsysadm-install-perl (0.31-1) unstable; urgency=low
* New upstream release
Modified: trunk/libsysadm-install-perl/lib/Sysadm/Install.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libsysadm-install-perl/lib/Sysadm/Install.pm?rev=43225&op=diff
==============================================================================
--- trunk/libsysadm-install-perl/lib/Sysadm/Install.pm (original)
+++ trunk/libsysadm-install-perl/lib/Sysadm/Install.pm Sat Aug 29 12:50:24 2009
@@ -6,7 +6,7 @@
use strict;
use warnings;
-our $VERSION = '0.31';
+our $VERSION = '0.32';
use File::Copy;
use File::Path;
@@ -651,12 +651,24 @@
Works with one or more file names.
+If the files are known to contain UTF-8 encoded data, and you want it
+to be read/written as a Unicode strings, use the C<utf8> option:
+
+ pie(sub { s/foo/bar/g; $_; }, "test.dat", { utf8 => 1 });
+
=cut
###############################################
sub pie {
###############################################
my($coderef, @files) = @_;
+
+ my $options = {};
+
+ if(defined $files[-1] and
+ ref $files[-1] eq "HASH") {
+ $options = pop @files;
+ }
local($Log::Log4perl::caller_depth) += 1;
@@ -669,7 +681,7 @@
open FILE, "<$file" or
LOGCROAK("Cannot open $file ($!)");
- if( utf8_available() ) {
+ if( $options->{utf8} ) {
binmode FILE, ":utf8";
}
@@ -678,7 +690,7 @@
}
close FILE;
- blurt($out, $file);
+ blurt($out, $file, $options);
}
}
@@ -696,12 +708,24 @@
Works with one or more file names.
+If the files are known to contain UTF-8 encoded data, and you want it
+to be read into Unicode strings, use the C<utf8> option:
+
+ plough(sub { print if /foobar/ }, "test.dat", { utf8 => 1 });
+
=cut
###############################################
sub plough {
###############################################
my($coderef, @files) = @_;
+
+ my $options = {};
+
+ if(defined $files[-1] and
+ ref $files[-1] eq "HASH") {
+ $options = pop @files;
+ }
local($Log::Log4perl::caller_depth) += 1;
@@ -714,7 +738,7 @@
open FILE, "<$file" or
LOGCROAK("Cannot open $file ($!)");
- if( utf8_available() ) {
+ if( $options->{utf8} ) {
binmode FILE, ":utf8";
}
@@ -727,18 +751,25 @@
=pod
-=item C<my $data = slurp($file)>
+=item C<my $data = slurp($file, $options)>
Slurps in the file and returns a scalar with the file's content. If
called without argument, data is slurped from STDIN or from any files
provided on the command line (like E<lt>E<gt> operates).
+If the file is known to contain UTF-8 encoded data and you want to
+read it in as a Unicode string, use the C<utf8> option:
+
+ my $unicode_string = slurp( $file, {utf8 => 1} );
+
=cut
###############################################
sub slurp {
###############################################
- my($file) = @_;
+ my($file, $options) = @_;
+
+ $options = {} unless defined $options;
local($Log::Log4perl::caller_depth) += 1;
@@ -752,7 +783,7 @@
INFO "Slurping data from $file";
open FILE, "<$file" or
LOGCROAK("Cannot open $file ($!)");
- if( utf8_available() ) {
+ if( exists $options->{utf8} ) {
binmode FILE, ":utf8";
}
$data = <FILE>;
@@ -775,25 +806,36 @@
If C<$append> is set to a true value, data will be appended to the
file. Default is false, existing files will be overwritten.
+If the string is a Unicode string, use the C<utf8> option:
+
+ blurt( $unicode_string, $file, {utf8 => 1} );
+
=cut
###############################################
sub blurt {
###############################################
- my($data, $file, $append) = @_;
-
- local($Log::Log4perl::caller_depth) += 1;
-
- $append = 0 unless defined $append;
-
- _confirm(($append ? "Appending" : "Writing") . " " .
+ my($data, $file, $options) = @_;
+
+ # legacy signature
+ if(defined $options and ref $options eq "") {
+ $options = { append => 1 };
+ }
+
+ $options = {} unless defined $options;
+
+ local($Log::Log4perl::caller_depth) += 1;
+
+ $options->{append} = 0 unless defined $options->{append};
+
+ _confirm(($options->{append} ? "Appending" : "Writing") . " " .
length($data) . " bytes to $file") or return 1;
- open FILE, ">" . ($append ? ">" : "") . $file
+ open FILE, ">" . ($options->{append} ? ">" : "") . $file
or
LOGCROAK("Cannot open $file for writing ($!)");
- if( is_utf8_data( $data ) ) {
+ if( $options->{utf8} ) {
binmode FILE, ":utf8";
}
@@ -809,7 +851,7 @@
=pod
-=item C<blurt_atomic($data, $file)>
+=item C<blurt_atomic($data, $file, $options)>
Write the data in $data to a file $file, guaranteeing that the operation
will either complete fully or not at all. This is accomplished by first
@@ -817,19 +859,25 @@
Unlike in C<blurt>, there is no C<$append> mode in C<blurt_atomic>.
+If the string is a Unicode string, use the C<utf8> option:
+
+ blurt_atomic( $unicode_string, $file, {utf8 => 1} );
+
=cut
###############################################
sub blurt_atomic {
###############################################
- my($data, $file) = @_;
+ my($data, $file, $options) = @_;
_confirm("Writing atomically " .
length($data) . " bytes to $file") or return 1;
+ $options = {} unless defined $options;
+
my($fh, $tmpname) = tempfile(DIR => dirname($file));
- blurt($data, $tmpname);
+ blurt($data, $tmpname, $options);
rename $tmpname, $file or
LOGDIE "Can't rename $tmpname to $file";
@@ -884,6 +932,13 @@
sub tap {
###############################################
my(@args) = @_;
+
+ my $options = {};
+
+ if(defined $args[-1] and
+ ref $args[-1] eq "HASH") {
+ $options = pop @args;
+ }
local($Log::Log4perl::caller_depth) += 1;
@@ -914,12 +969,17 @@
open PIPE, $cmd or
LOGCROAK("open $cmd | failed ($!)");
+
+ if( $options->{utf8} ) {
+ binmode PIPE, ":utf8";
+ }
+
my $stdout = join '', <PIPE>;
close PIPE;
my $exit_code = $?;
- my $stderr = slurp($tmpfile);
+ my $stderr = slurp($tmpfile, $options);
DEBUG "tap $cmd results: rc=$exit_code stderr=[$stderr] stdout=[$stdout]";
@@ -1301,7 +1361,9 @@
######################################
sub fs_read_open {
######################################
- my($dir) = @_;
+ my($dir, $options) = @_;
+
+ $options = {} unless defined $options;
local($Log::Log4perl::caller_depth) += 1;
@@ -1319,6 +1381,8 @@
open my $in, "$cmd |" or
LOGCROAK("Cannot open $cmd");
+ binmode $in, ":utf8" if $options->{utf8};
+
cdback;
return $in;
@@ -1340,7 +1404,9 @@
######################################
sub fs_write_open {
######################################
- my($dir) = @_;
+ my($dir, $options) = @_;
+
+ $options = {} unless defined $options;
local($Log::Log4perl::caller_depth) += 1;
@@ -1356,6 +1422,8 @@
DEBUG "Writing to $cmd in dir $dir";
open my $out, "| $cmd" or
LOGCROAK("Cannot open $cmd");
+
+ binmode $out, ":utf8" if $options->{utf8};
cdback;
Modified: trunk/libsysadm-install-perl/t/014utf8.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libsysadm-install-perl/t/014utf8.t?rev=43225&op=diff
==============================================================================
--- trunk/libsysadm-install-perl/t/014utf8.t (original)
+++ trunk/libsysadm-install-perl/t/014utf8.t Sat Aug 29 12:50:24 2009
@@ -29,7 +29,7 @@
my $utf8file = File::Spec->catfile($TEST_DIR, "canned", "utf8.txt");
-my $data = slurp $utf8file;
+my $data = slurp $utf8file, {utf8 => 1};
ok is_utf8( $data ), "slurped utf8 file data stored in utf8";
use utf8;
More information about the Pkg-perl-cvs-commits
mailing list