1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Use fields, and "my Locale::PO" where applicable.

This commit is contained in:
Kalle Olavi Niemitalo 2006-01-06 17:56:08 +02:00 committed by Kalle Olavi Niemitalo
parent 35d9107406
commit 4e653e8c84

View File

@ -7,6 +7,9 @@ use warnings;
package Locale::PO; package Locale::PO;
use Carp; use Carp;
use fields qw(msgid msgid_plural msgstr msgstr_n
comment automatic reference
fuzzy c_format php_format);
#use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); #use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
#use locale; #use locale;
@ -23,9 +26,7 @@ our $VERSION = '0.16.kon';
sub new { sub new {
my $this = shift; my $this = shift;
my %options = @_; my %options = @_;
my $class = ref($this) || $this; my Locale::PO $self = ref($this) ? $this : fields::new($this);
my $self = {};
bless $self, $class;
$self->msgid( $options{'-msgid'} ) if defined( $options{'-msgid'} ); $self->msgid( $options{'-msgid'} ) if defined( $options{'-msgid'} );
$self->msgid_plural( $options{'-msgid_plural'} ) $self->msgid_plural( $options{'-msgid_plural'} )
if defined( $options{'-msgid_plural'} ); if defined( $options{'-msgid_plural'} );
@ -46,12 +47,12 @@ sub new {
} }
sub msgid { sub msgid {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'msgid'} = $self->quote(shift) : $self->{'msgid'}; @_ ? $self->{'msgid'} = $self->quote(shift) : $self->{'msgid'};
} }
sub msgid_plural { sub msgid_plural {
my $self = shift; my Locale::PO $self = shift;
@_ @_
? $self->{'msgid_plural'} = ? $self->{'msgid_plural'} =
$self->quote(shift) $self->quote(shift)
@ -59,12 +60,12 @@ sub msgid_plural {
} }
sub msgstr { sub msgstr {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'msgstr'} = $self->quote(shift) : $self->{'msgstr'}; @_ ? $self->{'msgstr'} = $self->quote(shift) : $self->{'msgstr'};
} }
sub msgstr_n { sub msgstr_n {
my $self = shift; my Locale::PO $self = shift;
if (@_) { if (@_) {
my $hashref = shift; my $hashref = shift;
@ -87,37 +88,37 @@ sub msgstr_n {
} }
sub comment { sub comment {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'comment'} = shift: $self->{'comment'}; @_ ? $self->{'comment'} = shift: $self->{'comment'};
} }
sub automatic { sub automatic {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'automatic'} = shift: $self->{'automatic'}; @_ ? $self->{'automatic'} = shift: $self->{'automatic'};
} }
sub reference { sub reference {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'reference'} = shift: $self->{'reference'}; @_ ? $self->{'reference'} = shift: $self->{'reference'};
} }
sub fuzzy { sub fuzzy {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'fuzzy'} = shift: $self->{'fuzzy'}; @_ ? $self->{'fuzzy'} = shift: $self->{'fuzzy'};
} }
sub c_format { sub c_format {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'c_format'} = shift: $self->{'c_format'}; @_ ? $self->{'c_format'} = shift: $self->{'c_format'};
} }
sub php_format { sub php_format {
my $self = shift; my Locale::PO $self = shift;
@_ ? $self->{'php_format'} = shift: $self->{'php_format'}; @_ ? $self->{'php_format'} = shift: $self->{'php_format'};
} }
sub normalize_str { sub normalize_str {
my $self = shift; my $self = shift; # can be called as a class method
my $string = shift; my $string = shift;
my $dequoted = $self->dequote($string); my $dequoted = $self->dequote($string);
@ -144,7 +145,7 @@ sub normalize_str {
} }
sub dump { sub dump {
my $self = shift; my Locale::PO $self = shift;
my $dump; my $dump;
$dump = $self->dump_multi_comment( $self->comment, "# " ) $dump = $self->dump_multi_comment( $self->comment, "# " )
if ( $self->comment ); if ( $self->comment );
@ -180,7 +181,7 @@ sub dump {
} }
sub dump_multi_comment { sub dump_multi_comment {
my $self = shift; my $self = shift; # can be called as a class method
my $comment = shift; my $comment = shift;
my $leader = shift; my $leader = shift;
my $chopped = $leader; my $chopped = $leader;
@ -194,14 +195,14 @@ sub dump_multi_comment {
# Quote a string properly # Quote a string properly
sub quote { sub quote {
my $self = shift; my $self = shift; # can be called as a class method
my $string = shift; my $string = shift;
$string =~ s/"/\\"/g; $string =~ s/"/\\"/g;
return "\"$string\""; return "\"$string\"";
} }
sub dequote { sub dequote {
my $self = shift; my $self = shift; # can be called as a class method
my $string = shift; my $string = shift;
$string =~ s/^"(.*)"/$1/; $string =~ s/^"(.*)"/$1/;
$string =~ s/\\"/"/g; $string =~ s/\\"/"/g;
@ -209,17 +210,17 @@ sub dequote {
} }
sub save_file_fromarray { sub save_file_fromarray {
my $self = shift; my $self = shift; # normally called as a class method
$self->save_file( @_, 0 ); $self->save_file( @_, 0 );
} }
sub save_file_fromhash { sub save_file_fromhash {
my $self = shift; my $self = shift; # normally called as a class method
$self->save_file( @_, 1 ); $self->save_file( @_, 1 );
} }
sub save_file { sub save_file {
my $self = shift; my $self = shift; # normally called as a class method
my $file = shift; my $file = shift;
my $entries = shift; my $entries = shift;
my $ashash = shift; my $ashash = shift;
@ -238,17 +239,17 @@ sub save_file {
} }
sub load_file_asarray { sub load_file_asarray {
my $self = shift; my $self = shift; # normally called as a class method
$self->load_file( $_[0], 0 ); $self->load_file( $_[0], 0 );
} }
sub load_file_ashash { sub load_file_ashash {
my $self = shift; my $self = shift; # normally called as a class method
$self->load_file( $_[0], 1 ); $self->load_file( $_[0], 1 );
} }
sub load_file { sub load_file {
my $self = shift; my $self = shift; # normally called as a class method
my $file = shift; my $file = shift;
my $ashash = shift; my $ashash = shift;
my ( @entries, %entries ); my ( @entries, %entries );
@ -586,6 +587,7 @@ Added the copyright notice (from README) and this history.
Corrected a typo in the documentation. Corrected a typo in the documentation.
Documented quoting in the C<msgid>, C<msgid_plural>, C<msgstr>, and C<msgstr_n> methods. Documented quoting in the C<msgid>, C<msgid_plural>, C<msgstr>, and C<msgstr_n> methods.
Documented newlines in the C<comment>, C<automatic>, and C<reference> methods. Documented newlines in the C<comment>, C<automatic>, and C<reference> methods.
Use fields, and "my Locale::PO" where applicable.
=back =back