Re: [Module-build-general] file i/o stuff
Status: Beta
Brought to you by:
kwilliams
|
From: Ken W. <ke...@ma...> - 2003-08-30 20:45:59
|
On Saturday, August 30, 2003, at 02:03 AM, Uri Guttman wrote:
>
> i have been looking at Base.pm and how it does various file things. i
> see use of IO::File and also of open. and much code could be factored
> out into subs that write hashes with data::dumper and load them back
> in. i will do a pass over those subs and send in a patch. not sure =
when
> i will get it done but maybe next week.
Lemme apply patch this pre=EBmptively.
-Ken
Index: lib/Module/Build/Base.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v
retrieving revision 1.180
diff -u -r1.180 Base.pm
--- lib/Module/Build/Base.pm 26 Aug 2003 18:33:29 -0000 1.180
+++ lib/Module/Build/Base.pm 30 Aug 2003 20:44:35 -0000
@@ -440,11 +440,8 @@
if (my $file =3D $self->config_file($name)) {
return if -e $file and !keys %{ $ph->{new} }; # Nothing to do
- local $Data::Dumper::Terse =3D 1;
- my $fh =3D IO::File->new("> $file") or die "Can't write to $file:=20=
$!";
@{$ph->{disk}}{ keys %{$ph->{new}} } =3D values %{$ph->{new}}; #=20=
Merge
- print $fh Data::Dumper::Dumper($ph->{disk});
- close $fh;
+ $self->_write_dumper($name, $ph->{disk});
$ph->{new} =3D {};
}
@@ -515,24 +512,24 @@
}
}
+sub _write_dumper {
+ my ($self, $filename, $data) =3D @_;
+
+ my $file =3D $self->config_file($filename);
+ my $fh =3D IO::File->new("> $file") or die "Can't create '$file': =
$!";
+ local $Data::Dumper::Terse =3D 1;
+ print $fh Data::Dumper::Dumper($data);
+}
+
sub write_config {
my ($self) =3D @_;
File::Path::mkpath($self->{properties}{config_dir});
-d $self->{properties}{config_dir} or die "Can't mkdir=20
$self->{properties}{config_dir}: $!";
- local $Data::Dumper::Terse =3D 1;
-
- my $file =3D $self->config_file('build_params');
- my $fh =3D IO::File->new("> $file") or die "Can't create '$file': =
$!";
- print $fh Data::Dumper::Dumper([$self->{args}, $self->{config},=20
$self->{properties}]);
- close $fh;
-
- $file =3D $self->config_file('prereqs');
- open $fh, "> $file" or die "Can't create '$file': $!";
my @items =3D qw(requires build_requires conflicts recommends);
- print $fh Data::Dumper::Dumper( { map { $_, $self->$_() } @items } );
- close $fh;
+ $self->_write_dumper('prereqs', { map { $_, $self->$_() } @items });
+ $self->_write_dumper('build_params', [$self->{args},=20
$self->{config}, $self->{properties}]);
$self->_persistent_hash_write('cleanup');
}
|