summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-12-02 20:13:57 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-12-02 20:13:57 +0000
commit15698d0e3d680ce81348237b718834bd3b72ef15 (patch)
tree300fe45b50061455ffd3503ba30f16664ec61887
parentcbfb3ba09991893db180d37e7498077fbe5d0042 (diff)
downloadperl-MDK-Common-15698d0e3d680ce81348237b718834bd3b72ef15.tar
perl-MDK-Common-15698d0e3d680ce81348237b718834bd3b72ef15.tar.gz
perl-MDK-Common-15698d0e3d680ce81348237b718834bd3b72ef15.tar.bz2
perl-MDK-Common-15698d0e3d680ce81348237b718834bd3b72ef15.tar.xz
perl-MDK-Common-15698d0e3d680ce81348237b718834bd3b72ef15.zip
add output_with_perm(), cat_or_die()
-rw-r--r--MDK/Common/File.pm16
-rw-r--r--perl-MDK-Common.spec6
2 files changed, 18 insertions, 4 deletions
diff --git a/MDK/Common/File.pm b/MDK/Common/File.pm
index 1bec2f5..fd15da3 100644
--- a/MDK/Common/File.pm
+++ b/MDK/Common/File.pm
@@ -25,6 +25,10 @@ array context it returns the lines.
If the file doesn't exist, it returns undef
+=item cat_or_die(FILENAME)
+
+same as C<cat_> but dies when something goes wrong
+
=item cat__(FILEHANDLE REF)
returns the file content: in scalar context it returns a single string, in
@@ -42,6 +46,10 @@ add the LIST at the end of the file
just like C<output> but creates directories if needed
+=item output_with_perm(FILENAME, PERMISSION, LIST)
+
+same as C<output_p> but sets FILENAME permission to PERMISSION (using chmod)
+
=item mkdir_p(DIRNAME)
creates the directory (make parent directories as needed)
@@ -105,16 +113,18 @@ L<MDK::Common>
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(dirname basename cat_ cat__ output output_p append_to_file linkf symlinkf renamef mkdir_p rm_rf cp_af touch all glob_ substInFile expand_symlinks openFileMaybeCompressed catMaybeCompressed);
+@EXPORT_OK = qw(dirname basename cat_ cat__ output output_p output_with_perm append_to_file linkf symlinkf renamef mkdir_p rm_rf cp_af touch all glob_ substInFile expand_symlinks openFileMaybeCompressed catMaybeCompressed);
%EXPORT_TAGS = (all => [ @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__ { 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 @_ }
-sub append_to_file { my $f = shift; local *F; open F, ">>$f" or die "output in file $f failed: $!\n"; print F foreach @_ }
+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_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] }
sub symlinkf { unlink $_[1]; symlink $_[0], $_[1] }
sub renamef { unlink $_[1]; rename $_[0], $_[1] }
diff --git a/perl-MDK-Common.spec b/perl-MDK-Common.spec
index 5cda75e..ee3e00a 100644
--- a/perl-MDK-Common.spec
+++ b/perl-MDK-Common.spec
@@ -2,7 +2,7 @@
# do not change the version here, change in MDK/Common.pm.pl
%define version THEVERSION
-%define release 2mdk
+%define release 3mdk
Summary: Various simple functions
Name: perl-MDK-Common
@@ -50,6 +50,10 @@ rm -rf $RPM_BUILD_ROOT
# MODIFY IN THE CVS: cvs.mandrakesoft.com:/cooker soft/perl-MDK-Common
%changelog
+* Mon Dec 2 2002 Pixel <pixel@mandrakesoft.com> 1.0.4-3mdk
+- add output_with_perm(), cat_or_die()
+- some more checks in perl_checker ($1 =~ /re/ is a warning)
+
* Thu Nov 28 2002 Pixel <pixel@mandrakesoft.com> 1.0.4-2mdk
- new perl_checker now has every feature of the old version
(except checking $_ in small subs, a more global solution should come)