Changeset 5880


Ignore:
Timestamp:
07/06/09 10:39:27 (3 years ago)
Author:
szabgab
Message:

fix some open() calls and add some error handling

Location:
trunk/Locale-Msgfmt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Locale-Msgfmt/Changes

    r5866 r5880  
    11Revision history for Locale-Msgfmt 
     2 
     3        - some code improvement in open() and opendir() and error handling (SZABGAB) 
    24 
    350.10    Jul 5, 2009 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt.pm

    r5866 r5880  
    7373        File::Path::mkpath( $hash->{out} ); 
    7474    } 
    75     opendir D, $hash->{in}; 
    76     my @list = readdir D; 
    77     closedir D; 
     75    opendir my $D, $hash->{in} or die "Could not open ($hash->{in}) $!"; 
     76    my @list = readdir $D; 
     77    closedir $D; 
    7878    my @removelist = (); 
    7979    if ( $hash->{remove} ) { 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt/mo.pm

    r5866 r5880  
    3838    my $self = shift; 
    3939    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); 
     40    open my $OUT, ">", $file or die "Could not open ($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); 
    4949 
    5050    foreach ( @{ $self->{sorted} } ) { 
    5151        my $length = length($_); 
    52         print OUT Locale::Msgfmt::Utils::character($length); 
    53         print OUT Locale::Msgfmt::Utils::character( $self->{free_mem} ); 
     52        print $OUT Locale::Msgfmt::Utils::character($length); 
     53        print $OUT Locale::Msgfmt::Utils::character( $self->{free_mem} ); 
    5454        $self->{free_mem} += $length + 1; 
    5555    } 
    5656    foreach ( @{ $self->{translations} } ) { 
    5757        my $length = length($_); 
    58         print OUT Locale::Msgfmt::Utils::character($length); 
    59         print OUT Locale::Msgfmt::Utils::character( $self->{free_mem} ); 
     58        print $OUT Locale::Msgfmt::Utils::character($length); 
     59        print $OUT Locale::Msgfmt::Utils::character( $self->{free_mem} ); 
    6060        $self->{free_mem} += $length + 1; 
    6161    } 
    6262    foreach ( @{ $self->{sorted} } ) { 
    63         print OUT Locale::Msgfmt::Utils::null_terminate($_); 
     63        print $OUT Locale::Msgfmt::Utils::null_terminate($_); 
    6464    } 
    6565    foreach ( @{ $self->{translations} } ) { 
    66         print OUT Locale::Msgfmt::Utils::null_terminate($_); 
     66        print $OUT Locale::Msgfmt::Utils::null_terminate($_); 
    6767    } 
    68     close OUT; 
     68    close $OUT; 
    6969} 
    7070 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt/po.pm

    r5866 r5880  
    5151    my $pofile = shift; 
    5252    my $mo     = $self->{mo}; 
    53     open F, $pofile; 
     53    open my $F, '<', $pofile or die "Could not open ($pofile) $!"; 
    5454    my %h = (); 
    5555    my $type; 
    56     while (<F>) { 
     56    while (<$F>) { 
    5757        s/\r\n/\n/; 
    5858        if (/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) { 
     
    9494    } 
    9595    $self->add_string( \%h ); 
    96     close F; 
     96    close $F; 
    9797} 
    9898 
  • trunk/Locale-Msgfmt/t/interface.t

    r5854 r5880  
    1010 
    1111sub slurp { 
    12     open F, shift; 
    13     binmode F; 
     12    my $file = shift; 
     13    open my $F, '<', $file or die "Could not open ($file) $!"; 
     14    binmode $F; 
    1415    my $s = ""; 
    15     while (<F>) { $s .= $_; } 
    16     close F; 
     16    while (<$F>) { $s .= $_; } 
     17    close $F; 
    1718    return $s; 
    1819} 
Note: See TracChangeset for help on using the changeset viewer.