diff options
author | Bas Zoetekouw <bas> | 2008-09-30 19:30:03 +0000 |
---|---|---|
committer | Bas Zoetekouw <bas> | 2008-09-30 19:30:03 +0000 |
commit | 324421a41d575e97d2e7b2f51297e19771e9e4ef (patch) | |
tree | 390f6a399452a3e7ffd0b07b6c7b99948964ffea | |
parent | b8bbe054324844ae6cdfc1fcd64dc66bc7a1326c (diff) |
Move read_file() to Local::Util.
CVS version numbers
check_trans.pl: 1.71 -> 1.72
Perl/Local/Util.pm: 1.1 -> 1.2
-rw-r--r-- | Perl/Local/Util.pm | 28 | ||||
-rwxr-xr-x | check_trans.pl | 25 |
2 files changed, 31 insertions, 22 deletions
diff --git a/Perl/Local/Util.pm b/Perl/Local/Util.pm index 87501fb6383..137764b6b0d 100644 --- a/Perl/Local/Util.pm +++ b/Perl/Local/Util.pm @@ -22,6 +22,7 @@ scripts, and for which we don't want to add dependencies on external modules. package Local::Util; use 5.008; +use Carp; use strict; use warnings; @@ -30,7 +31,7 @@ BEGIN { use base qw( Exporter ); our $VERSION = sprintf "%d", q$Revision$ =~ /(\d+)/g; - our @EXPORT_OK = qw( uniq ); + our @EXPORT_OK = qw( uniq read_file ); our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); } @@ -61,6 +62,31 @@ sub uniq (@) map { $h{$_}++ == 0 ? $_ : () } @_; } +=item read_file + +Slurps an entire file and returns the contents of the file as a scalar, or +undef if an error occured (actual error will be in $!). + +This function is mean as a light-weight replacement for File::Slurp. + +=cut +sub read_file +{ + my $filename = shift + or croak("Local::Util::read_file: no file specified"); + + # slurp mode + local $/ = undef; + + # read the file + open( my $fd, '<', $filename ) or return; + my $text = <$fd>; + close( $fd ); + + return $text; +} + + 42; __END__ diff --git a/check_trans.pl b/check_trans.pl index 1248f13cf94..78af3632b56 100755 --- a/check_trans.pl +++ b/check_trans.pl @@ -90,7 +90,7 @@ FindBin::again(); # These modules reside under webwml/Perl use lib "$FindBin::Bin/Perl"; use Local::VCS ':all'; -use Local::Util 'uniq'; +use Local::Util qw/ uniq read_file /; use Local::WmlDiffTrans; use Webwml::TransCheck; use Webwml::TransIgnore; @@ -684,25 +684,6 @@ sub get_diff } #================================================= -##== read en entire file and return the text -##== -sub read_file -{ - my $filename = shift or die("Internal error: no file specified"); - - # slurp mode - local $/ = undef; - - # read the file - open( my $fd, '<', $filename ) - or die("Couldn't open file `$filename': $!\n"); - my $text = <$fd>; - close( $fd ); - - return $text; -} - -#================================================= #== get a diff while trying to match html tags #== sub get_diff_txt @@ -719,7 +700,9 @@ sub get_diff_txt my @english_txt = split( "\n", vcs_get_file( $english_file, $rev1 ) ); # Get translation file - my @transl_txt = split( "\n", read_file( $transl_file ) ); + my $transl_txt = read_file( $transl_file ) + or die("Couln't read `$transl_file': $!"); + my @transl_txt = split( "\n", $transl_txt ); # Get diff lines my @diff_txt = split( "\n", get_diff( $english_file, $rev1, $rev2 ) ); |