r55638 - in /trunk/dh-make-perl/lib: Debian/Rules.pm DhMakePerl/Command/Packaging.pm

dmn at users.alioth.debian.org dmn at users.alioth.debian.org
Wed Apr 7 20:13:08 UTC 2010


Author: dmn
Date: Wed Apr  7 20:12:59 2010
New Revision: 55638

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=55638
Log:
drop Tie::File from Rules

expliciit writing and no more empty file creation on new

Modified:
    trunk/dh-make-perl/lib/Debian/Rules.pm
    trunk/dh-make-perl/lib/DhMakePerl/Command/Packaging.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=55638&op=diff
==============================================================================
--- trunk/dh-make-perl/lib/Debian/Rules.pm (original)
+++ trunk/dh-make-perl/lib/Debian/Rules.pm Wed Apr  7 20:12:59 2010
@@ -18,6 +18,8 @@
 
     $r->add_quilt;
     $r->drop_quilt;
+
+    $r->write;  # or undef($r);
 
 
 =head1 DESCRIPTION
@@ -27,12 +29,17 @@
 provides facilities to check this, as well as adding/removing quilt
 integration.
 
+Modified contents are written to file either vie the L</write> method, or when
+the object reference goes out of scope (via DESTROY).
+
 =head1 CONSTRUCTOR
 
 C<new> is the standard L<Class::Accessor> constructor, with the exception that
 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.
+
 =head1 FIELDS
 
 =over
@@ -43,14 +50,13 @@
 
 =item lines
 
-Reference to a tied (via <Tie::File>) array pointing to the rules file. Initialized by L</new>.
+Reference to an array pointing to the rules file. Initialized by L</new>.
 
 =back
 
 =cut
 
 use base 'Class::Accessor';
-use Tie::File;
 
 __PACKAGE__->mk_accessors(
     qw(filename lines _is_dh7tiny _is_quiltified _parsed));
@@ -68,10 +74,9 @@
 
     $self->filename or die "'filename' is mandatory";
 
-    my @lines;
-    tie @lines, Tie::File, $self->filename;
-
-    $self->lines( \@lines );
+    $self->lines( [] );
+
+    $self->read;
 
     return $self;
 }
@@ -203,7 +208,7 @@
 =item drop_quilt
 
 Removes L<quilt(1)> integration. Both debhelper 7 I<tiny> style (C<dh
---with=quilt>) and traditional (C<< $(QUILT_STAMPFN >> and C<unpatch>)
+--with=quilt>) and traditional (C<< $(QUILT_STAMPFN) >> and C<unpatch>)
 approaches are detected and removed.
 
 =cut
@@ -295,24 +300,61 @@
     }
 }
 
-=item copy_from I<filename>
-
-Replaces the current rules content with the content of I<filename>.
-
-=cut
-
-sub copy_from {
-    my ( $self, $filename ) = @_;
+=item read [I<filename>]
+
+Replaces the current rules content with the content of I<filename>. If I<filename> is not given, uses the value of the L</filename> member.
+
+=cut
+
+sub read {
+    my $self = shift;
+    my $filename = shift // $self->filename;
+
+    @{ $self->lines } = ();
+    $self->_parsed(0);
+
+    return unless -e $filename;
 
     my $fh;
     open( $fh, '<', $filename ) or die "open($filename): $!";
-    @{ $self->lines } = ();
     while( defined( $_ = <$fh> ) ) {
         push @{ $self->lines }, $_;
     }
-    $self->_parsed(0);
-
-    ( tied @{ $self->lines } )->flush;
+    close $fh;
+}
+
+=item write [I<filename>]
+
+Writes the in-memory contents I<filename>. If not given, uses the value of the
+L</filename> member.
+
+If L</lines> points to an empty array, the file is removed.
+
+=cut
+
+sub write {
+    my $self = shift;
+    my $filename = shift // $self->filename;
+
+    if ( @{ $self->lines } ) {
+        open my $fh, '>', $filename
+            or die "Error opening '$filename': $!";
+
+        print $fh $_ for @{ $self->lines };
+
+        close $fh;
+    }
+    else {
+        unlink $filename or die "unlink($filename): $!";
+    }
+}
+
+sub DESTROY {
+    my $self = shift;
+
+    $self->write;
+
+    $self->SUPER::DESTROY;
 }
 
 =back

Modified: trunk/dh-make-perl/lib/DhMakePerl/Command/Packaging.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/dh-make-perl/lib/DhMakePerl/Command/Packaging.pm?rev=55638&op=diff
==============================================================================
--- trunk/dh-make-perl/lib/DhMakePerl/Command/Packaging.pm (original)
+++ trunk/dh-make-perl/lib/DhMakePerl/Command/Packaging.pm Wed Apr  7 20:12:59 2010
@@ -665,12 +665,7 @@
         return;
     }
 
-    # first close the currently open filehandle
-    $self->rules(undef);
-
     $self->backup_file($file);
-
-    $self->rules( Debian::Rules->new($file) );
 
     my $rulesname = 'rules.dh7.tiny';
 
@@ -680,10 +675,11 @@
     ) {
         if ( -e $source ) {
             print "Using rules: $source\n" if $self->cfg->verbose;
-            $self->rules->copy_from($source);
+            $self->rules->read($source);
             last;
         };
     }
+    $self->rules->write;
     chmod( 0755, $file ) or die "chmod($file): $!";
 }
 




More information about the Pkg-perl-cvs-commits mailing list