don't use binmode when there is not real file handle behind; translate \r\n into \n; prepare for release
Salvador Fandino
10 years ago
0 | 0 |
Revision history for Perl extension Config::Properties.
|
|
1 |
|
|
2 |
1.77 Apr 27, 2014
|
|
3 |
- binmode doesn't work on IO::String and others tied objects (bug
|
|
4 |
report by Mithun Ayachit)
|
1 | 5 |
|
2 | 6 |
1.76 Feb 13, 2014
|
3 | 7 |
- add encoding feature
|
2 | 2 |
use strict;
|
3 | 3 |
use warnings;
|
4 | 4 |
|
5 | |
our $VERSION = '1.76';
|
|
5 |
our $VERSION = '1.77';
|
6 | 6 |
|
7 | 7 |
use IO::Handle;
|
8 | 8 |
use Carp;
|
|
236 | 236 |
sub load {
|
237 | 237 |
my ($self, $file) = @_;
|
238 | 238 |
_t_file $file;
|
239 | |
unless (grep /^(?:encoding|utf8)\b/, PerlIO::get_layers($file)) {
|
240 | |
binmode $file, ":encoding($self->{encoding})"
|
241 | |
or croak "Unable to set file encoding layer: $!";
|
|
239 |
|
|
240 |
# check whether it is a real file handle
|
|
241 |
my $fn = do {
|
|
242 |
local $@;
|
|
243 |
eval { fileno($file) }
|
|
244 |
};
|
|
245 |
if (defined $fn and $fn >0) {
|
|
246 |
unless (grep /^(?:encoding|utf8)\b/, PerlIO::get_layers($file)) {
|
|
247 |
binmode $file, ":encoding($self->{encoding})"
|
|
248 |
or croak "Unable to set file encoding layer: $!";
|
|
249 |
}
|
242 | 250 |
}
|
243 | 251 |
$self->{properties}={};
|
244 | 252 |
$self->{property_line_numbers}={};
|
|
286 | 294 |
sub process_line {
|
287 | 295 |
my ($self, $file) = @_;
|
288 | 296 |
my $line=<$file>;
|
289 | |
|
290 | 297 |
defined $line or return undef;
|
|
298 |
$line =~ s/\r\n/\n/g;
|
291 | 299 |
my $ln = $self->{line_number} = $file->input_line_number;
|
292 | 300 |
if ($ln == 1) {
|
293 | 301 |
# remove utf8 byte order mark
|