The following commit has been merged in the master branch:
commit 1d70649516259db6bcfc468299c35f3113115fce
Author: Raphaël Hertzog <[email protected]>
Date:   Sat Feb 20 21:53:15 2010 +0100

    Update Dpkg::Shlibs::SymbolFile to use Dpkg::Interface::Storable
    
    In the process dump() is renamed output() and save() is dropped in favor
    of the version provided by Dpkg::Interface::Storable. load() is
    transformed in parse().

diff --git a/scripts/Dpkg/Shlibs/SymbolFile.pm 
b/scripts/Dpkg/Shlibs/SymbolFile.pm
index 5dfb77f..c0c568a 100644
--- a/scripts/Dpkg/Shlibs/SymbolFile.pm
+++ b/scripts/Dpkg/Shlibs/SymbolFile.pm
@@ -25,6 +25,8 @@ use Dpkg::Control::Fields;
 use Dpkg::Shlibs::Symbol;
 use Dpkg::Arch qw(get_host_arch);
 
+use base qw(Dpkg::Interface::Storable);
+
 my %blacklist = (
     '__bss_end__' => 1,                # arm
     '__bss_end' => 1,          # arm
@@ -185,8 +187,8 @@ sub add_symbol {
 }
 
 # Parameter seen is only used for recursive calls
-sub load {
-    my ($self, $file, $seen, $obj_ref, $base_symbol) = @_;
+sub parse {
+    my ($self, $fh, $file, $seen, $obj_ref, $base_symbol) = @_;
 
     sub new_symbol {
         my $base = shift || 'Dpkg::Shlibs::Symbol';
@@ -205,9 +207,7 @@ sub load {
         $$obj_ref = undef;
     }
 
-    open(my $sym_file, "<", $file)
-       || syserr(_g("cannot open %s"), $file);
-    while (defined($_ = <$sym_file>)) {
+    while (defined($_ = <$fh>)) {
        chomp($_);
 
        if (/^(?:\s+|#(?:DEPRECATED|MISSING): ([^#]+)#\s*)(.*)/) {
@@ -255,7 +255,6 @@ sub load {
            warning(_g("Failed to parse a line in %s: %s"), $file, $_);
        }
     }
-    close($sym_file);
     delete $seen->{$file};
 }
 
@@ -270,39 +269,30 @@ sub merge_object_from_symfile {
     }
 }
 
-sub save {
-    my ($self, $file, %opts) = @_;
-    $file = $self->{file} unless defined($file);
-    my $fh;
-    if ($file eq "-") {
-       $fh = \*STDOUT;
-    } else {
-       open($fh, ">", $file)
-           || syserr(_g("cannot write %s"), $file);
-    }
-    $self->dump($fh, %opts);
-    close($fh) if ($file ne "-");
-}
-
-sub dump {
+sub output {
     my ($self, $fh, %opts) = @_;
     $opts{template_mode} = 0 unless exists $opts{template_mode};
     $opts{with_deprecated} = 1 unless exists $opts{with_deprecated};
     $opts{with_pattern_matches} = 0 unless exists $opts{with_pattern_matches};
+    my $res = "";
     foreach my $soname (sort $self->get_sonames()) {
        my @deps = $self->get_dependencies($soname);
        my $dep = shift @deps;
        $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
-       print $fh "$soname $dep\n";
+       print $fh "$soname $dep\n" if defined $fh;
+       $res .= "$soname $dep\n" if defined wantarray;
+
        foreach $dep (@deps) {
            $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
-           print $fh "| $dep\n";
+           print $fh "| $dep\n" if defined $fh;
+           $res .= "| $dep\n" if defined wantarray;
        }
        my $f = $self->{objects}{$soname}{fields};
        foreach my $field (sort keys %{$f}) {
            my $value = $f->{$field};
            $value =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
-           print $fh "* $field: $value\n";
+           print $fh "* $field: $value\n" if defined $fh;
+           $res .= "* $field: $value\n" if defined wantarray;
        }
 
        my @symbols;
@@ -320,17 +310,20 @@ sub dump {
            next if not $opts{template_mode} and
                    not $sym->arch_is_concerned($self->get_arch());
            # Dump symbol specification. Dump symbol tags only in template mode.
-           print $fh $sym->get_symbolspec($opts{template_mode}), "\n";
+           print $fh $sym->get_symbolspec($opts{template_mode}), "\n" if 
defined $fh;
+           $res .= $sym->get_symbolspec($opts{template_mode}) . "\n" if 
defined wantarray;
            # Dump pattern matches as comments (if requested)
            if ($opts{with_pattern_matches} && $sym->is_pattern()) {
                for my $match (sort { $a->get_symboltempl() cmp
                                      $b->get_symboltempl() } 
$sym->get_pattern_matches())
                {
-                   print $fh "#MATCH:", $match->get_symbolspec(0), "\n";
+                   print $fh "#MATCH:", $match->get_symbolspec(0), "\n" if 
defined $fh;
+                   $res .= "#MATCH:" . $match->get_symbolspec(0) . "\n" if 
defined wantarray;
                }
            }
        }
     }
+    return $res;
 }
 
 # Tries to match a symbol name and/or version against the patterns defined.
diff --git a/scripts/dpkg-gensymbols.pl b/scripts/dpkg-gensymbols.pl
index e710031..141201f 100755
--- a/scripts/dpkg-gensymbols.pl
+++ b/scripts/dpkg-gensymbols.pl
@@ -225,10 +225,10 @@ $symfile->clear_except(keys %{$od->{objects}});
 # Write out symbols files
 if ($stdout) {
     $output = _g("<standard output>");
-    $symfile->save("-", package => $oppackage,
-                   template_mode => $template_mode,
-                   with_pattern_matches => $verbose_output,
-                   with_deprecated => $verbose_output);
+    $symfile->output(\*STDOUT, package => $oppackage,
+                     template_mode => $template_mode,
+                     with_pattern_matches => $verbose_output,
+                     with_deprecated => $verbose_output);
 } else {
     unless (defined($output)) {
        unless($symfile->is_empty()) {
@@ -279,8 +279,8 @@ unless ($quiet) {
     # Compare template symbols files before and after
     my $before = File::Temp->new(TEMPLATE=>'dpkg-gensymbolsXXXXXX');
     my $after = File::Temp->new(TEMPLATE=>'dpkg-gensymbolsXXXXXX');
-    $ref_symfile->dump($before, package => $oppackage, template_mode => 1);
-    $symfile->dump($after, package => $oppackage, template_mode => 1);
+    $ref_symfile->output($before, package => $oppackage, template_mode => 1);
+    $symfile->output($after, package => $oppackage, template_mode => 1);
     seek($before, 0, 0); seek($after, 0, 0);
     my ($md5_before, $md5_after) = (Digest::MD5->new(), Digest::MD5->new());
     $md5_before->addfile($before);
diff --git a/scripts/t/200_Dpkg_Shlibs.t b/scripts/t/200_Dpkg_Shlibs.t
index d634e74..61312fa 100644
--- a/scripts/t/200_Dpkg_Shlibs.t
+++ b/scripts/t/200_Dpkg_Shlibs.t
@@ -222,7 +222,7 @@ is($sym_file->get_smallest_version('libfake.so.1'), "1.0",
 
 # Check dump output
 my $io = IO::String->new();
-$sym_file->dump($io, package => "libfake1");
+$sym_file->output($io, package => "libfake1");
 is(${$io->string_ref()},
 'libfake.so.1 libfake1 #MINVER#
 | libvirtualfake
@@ -260,7 +260,7 @@ save_load_test($sym_file, 'template save -> load', 
template_mode => 1);
 
 # Dumping in non-template mode (amd64) (test for arch tags)
 $io = IO::String->new();
-$sym_file->dump($io);
+$sym_file->output($io);
 is(${$io->string_ref()},
 'libbasictags.so.1 libbasictags1 #MINVER#
 | libbasictags1 (>= 1.1)
@@ -274,7 +274,7 @@ is(${$io->string_ref()},
 $io = IO::String->new();
 $sym_file = Dpkg::Shlibs::SymbolFile->new(file => 
"$datadir/basictags.symbols", arch => 'i386');
 $sym_file_dup = Dpkg::Shlibs::SymbolFile->new(file => 
"$datadir/basictags.symbols", arch => 'i386');
-$sym_file->dump($io);
+$sym_file->output($io);
 is(${$io->string_ref()},
 'libbasictags.so.1 libbasictags1 #MINVER#
 | libbasictags1 (>= 1.1)

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to