Codebase list libconfig-properties-perl-upstream / c71a7d8
add encoding feature, add support for Travis CI, prepare for release 1.76 Salvador Fandino 10 years ago
3 changed file(s) with 31 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Perl extension Config::Properties.
1
2 1.76 Feb 13, 2014
3 - add encoding feature
14
25 1.75 Jul 16, 2012
36 - add support for order feature
99 t/5_save.t
1010 t/6_sorted.t
1111 t/7_pods.t
12 t/utf8.t
1213 META.yml Module meta-data (added by MakeMaker)
22 use strict;
33 use warnings;
44
5 our $VERSION = '1.74';
5 our $VERSION = '1.76';
66
77 use IO::Handle;
88 use Carp;
9 use PerlIO;
910
1011 {
1112 no warnings;
4445 my $o = shift;
4546 $o =~ /^(?:keep|alpha|none)$/ or
4647 croak "invalid order";
48 }
49
50 sub _t_encoding ($) {
51 my $e = shift;
52 $e =~ /^[\w\-]+$/ or
53 croak "invalid encoding '$e'";
4754 }
4855 }
4956
6673 $order = 'keep' unless defined $order;
6774 _t_order($order);
6875 my $file = delete $opts{file};
69
76 my $encoding = delete $opts{encoding} || 'latin1';
77 _t_encoding($encoding);
7078
7179 %opts and croak "invalid option(s) '" . join("', '", keys %opts) . "'";
7280
9098 properties => {},
9199 next_line_number => 1,
92100 property_line_numbers => {},
93 file => $file };
101 file => $file,
102 encoding => $encoding };
94103 bless $self, $class;
95104
96105 if (defined $file) {
227236 sub load {
228237 my ($self, $file) = @_;
229238 _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: $!";
242 }
230243 $self->{properties}={};
231244 $self->{property_line_numbers}={};
232245 $self->{next_line_number}=1;
670683 of the properties as added or readed from a file. C<none> returns the
671684 properties unordered.
672685
686 =item encoding => $encoding
687
688 IO encoding used to read the configuration file. See L<PerlIO>.
689
690 When C<load> is called the given encoding is used unless the file
691 handler already has a encoding layer applied.
692
693 C<latin1> is used as the default encoding (as specified in the Java
694 properties specification).
695
696
673697 =back
674698
675699 =item Config::Properties-E<gt>new($defaults)