diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-04-28 11:25:26 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-04-28 11:25:26 +0000 |
commit | 11a4d7c3b70b617bdce862eb466306d9673e66e7 (patch) | |
tree | 813c10472765c23ae9b109e763101e72da4ac4d7 | |
parent | 26ebc5ad59c9044e10fa55ebf57f1aa245738e92 (diff) | |
download | perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar.gz perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar.bz2 perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar.xz perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.zip |
- deprecate "open F, ..." prefering "open(my $F, ...)"
- fix an internal_error
-rw-r--r-- | MDK/Common/File.pm | 23 | ||||
-rw-r--r-- | MDK/Common/System.pm | 4 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.ml | 15 |
3 files changed, 27 insertions, 15 deletions
diff --git a/MDK/Common/File.pm b/MDK/Common/File.pm index bf4cd01..a5f95d3 100644 --- a/MDK/Common/File.pm +++ b/MDK/Common/File.pm @@ -122,11 +122,11 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK); sub dirname { local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' } sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ } -sub cat_ { local *F; open F, $_[0] or return; my @l = <F>; wantarray() ? @l : join '', @l } -sub cat_or_die { local *F; open F, $_[0] or die "can't read file $_[0]: $!\n"; my @l = <F>; wantarray() ? @l : join '', @l } +sub cat_ { open(my $F, $_[0]) or return; my @l = <$F>; wantarray() ? @l : join '', @l } +sub cat_or_die { open(my $F, $_[0]) or die "can't read file $_[0]: $!\n"; my @l = <$F>; wantarray() ? @l : join '', @l } sub cat__ { my ($f) = @_; my @l = <$f>; wantarray() ? @l : join '', @l } -sub output { my $f = shift; local *F; open F, ">$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 } -sub append_to_file { my $f = shift; local *F; open F, ">>$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 } +sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 } +sub append_to_file { my $f = shift; open(my $F, ">>$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 } sub output_p { my $f = shift; mkdir_p(dirname($f)); output($f, @_) } sub output_with_perm { my ($f, $perm, @l) = @_; mkdir_p(dirname($f)); output($f, @l); chmod $perm, $f } sub linkf { unlink $_[1]; link $_[0], $_[1] } @@ -186,9 +186,9 @@ sub cp_with_option { require MDK::Common::System; MDK::Common::System::syscall_('mknod', $dest, $stat[2], $stat[6]) or die "mknod failed (dev $dest): $!"; } else { - local *F; open F, $src or die "can't open $src for reading: $!\n"; - local *G; open G, "> $dest"; - local $_; while (<F>) { print G $_ } + open(my $F, $src) or die "can't open $src for reading: $!\n"; + open(my $G, "> $dest"); + local $_; while (<$F>) { print $G $_ } chmod((stat($src))[2], $dest); } } @@ -201,8 +201,8 @@ sub cp_af { cp_with_option('af', @_) } sub touch { my ($f) = @_; unless (-e $f) { - local *F; - open F, ">$f"; + my $F; + open($F, ">$f"); } my $now = time(); utime $now, $now, $f; @@ -286,9 +286,8 @@ sub expand_symlinks { sub openFileMaybeCompressed { my ($f) = @_; -e $f || -e "$f.gz" or die "file $f not found"; - local *F; - open F, -e $f ? $f : "gzip -dc $f.gz|" or die "file $f is not readable"; - *F; + open(my $F, -e $f ? $f : "gzip -dc $f.gz|") or die "file $f is not readable"; + $F; } sub catMaybeCompressed { cat__(openFileMaybeCompressed($_[0])) } diff --git a/MDK/Common/System.pm b/MDK/Common/System.pm index e4f5476..a864968 100644 --- a/MDK/Common/System.pm +++ b/MDK/Common/System.pm @@ -303,9 +303,9 @@ sub whereis_binary { sub getVarsFromSh { my %l; - local *F; open F, $_[0] or return; + open(my $F, $_[0]) or return; local $_; - while (<F>) { + while (<$F>) { s/#.*//; # remove comments my ($v, $val, $val2) = /^\s* # leading space diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 1e26878..3370d9a 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -86,6 +86,10 @@ let rec un_parenthesize_full = function | List[e] -> un_parenthesize_full e | e -> e +let rec un_parenthesize_full_l = function + | [ List l ] -> un_parenthesize_full_l l + | l -> l + let is_always_true = function | Num(n, _) -> float_of_string n <> 0. | Raw_string(s, _) -> s <> "" @@ -804,6 +808,15 @@ let call_raw force_non_builtin_func (e, para) = if is_not_a_scalar (List.hd para) then warn_rule "never use \"length @l\", it returns the length of the string int(@l)" ; None + | "open" -> + (match para with + | [ List(Ident(None, name, _) :: _) ] + | Ident(None, name, _) :: _ -> + if not (List.member [ "STDIN" ; "STDOUT" ; "STDERR" ]) then + warn_rule (sprintf "use a scalar instead of a bareword (eg: occurrences of %s with $%s)" name name) + | _ -> ()); + None + | "split" -> (match para with | [ List(Call_op("m//", Deref(I_scalar, Ident(None, "_", _)) :: pattern, pos) :: l) ] @@ -1134,7 +1147,7 @@ let mcontext_check_none msg expr esp = iter (l_expr, l) | [], [] -> () | _ -> internal_error "mcontext_check_none" - in iter (l_expr, l) + in iter (un_parenthesize_full_l l_expr, l) | _ -> internal_error "mcontext_check_none") | _ -> match expr with |