r56118 - /trunk/dh-make-perl/lib/Debian/Rules.pm
dmn at users.alioth.debian.org
dmn at users.alioth.debian.org
Thu Apr 15 08:49:27 UTC 2010
Author: dmn
Date: Thu Apr 15 08:49:14 2010
New Revision: 56118
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=56118
Log:
Rules: allow construction without a file name
Mostly useful for tests, which need a way to feed file's contents without
resorting to an on-disk file.
Modified:
trunk/dh-make-perl/lib/Debian/Rules.pm
Modified: trunk/dh-make-perl/lib/Debian/Rules.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/dh-make-perl/lib/Debian/Rules.pm?rev=56118&op=diff
==============================================================================
--- trunk/dh-make-perl/lib/Debian/Rules.pm (original)
+++ trunk/dh-make-perl/lib/Debian/Rules.pm Thu Apr 15 08:49:14 2010
@@ -38,7 +38,10 @@
if only one, non-reference argument is provided, it is treated as a value for
the L<filename> field.
-The constructor calls L</read> to read the file ccontents into memory.
+If a file name is given, the constructor calls L</read> to read the file
+contents into memory.
+
+One of B<filename> or B<lines> is mandatory.
=head1 FIELDS
@@ -72,11 +75,11 @@
my $self = $class->SUPER::new(@params);
- $self->filename or die "'filename' is mandatory";
-
- $self->lines( [] );
-
- $self->read;
+ $self->filename or $self->lines or die "'filename' or 'lines' is mandatory";
+
+ $self->lines( [] ) unless $self->lines;
+
+ $self->read if $self->filename;
return $self;
}
@@ -310,6 +313,8 @@
my $self = shift;
my $filename = shift // $self->filename;
+ defined($filename) or die "No filename given to read() nor new()";
+
@{ $self->lines } = ();
$self->_parsed(0);
@@ -336,6 +341,8 @@
my $self = shift;
my $filename = shift // $self->filename;
+ defined($filename) or die "No filename given to write() nor new()";
+
if ( @{ $self->lines } ) {
open my $fh, '>', $filename
or die "Error opening '$filename': $!";
@@ -352,7 +359,7 @@
sub DESTROY {
my $self = shift;
- $self->write;
+ $self->write if $self->filename;
$self->SUPER::DESTROY;
}
More information about the Pkg-perl-cvs-commits
mailing list