Changeset 5854


Ignore:
Timestamp:
07/05/09 21:49:57 (3 years ago)
Author:
ryan52
Message:

perltidy, update version number

Location:
trunk/Locale-Msgfmt
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt.pm

    r5853 r5854  
    1313our @EXPORT = qw/msgfmt/; 
    1414 
    15 our $VERSION = '0.08'; 
     15our $VERSION = '0.09'; 
    1616 
    1717sub msgfmt { 
    18   my $hash = shift; 
    19   if(!defined($hash)) { 
    20     die("error: must give input"); 
    21   } 
    22   if(!(ref($hash) eq "HASH")) { 
    23     $hash = {in => $hash}; 
    24   } 
    25   if(!defined($hash->{in}) or !length($hash->{in})) { 
    26     die("error: must give an input file"); 
    27   } 
    28   if(! -e $hash->{in}) { 
    29     die("error: input does not exist"); 
    30   } 
    31   if(-d $hash->{in}) { 
    32     return _msgfmt_dir($hash); 
    33   } else { 
    34     return _msgfmt($hash); 
    35   } 
     18    my $hash = shift; 
     19    if ( !defined($hash) ) { 
     20        die("error: must give input"); 
     21    } 
     22    if ( !( ref($hash) eq "HASH" ) ) { 
     23        $hash = { in => $hash }; 
     24    } 
     25    if ( !defined( $hash->{in} ) or !length( $hash->{in} ) ) { 
     26        die("error: must give an input file"); 
     27    } 
     28    if ( !-e $hash->{in} ) { 
     29        die("error: input does not exist"); 
     30    } 
     31    if ( -d $hash->{in} ) { 
     32        return _msgfmt_dir($hash); 
     33    } else { 
     34        return _msgfmt($hash); 
     35    } 
    3636} 
    3737 
    3838sub _msgfmt { 
    39   my $hash = shift; 
    40   if(! defined($hash->{in})) { 
    41     die("error: must give an input file"); 
    42   } 
    43   if(! -f $hash->{in}) { 
    44     die("error: input file does not exist"); 
    45   } 
    46   if(! defined($hash->{out})) { 
    47     if($hash->{in} =~ /\.po$/) { 
    48       $hash->{out} = $hash->{in}; 
    49       $hash->{out} =~ s/po$/mo/; 
    50     } else { 
    51       die("error: must give an output file"); 
    52     } 
    53   } 
    54   my $mo = Locale::Msgfmt::mo->new(); 
    55   $mo->initialize(); 
    56   my $po = Locale::Msgfmt::po->new({fuzzy => $hash->{fuzzy}}); 
    57   $po->parse($hash->{in}, $mo); 
    58   $mo->prepare(); 
    59   $mo->out($hash->{out}); 
    60   print $hash->{in} . " -> " . $hash->{out} . "\n" if($hash->{verbose}); 
    61   unlink($hash->{in}) if($hash->{remove}); 
     39    my $hash = shift; 
     40    if ( !defined( $hash->{in} ) ) { 
     41        die("error: must give an input file"); 
     42    } 
     43    if ( !-f $hash->{in} ) { 
     44        die("error: input file does not exist"); 
     45    } 
     46    if ( !defined( $hash->{out} ) ) { 
     47        if ( $hash->{in} =~ /\.po$/ ) { 
     48            $hash->{out} = $hash->{in}; 
     49            $hash->{out} =~ s/po$/mo/; 
     50        } else { 
     51            die("error: must give an output file"); 
     52        } 
     53    } 
     54    my $mo = Locale::Msgfmt::mo->new(); 
     55    $mo->initialize(); 
     56    my $po = Locale::Msgfmt::po->new( { fuzzy => $hash->{fuzzy} } ); 
     57    $po->parse( $hash->{in}, $mo ); 
     58    $mo->prepare(); 
     59    $mo->out( $hash->{out} ); 
     60    print $hash->{in} . " -> " . $hash->{out} . "\n" if ( $hash->{verbose} ); 
     61    unlink( $hash->{in} ) if ( $hash->{remove} ); 
    6262} 
    6363 
    6464sub _msgfmt_dir { 
    65   my $hash = shift; 
    66   if(! -d $hash->{in}) { 
    67     die("error: input directory does not exist"); 
    68   } 
    69   if(! defined($hash->{out})) { 
    70     $hash->{out} = $hash->{in}; 
    71   } 
    72   if(! -d $hash->{out}) { 
    73     File::Path::mkpath($hash->{out}); 
    74   } 
    75   opendir D, $hash->{in}; 
    76   my @list = readdir D; 
    77   closedir D; 
    78   my @removelist = (); 
    79   if($hash->{remove}) { 
    80     @removelist = grep /\.pot$/, @list; 
    81   } 
    82   @list = grep /\.po$/, @list; 
    83   my %files; 
    84   foreach(@list) { 
    85     my $in = File::Spec->catfile($hash->{in}, $_); 
    86     my $out = File::Spec->catfile($hash->{out}, substr($_, 0, -3) . ".mo"); 
    87     $files{$in} = $out; 
    88   } 
    89   foreach(keys %files) { 
    90     my %newhash = (%{$hash}); 
    91     $newhash{in} = $_; 
    92     $newhash{out} = $files{$_}; 
    93     _msgfmt(\%newhash); 
    94   } 
    95   foreach(@removelist) { 
    96     my $f = File::Spec->catfile($hash->{in}, $_); 
    97     print "-$f\n" if($hash->{verbose}); 
    98     unlink($f); 
    99   } 
     65    my $hash = shift; 
     66    if ( !-d $hash->{in} ) { 
     67        die("error: input directory does not exist"); 
     68    } 
     69    if ( !defined( $hash->{out} ) ) { 
     70        $hash->{out} = $hash->{in}; 
     71    } 
     72    if ( !-d $hash->{out} ) { 
     73        File::Path::mkpath( $hash->{out} ); 
     74    } 
     75    opendir D, $hash->{in}; 
     76    my @list = readdir D; 
     77    closedir D; 
     78    my @removelist = (); 
     79    if ( $hash->{remove} ) { 
     80        @removelist = grep /\.pot$/, @list; 
     81    } 
     82    @list = grep /\.po$/, @list; 
     83    my %files; 
     84    foreach (@list) { 
     85        my $in = File::Spec->catfile( $hash->{in}, $_ ); 
     86        my $out = File::Spec->catfile( $hash->{out}, substr( $_, 0, -3 ) . ".mo" ); 
     87        $files{$in} = $out; 
     88    } 
     89    foreach ( keys %files ) { 
     90        my %newhash = ( %{$hash} ); 
     91        $newhash{in} = $_; 
     92        $newhash{out} = $files{$_}; 
     93        _msgfmt( \%newhash ); 
     94    } 
     95    foreach (@removelist) { 
     96        my $f = File::Spec->catfile( $hash->{in}, $_ ); 
     97        print "-$f\n" if ( $hash->{verbose} ); 
     98        unlink($f); 
     99    } 
    100100} 
    101101 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt/Utils.pm

    r5660 r5854  
    44use warnings; 
    55 
    6 our $VERSION = '0.08'; 
     6our $VERSION = '0.09'; 
    77 
    88sub character { 
    9   return map {pack "N*", $_} @_; 
     9    return map { pack "N*", $_ } @_; 
    1010} 
    1111 
    1212sub _from_character { 
    13   return map {ord($_)} @_; 
     13    return map { ord($_) } @_; 
    1414} 
    1515 
    1616sub from_character { 
    17   return character(_from_character(@_)); 
     17    return character( _from_character(@_) ); 
    1818} 
    1919 
    2020sub _from_hex { 
    21   return map {hex($_)} @_; 
     21    return map { hex($_) } @_; 
    2222} 
    2323 
    2424sub from_hex { 
    25   return character(_from_hex(@_)); 
     25    return character( _from_hex(@_) ); 
    2626} 
    2727 
    2828sub _from_string { 
    29   return split //, join '', @_; 
     29    return split //, join '', @_; 
    3030} 
    3131 
    3232sub from_string { 
    33   return join_string(from_character(_from_string(@_))); 
     33    return join_string( from_character( _from_string(@_) ) ); 
    3434} 
    3535 
    3636sub join_string { 
    37   return join '', @_; 
     37    return join '', @_; 
    3838} 
    3939 
    4040sub number_to_s { 
    41   return sprintf "%d", shift; 
     41    return sprintf "%d", shift; 
    4242} 
    4343 
    4444sub null_terminate { 
    45   return pack "Z*", shift; 
     45    return pack "Z*", shift; 
    4646} 
    4747 
    4848sub null { 
    49   return null_terminate(""); 
     49    return null_terminate(""); 
    5050} 
    5151 
    5252sub eot { 
    53   return chr(4); 
     53    return chr(4); 
    5454} 
    5555 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt/mo.pm

    r5660 r5854  
    44use warnings; 
    55 
    6 our $VERSION = '0.08'; 
     6our $VERSION = '0.09'; 
    77 
    88use Locale::Msgfmt::Utils; 
    99 
    1010sub new { 
    11   return bless {}, shift; 
     11    return bless {}, shift; 
    1212} 
    1313 
    1414sub initialize { 
    15   my $self = shift; 
    16   $self->{magic} = "0x950412de"; 
    17   $self->{format} = 0; 
    18   $self->{strings} = {}; 
     15    my $self = shift; 
     16    $self->{magic}  = "0x950412de"; 
     17    $self->{format} = 0; 
     18    $self->{strings} = {}; 
    1919} 
    2020 
    2121sub add_string { 
    22   my ($self, $string, $translation) = @_; 
    23   $self->{strings}->{$string} = $translation; 
     22    my ( $self, $string, $translation ) = @_; 
     23    $self->{strings}->{$string} = $translation; 
    2424} 
    2525 
    2626sub prepare { 
    27   my $self = shift; 
    28   $self->{count} = scalar keys %{$self->{strings}}; 
    29   $self->{free_mem} = 28 + $self->{count} * 16; 
    30   @{$self->{sorted}} = sort keys %{$self->{strings}}; 
    31   @{$self->{translations}} = (); 
    32   foreach(@{$self->{sorted}}) { 
    33     push @{$self->{translations}}, $self->{strings}->{$_}; 
    34   } 
     27    my $self = shift; 
     28    $self->{count}    = scalar keys %{ $self->{strings} }; 
     29    $self->{free_mem} = 28 + $self->{count} * 16; 
     30    @{ $self->{sorted} }       = sort keys %{ $self->{strings} }; 
     31    @{ $self->{translations} } = (); 
     32    foreach ( @{ $self->{sorted} } ) { 
     33        push @{ $self->{translations} }, $self->{strings}->{$_}; 
     34    } 
    3535} 
    3636 
    3737sub out { 
    38   my $self = shift; 
    39   my $file = shift; 
    40   open OUT, ">", $file; 
    41   binmode OUT; 
    42   print OUT Locale::Msgfmt::Utils::from_hex($self->{magic}); 
    43   print OUT Locale::Msgfmt::Utils::character($self->{format}); 
    44   print OUT Locale::Msgfmt::Utils::character($self->{count}); 
    45   print OUT Locale::Msgfmt::Utils::character(28); 
    46   print OUT Locale::Msgfmt::Utils::character(28 + $self->{count} * 8); 
    47   print OUT Locale::Msgfmt::Utils::character(0); 
    48   print OUT Locale::Msgfmt::Utils::character(0); 
    49   foreach(@{$self->{sorted}}) { 
    50     my $length = length($_); 
    51     print OUT Locale::Msgfmt::Utils::character($length); 
    52     print OUT Locale::Msgfmt::Utils::character($self->{free_mem}); 
    53     $self->{free_mem} += $length + 1; 
    54   } 
    55   foreach(@{$self->{translations}}) { 
    56     my $length = length($_); 
    57     print OUT Locale::Msgfmt::Utils::character($length); 
    58     print OUT Locale::Msgfmt::Utils::character($self->{free_mem}); 
    59     $self->{free_mem} += $length + 1; 
    60   } 
    61   foreach(@{$self->{sorted}}) { 
    62     print OUT Locale::Msgfmt::Utils::null_terminate($_); 
    63   } 
    64   foreach(@{$self->{translations}}) { 
    65     print OUT Locale::Msgfmt::Utils::null_terminate($_); 
    66   } 
    67   close OUT; 
     38    my $self = shift; 
     39    my $file = shift; 
     40    open OUT, ">", $file; 
     41    binmode OUT; 
     42    print OUT Locale::Msgfmt::Utils::from_hex( $self->{magic} ); 
     43    print OUT Locale::Msgfmt::Utils::character( $self->{format} ); 
     44    print OUT Locale::Msgfmt::Utils::character( $self->{count} ); 
     45    print OUT Locale::Msgfmt::Utils::character(28); 
     46    print OUT Locale::Msgfmt::Utils::character( 28 + $self->{count} * 8 ); 
     47    print OUT Locale::Msgfmt::Utils::character(0); 
     48    print OUT Locale::Msgfmt::Utils::character(0); 
     49 
     50    foreach ( @{ $self->{sorted} } ) { 
     51        my $length = length($_); 
     52        print OUT Locale::Msgfmt::Utils::character($length); 
     53        print OUT Locale::Msgfmt::Utils::character( $self->{free_mem} ); 
     54        $self->{free_mem} += $length + 1; 
     55    } 
     56    foreach ( @{ $self->{translations} } ) { 
     57        my $length = length($_); 
     58        print OUT Locale::Msgfmt::Utils::character($length); 
     59        print OUT Locale::Msgfmt::Utils::character( $self->{free_mem} ); 
     60        $self->{free_mem} += $length + 1; 
     61    } 
     62    foreach ( @{ $self->{sorted} } ) { 
     63        print OUT Locale::Msgfmt::Utils::null_terminate($_); 
     64    } 
     65    foreach ( @{ $self->{translations} } ) { 
     66        print OUT Locale::Msgfmt::Utils::null_terminate($_); 
     67    } 
     68    close OUT; 
    6869} 
    6970 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt/po.pm

    r5660 r5854  
    66use warnings; 
    77 
    8 our $VERSION = '0.08'; 
     8our $VERSION = '0.09'; 
    99 
    1010sub new { 
    11   my $class = shift; 
    12   return bless shift || {}, $class; 
     11    my $class = shift; 
     12    return bless shift || {}, $class; 
    1313} 
    1414 
    1515sub cleanup_string { 
    16   my $str = shift; 
    17   $str =~ s/\\n/\n/g; 
    18   $str =~ s/\\r/\r/g; 
    19   $str =~ s/\\t/\t/g; 
    20   $str =~ s/\\"/"/g; 
    21   $str =~ s/\\\\/\\/g; 
    22   return $str; 
     16    my $str = shift; 
     17    $str =~ s/\\n/\n/g; 
     18    $str =~ s/\\r/\r/g; 
     19    $str =~ s/\\t/\t/g; 
     20    $str =~ s/\\"/"/g; 
     21    $str =~ s/\\\\/\\/g; 
     22    return $str; 
    2323} 
    2424 
    2525sub add_string { 
    26   my $self = shift; 
    27   my $hash = shift; 
    28   my %h = %{$hash}; 
    29   return if !(defined($h{msgid}) && defined($h{msgstr})); 
    30   return if ($h{fuzzy} && !$self->{fuzzy} && length($h{msgid}) > 0); 
    31   my $msgstr = join Locale::Msgfmt::Utils::null(), @{$h{msgstr}}; 
    32   return if($msgstr eq ""); 
    33   my $context; 
    34   my $plural; 
    35   if($h{msgctxt}) { 
    36     $context = cleanup_string($h{msgctxt}) . Locale::Msgfmt::Utils::eot(); 
    37   } else { 
    38     $context = ""; 
    39   } 
    40   if($h{msgid_plural}) { 
    41     $plural = Locale::Msgfmt::Utils::null() . cleanup_string($h{msgid_plural}); 
    42   } else { 
    43     $plural = ""; 
    44   } 
    45   $self->{mo}->add_string($context . cleanup_string($h{msgid}) . $plural, cleanup_string($msgstr)); 
     26    my $self = shift; 
     27    my $hash = shift; 
     28    my %h    = %{$hash}; 
     29    return if !( defined( $h{msgid} ) && defined( $h{msgstr} ) ); 
     30    return if ( $h{fuzzy} && !$self->{fuzzy} && length( $h{msgid} ) > 0 ); 
     31    my $msgstr = join Locale::Msgfmt::Utils::null(), @{ $h{msgstr} }; 
     32    return if ( $msgstr eq "" ); 
     33    my $context; 
     34    my $plural; 
     35 
     36    if ( $h{msgctxt} ) { 
     37        $context = cleanup_string( $h{msgctxt} ) . Locale::Msgfmt::Utils::eot(); 
     38    } else { 
     39        $context = ""; 
     40    } 
     41    if ( $h{msgid_plural} ) { 
     42        $plural = Locale::Msgfmt::Utils::null() . cleanup_string( $h{msgid_plural} ); 
     43    } else { 
     44        $plural = ""; 
     45    } 
     46    $self->{mo}->add_string( $context . cleanup_string( $h{msgid} ) . $plural, cleanup_string($msgstr) ); 
    4647} 
    4748 
    4849sub read_po { 
    49   my $self = shift; 
    50   my $pofile = shift; 
    51   my $mo = $self->{mo}; 
    52   open F, $pofile; 
    53   my %h = (); 
    54   my $type; 
    55   while (<F>) { 
    56     s/\r\n/\n/; 
    57     if(/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) { 
    58       $type = $1; 
    59       if(defined($h{$type})) { 
    60         $self->add_string(\%h); 
    61         %h = (); 
    62       } 
    63       $h{$type} = $2; 
    64     } 
    65     elsif(/^msgstr(?:\[(\d*)\])? +"(.*)" *$/) { 
    66       $type = "msgstr"; 
    67       if(!$h{$type}) { 
    68         @{$h{$type}} = (); 
    69       } 
    70       push @{$h{$type}}, $2; 
    71     } 
    72     elsif(/^"(.*)" *$/) { 
    73       if($type eq "msgstr") { 
    74         @{$h{$type}}[scalar(@{$h{$type}}) - 1] .= $1; 
    75       } else { 
    76         $h{$type} .= $1; 
    77       } 
    78     } 
    79     elsif(/^ *$/) { 
    80       $self->add_string(\%h); 
    81       %h = (); 
    82       $type = undef; 
    83     } elsif(/^#/) { 
    84       if(/^#, fuzzy/) { 
    85         $h{fuzzy} = 1; 
    86       } elsif (/^#:/) { 
    87         if(defined($h{msgid})) { 
    88           $self->add_string(\%h); 
    89           %h = (); 
    90           $type = undef; 
    91         } 
    92       } 
    93     } else { 
    94       print "unknown line: " . $_ . "\n"; 
    95     } 
    96   } 
    97   $self->add_string(\%h); 
    98   close F; 
     50    my $self   = shift; 
     51    my $pofile = shift; 
     52    my $mo     = $self->{mo}; 
     53    open F, $pofile; 
     54    my %h = (); 
     55    my $type; 
     56    while (<F>) { 
     57        s/\r\n/\n/; 
     58        if (/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) { 
     59            $type = $1; 
     60            if ( defined( $h{$type} ) ) { 
     61                $self->add_string( \%h ); 
     62                %h = (); 
     63            } 
     64            $h{$type} = $2; 
     65        } elsif (/^msgstr(?:\[(\d*)\])? +"(.*)" *$/) { 
     66            $type = "msgstr"; 
     67            if ( !$h{$type} ) { 
     68                @{ $h{$type} } = (); 
     69            } 
     70            push @{ $h{$type} }, $2; 
     71        } elsif (/^"(.*)" *$/) { 
     72            if ( $type eq "msgstr" ) { 
     73                @{ $h{$type} }[ scalar( @{ $h{$type} } ) - 1 ] .= $1; 
     74            } else { 
     75                $h{$type} .= $1; 
     76            } 
     77        } elsif (/^ *$/) { 
     78            $self->add_string( \%h ); 
     79            %h    = (); 
     80            $type = undef; 
     81        } elsif (/^#/) { 
     82            if (/^#, fuzzy/) { 
     83                $h{fuzzy} = 1; 
     84            } elsif (/^#:/) { 
     85                if ( defined( $h{msgid} ) ) { 
     86                    $self->add_string( \%h ); 
     87                    %h    = (); 
     88                    $type = undef; 
     89                } 
     90            } 
     91        } else { 
     92            print "unknown line: " . $_ . "\n"; 
     93        } 
     94    } 
     95    $self->add_string( \%h ); 
     96    close F; 
    9997} 
    10098 
    10199sub parse { 
    102   my $self = shift; 
    103   my ($pofile, $mo) = @_; 
    104   $self->{mo} = $mo; 
    105   $self->read_po($pofile); 
     100    my $self = shift; 
     101    my ( $pofile, $mo ) = @_; 
     102    $self->{mo} = $mo; 
     103    $self->read_po($pofile); 
    106104} 
    107105 
  • trunk/Locale-Msgfmt/lib/Module/Install/Msgfmt.pm

    r5853 r5854  
    66use Module::Install::Share; 
    77 
    8 use vars qw{$VERSION @ISA $ISCORE}; 
    9 $VERSION = '0.01'; 
    10 @ISA     = 'Module::Install::Base'; 
     8our $VERSION = '0.09'; 
     9our @ISA     = 'Module::Install::Base'; 
    1110 
    1211sub install_share_with_mofiles { 
    13   my @orig = (@_); 
    14   my $self = shift; 
    15   my $class     = ref($self); 
    16   my $inc_class = join('::', @{$self->_top}{qw(prefix name)}); 
    17   my $dir  = @_ ? pop   : 'share'; 
    18   my $type = @_ ? shift : 'dist'; 
    19   my $module = @_ ? shift : ''; 
    20   $self->build_requires( 'Locale::Msgfmt' => '0.09' ); 
    21   install_share(@orig); 
    22   my $distname = ""; 
    23   if ( $type eq 'dist' ) { 
    24     $distname = $self->name; 
    25   } else { 
    26     $distname = Module::Install::_CLASS($module); 
    27     $distname =~ s/::/-/g; 
    28   } 
    29   my $path = File::Spec->catfile('auto', 'share', $type, $distname); 
    30   $self->postamble(<<"END_MAKEFILE"); 
     12    my @orig      = (@_); 
     13    my $self      = shift; 
     14    my $class     = ref($self); 
     15    my $inc_class = join( '::', @{ $self->_top }{qw(prefix name)} ); 
     16    my $dir       = @_ ? pop : 'share'; 
     17    my $type      = @_ ? shift : 'dist'; 
     18    my $module    = @_ ? shift : ''; 
     19    $self->build_requires( 'Locale::Msgfmt' => '0.09' ); 
     20    install_share(@orig); 
     21    my $distname = ""; 
     22 
     23    if ( $type eq 'dist' ) { 
     24        $distname = $self->name; 
     25    } else { 
     26        $distname = Module::Install::_CLASS($module); 
     27        $distname =~ s/::/-/g; 
     28    } 
     29    my $path = File::Spec->catfile( 'auto', 'share', $type, $distname ); 
     30    $self->postamble(<<"END_MAKEFILE"); 
    3131config :: 
    3232\t\$(NOECHO) \$(PERL) "-M$inc_class" -e "do_msgfmt(q(\$(INST_LIB)), q($path))" 
     
    3737# blib/lib/auto/share/dist/Padre/locale/he.po 
    3838sub do_msgfmt { 
    39   my $self = shift; 
    40   my $lib = shift; 
    41   my $sharepath = shift; 
    42   my $fullpath = File::Spec->catfile($lib, $sharepath, 'locale'); 
    43   if(! -d $fullpath) { 
    44     die("$fullpath isn't a directory"); 
    45   } 
    46   require Locale::Msgfmt; 
    47   Locale::Msgfmt::msgfmt({in => $fullpath, verbose => 1, remove => 1}); 
     39    my $self      = shift; 
     40    my $lib      = shift; 
     41    my $sharepath = shift; 
     42    my $fullpath  = File::Spec->catfile( $lib, $sharepath, 'locale' ); 
     43    if ( !-d $fullpath ) { 
     44        die("$fullpath isn't a directory"); 
     45    } 
     46    require Locale::Msgfmt; 
     47    Locale::Msgfmt::msgfmt( { in => $fullpath, verbose => 1, remove => 1 } ); 
    4848} 
  • trunk/Locale-Msgfmt/t/00-load.t

    r5526 r5854  
    44 
    55BEGIN { 
    6     use_ok( 'Locale::Msgfmt' ); 
     6    use_ok('Locale::Msgfmt'); 
    77} 
    88 
    9 diag( "Testing Locale::Msgfmt $Locale::Msgfmt::VERSION, Perl $], $^X" ); 
     9diag("Testing Locale::Msgfmt $Locale::Msgfmt::VERSION, Perl $], $^X"); 
  • trunk/Locale-Msgfmt/t/interface.t

    r5625 r5854  
    1010 
    1111sub slurp { 
    12     open F, shift; 
    13     binmode F; 
    14     my $s = ""; 
    15     while(<F>) { $s .= $_; }; 
    16     close F; 
    17     return $s; 
     12    open F, shift; 
     13    binmode F; 
     14    my $s = ""; 
     15    while (<F>) { $s .= $_; } 
     16    close F; 
     17    return $s; 
    1818} 
    1919 
    20 $dir = File::Temp::tempdir(CLEANUP => 0); 
    21 copy(File::Spec->catfile("t", "samples", "basic.po"), File::Spec->catfile($dir, "basic.po")); 
    22 msgfmt(File::Spec->catfile($dir, "basic.po")); 
    23 ok(-f File::Spec->catfile($dir, "basic.mo")); 
    24 unlink File::Spec->catfile($dir, "basic.mo"); 
    25 msgfmt({in => File::Spec->catfile($dir, "basic.po")}); 
    26 ok(-f File::Spec->catfile($dir, "basic.mo")); 
    27 unlink File::Spec->catfile($dir, "basic.mo"); 
    28 msgfmt({in => File::Spec->catfile($dir, "basic.po"), out => File::Spec->catfile($dir, "mo")}); 
    29 ok(-f File::Spec->catfile($dir, "mo")); 
    30 unlink(File::Spec->catfile($dir, "mo")); 
    31 mkdir(File::Spec->catdir($dir, "a")); 
    32 mkdir(File::Spec->catdir($dir, "b")); 
    33 move(File::Spec->catfile($dir, "basic.po"), File::Spec->catfile($dir, "a", "basic.po")); 
    34 msgfmt(File::Spec->catdir($dir, "a")); 
    35 ok(-f File::Spec->catfile($dir, "a", "basic.mo")); 
    36 unlink File::Spec->catfile($dir, "a", "basic.mo"); 
    37 msgfmt({in => File::Spec->catdir($dir, "a")}); 
    38 ok(-f File::Spec->catfile($dir, "a", "basic.mo")); 
    39 unlink File::Spec->catfile($dir, "a", "basic.mo"); 
    40 msgfmt({in => File::Spec->catdir($dir, "a"), out => File::Spec->catdir($dir, "b"),}); 
    41 ok(-f File::Spec->catfile($dir, "b", "basic.mo")); 
    42 unlink(File::Spec->catfile($dir, "b", "basic.mo")); 
    43 move(File::Spec->catfile($dir, "a", "basic.po"), File::Spec->catfile($dir, "basic.po")); 
    44 msgfmt({in => File::Spec->catfile($dir, "basic.po"), fuzzy => 1, out => File::Spec->catfile($dir, "fuzzy")}); 
    45 msgfmt({in => File::Spec->catfile($dir, "basic.po"), out => File::Spec->catfile($dir, "not_fuzzy")}); 
    46 ok(!(slurp(File::Spec->catfile($dir, "not_fuzzy")) eq slurp(File::Spec->catfile($dir, "fuzzy")))); 
    47 unlink(File::Spec->catfile($dir, "not_fuzzy")); 
    48 unlink(File::Spec->catfile($dir, "fuzzy")); 
    49 move(File::Spec->catfile($dir, "basic.po"), File::Spec->catfile($dir, "a", "basic.po")); 
    50 msgfmt({in => File::Spec->catfile($dir, "a"), fuzzy => 1, out => File::Spec->catfile($dir, "b")}); 
    51 msgfmt({in => File::Spec->catfile($dir, "a"), out => File::Spec->catfile($dir, "c")}); 
    52 ok(!(slurp(File::Spec->catfile($dir, "b", "basic.mo")) eq slurp(File::Spec->catfile($dir, "c", "basic.mo")))); 
    53 unlink(File::Spec->catfile($dir, "c", "basic.mo")); 
    54 unlink(File::Spec->catfile($dir, "b", "basic.mo")); 
     20$dir = File::Temp::tempdir( CLEANUP => 0 ); 
     21copy( File::Spec->catfile( "t", "samples", "basic.po" ), File::Spec->catfile( $dir, "basic.po" ) ); 
     22msgfmt( File::Spec->catfile( $dir, "basic.po" ) ); 
     23ok( -f File::Spec->catfile( $dir, "basic.mo" ) ); 
     24unlink File::Spec->catfile( $dir, "basic.mo" ); 
     25msgfmt( { in => File::Spec->catfile( $dir, "basic.po" ) } ); 
     26ok( -f File::Spec->catfile( $dir, "basic.mo" ) ); 
     27unlink File::Spec->catfile( $dir, "basic.mo" ); 
     28msgfmt( { in => File::Spec->catfile( $dir, "basic.po" ), out => File::Spec->catfile( $dir, "mo" ) } ); 
     29ok( -f File::Spec->catfile( $dir, "mo" ) ); 
     30unlink( File::Spec->catfile( $dir, "mo" ) ); 
     31mkdir( File::Spec->catdir( $dir, "a" ) ); 
     32mkdir( File::Spec->catdir( $dir, "b" ) ); 
     33move( File::Spec->catfile( $dir, "basic.po" ), File::Spec->catfile( $dir, "a", "basic.po" ) ); 
     34msgfmt( File::Spec->catdir( $dir, "a" ) ); 
     35ok( -f File::Spec->catfile( $dir, "a", "basic.mo" ) ); 
     36unlink File::Spec->catfile( $dir, "a", "basic.mo" ); 
     37msgfmt( { in => File::Spec->catdir( $dir, "a" ) } ); 
     38ok( -f File::Spec->catfile( $dir, "a", "basic.mo" ) ); 
     39unlink File::Spec->catfile( $dir, "a", "basic.mo" ); 
     40msgfmt( { in => File::Spec->catdir( $dir, "a" ), out => File::Spec->catdir( $dir, "b" ), } ); 
     41ok( -f File::Spec->catfile( $dir, "b", "basic.mo" ) ); 
     42unlink( File::Spec->catfile( $dir, "b", "basic.mo" ) ); 
     43move( File::Spec->catfile( $dir, "a", "basic.po" ), File::Spec->catfile( $dir, "basic.po" ) ); 
     44msgfmt( { in => File::Spec->catfile( $dir, "basic.po" ), fuzzy => 1, out => File::Spec->catfile( $dir, "fuzzy" ) } ); 
     45msgfmt( { in => File::Spec->catfile( $dir, "basic.po" ), out => File::Spec->catfile( $dir, "not_fuzzy" ) } ); 
     46ok( !( slurp( File::Spec->catfile( $dir, "not_fuzzy" ) ) eq slurp( File::Spec->catfile( $dir, "fuzzy" ) ) ) ); 
     47unlink( File::Spec->catfile( $dir, "not_fuzzy" ) ); 
     48unlink( File::Spec->catfile( $dir, "fuzzy" ) ); 
     49move( File::Spec->catfile( $dir, "basic.po" ), File::Spec->catfile( $dir, "a", "basic.po" ) ); 
     50msgfmt( { in => File::Spec->catfile( $dir, "a" ), fuzzy => 1, out => File::Spec->catfile( $dir, "b" ) } ); 
     51msgfmt( { in => File::Spec->catfile( $dir, "a" ), out => File::Spec->catfile( $dir, "c" ) } ); 
     52ok( !( slurp( File::Spec->catfile( $dir, "b", "basic.mo" ) ) eq slurp( File::Spec->catfile( $dir, "c", "basic.mo" ) ) ) 
     53); 
     54unlink( File::Spec->catfile( $dir, "c", "basic.mo" ) ); 
     55unlink( File::Spec->catfile( $dir, "b", "basic.mo" ) ); 
    5556 
  • trunk/Locale-Msgfmt/t/msgfmt.t

    r5729 r5854  
    88 
    99SKIP: { 
    10     skip "Test needs Locale::Maketext::Gettext", 5 if(!eval("use Locale::Maketext::Gettext; 1;")); 
    11     sub my_read_mo { 
    12         my %h = read_mo(shift); 
    13         return \%h; 
    14     } 
    15     sub my_msgfmt { 
    16         my ($fh, $filename) = File::Temp::tempfile(); 
    17         close $fh; 
    18         my $in = shift; 
    19         my $fuzzy = 0; 
    20         if(shift) { 
    21             $fuzzy = 1; 
    22         } 
    23         msgfmt({in => $in, out => $filename, fuzzy => $fuzzy}); 
    24         return $filename; 
    25     } 
    26     sub do_one_test { 
    27         my $basename = shift; 
    28         my $po = File::Spec->catfile("t", "samples", $basename . ".po"); 
    29         my $mo = File::Spec->catfile("t", "samples", $basename . ".mo"); 
    30         my $good = my_read_mo($mo); 
    31         my $filename = my_msgfmt($po); 
    32         my $test = my_read_mo($filename); 
    33         is_deeply($test, $good); 
    34         if($basename eq "basic") { 
    35             unlink($filename); 
    36             $filename = my_msgfmt($po, 1); 
    37             $good = my_read_mo(File::Spec->catfile("t", "samples", "fuzz.mo")); 
    38             $test = my_read_mo($filename); 
    39             is_deeply($test, $good); 
    40         } 
    41         unlink($filename); 
    42     } 
    43     do_one_test("basic"); 
    44     do_one_test("ja"); 
    45     do_one_test("context"); 
    46     do_one_test("ngettext"); 
     10    skip "Test needs Locale::Maketext::Gettext", 5 if ( !eval("use Locale::Maketext::Gettext; 1;") ); 
     11 
     12    sub my_read_mo { 
     13        my %h = read_mo(shift); 
     14        return \%h; 
     15    } 
     16 
     17    sub my_msgfmt { 
     18        my ( $fh, $filename ) = File::Temp::tempfile(); 
     19        close $fh; 
     20        my $in    = shift; 
     21        my $fuzzy = 0; 
     22        if (shift) { 
     23            $fuzzy = 1; 
     24        } 
     25        msgfmt( { in => $in, out => $filename, fuzzy => $fuzzy } ); 
     26        return $filename; 
     27    } 
     28 
     29    sub do_one_test { 
     30        my $basename = shift; 
     31        my $po       = File::Spec->catfile( "t", "samples", $basename . ".po" ); 
     32        my $mo       = File::Spec->catfile( "t", "samples", $basename . ".mo" ); 
     33        my $good     = my_read_mo($mo); 
     34        my $filename = my_msgfmt($po); 
     35        my $test     = my_read_mo($filename); 
     36        is_deeply( $test, $good ); 
     37        if ( $basename eq "basic" ) { 
     38            unlink($filename); 
     39            $filename = my_msgfmt( $po, 1 ); 
     40            $good = my_read_mo( File::Spec->catfile( "t", "samples", "fuzz.mo" ) ); 
     41            $test = my_read_mo($filename); 
     42            is_deeply( $test, $good ); 
     43        } 
     44        unlink($filename); 
     45    } 
     46    do_one_test("basic"); 
     47    do_one_test("ja"); 
     48    do_one_test("context"); 
     49    do_one_test("ngettext"); 
    4750} 
    4851 
Note: See TracChangeset for help on using the changeset viewer.