소스 검색

scripts: Use // instead of || where appropriate

Replace only safe usages, i.e. those that fallback on initialization
values that evaluate to false anyway. Or when the API is explicit about
the variable being undefined.
Guillem Jover 12 년 전
부모
커밋
53ab15cf80

+ 1 - 1
scripts/Dpkg/Arch.pm

@@ -389,7 +389,7 @@ sub debarch_to_cpuattrs($)
     if (defined($cpu)) {
         abitable_load();
 
-        return ($abibits{$abi} || $cpubits{$cpu}, $cpuendian{$cpu});
+        return ($abibits{$abi} // $cpubits{$cpu}, $cpuendian{$cpu});
     } else {
         return;
     }

+ 11 - 11
scripts/Dpkg/Changelog.pm

@@ -362,7 +362,7 @@ sub _data_range {
 
     my ($start, $end);
     if (defined($range->{count})) {
-	my $offset = $range->{offset} || 0;
+	my $offset = $range->{offset} // 0;
 	my $count = $range->{count};
 	# Convert count/offset in start/end
 	if ($offset > 0) {
@@ -416,8 +416,8 @@ sub abort_early {
 
     my $data = $self->{data} or return;
     my $r = $self->{range} or return;
-    my $count = $r->{count} || 0;
-    my $offset = $r->{offset} || 0;
+    my $count = $r->{count} // 0;
+    my $offset = $r->{offset} // 0;
 
     return if $self->_is_full_range($r);
     return if $offset < 0 or $count < 0;
@@ -537,8 +537,8 @@ sub dpkg {
     $f->{Source} = $src->get_source() || 'unknown';
     $f->{Version} = $src->get_version() // 'unknown';
     $f->{Distribution} = join(' ', $src->get_distributions());
-    $f->{Maintainer} = $src->get_maintainer() || '';
-    $f->{Date} = $src->get_timestamp() || '';
+    $f->{Maintainer} = $src->get_maintainer() // '';
+    $f->{Date} = $src->get_timestamp() // '';
     $f->{Changes} = $src->get_dpkg_changes();
 
     # handle optional fields
@@ -554,10 +554,10 @@ sub dpkg {
     }
 
     foreach my $bin (@data) {
-	my $oldurg = $f->{Urgency} || '';
-	my $oldurgn = $URGENCIES{$f->{Urgency}} || -1;
-	my $newurg = $bin->get_urgency() || '';
-	my $newurgn = $URGENCIES{$newurg} || -1;
+	my $oldurg = $f->{Urgency} // '';
+	my $oldurgn = $URGENCIES{$f->{Urgency}} // -1;
+	my $newurg = $bin->get_urgency() // '';
+	my $newurgn = $URGENCIES{$newurg} // -1;
 	$f->{Urgency} = ($newurgn > $oldurgn) ? $newurg : $oldurg;
 	$f->{Changes} .= "\n" . $bin->get_dpkg_changes();
 
@@ -602,8 +602,8 @@ sub rfc822 {
 	$f->{Source} = $entry->get_source() || 'unknown';
 	$f->{Version} = $entry->get_version() // 'unknown';
 	$f->{Distribution} = join(' ', $entry->get_distributions());
-	$f->{Maintainer} = $entry->get_maintainer() || '';
-	$f->{Date} = $entry->get_timestamp() || '';
+	$f->{Maintainer} = $entry->get_maintainer() // '';
+	$f->{Date} = $entry->get_timestamp() // '';
 	$f->{Changes} = $entry->get_dpkg_changes();
 
 	# handle optional fields

+ 1 - 1
scripts/Dpkg/Changelog/Entry.pm

@@ -290,7 +290,7 @@ in the output format of C<dpkg-parsechangelog>.
 
 sub get_dpkg_changes {
     my ($self) = @_;
-    my $header = $self->get_part('header') || '';
+    my $header = $self->get_part('header') // '';
     $header =~ s/\s+$//;
     return "\n$header\n\n" . join("\n", @{$self->get_part('changes')});
 }

+ 1 - 1
scripts/Dpkg/Compression/FileHandle.pm

@@ -419,7 +419,7 @@ sub open_for_read {
 
 sub cleanup {
     my ($self) = @_;
-    my $cmdline = *$self->{compressor}{cmdline} || '';
+    my $cmdline = *$self->{compressor}{cmdline} // '';
     *$self->{compressor}->wait_end_process(nocheck => *$self->{allow_sigpipe});
     if (*$self->{allow_sigpipe}) {
         unless (($? == 0) || (WIFSIGNALED($?) && (WTERMSIG($?) == SIGPIPE))) {

+ 2 - 2
scripts/Dpkg/Deps.pm

@@ -523,7 +523,7 @@ sub new {
     $self->reset();
     $self->{host_arch} = $opts{host_arch} || Dpkg::Arch::get_host_arch();
     $self->{build_arch} = $opts{build_arch} || Dpkg::Arch::get_build_arch();
-    $self->{build_dep} = $opts{build_dep} || 0;
+    $self->{build_dep} = $opts{build_dep} // 0;
     $self->parse_string($arg) if defined($arg);
     return $self;
 }
@@ -1348,7 +1348,7 @@ sub add_installed_package {
 	package => $pkg,
 	version => $ver,
 	architecture => $arch,
-	multiarch => $multiarch || 'no',
+	multiarch => $multiarch // 'no',
     };
     $self->{pkg}{"$pkg:$arch"} = $p if defined $arch;
     push @{$self->{pkg}{$pkg}}, $p;

+ 1 - 1
scripts/Dpkg/Package.pm

@@ -27,7 +27,7 @@ use Exporter qw(import);
 our @EXPORT = qw(pkg_name_is_illegal);
 
 sub pkg_name_is_illegal($) {
-    my $name = shift || '';
+    my $name = shift // '';
 
     if ($name eq '') {
         return _g('may not be empty string');

+ 1 - 1
scripts/Dpkg/Shlibs/Objdump.pm

@@ -138,7 +138,7 @@ use Dpkg::ErrorHandling;
 
 sub new {
     my $this = shift;
-    my $file = shift || '';
+    my $file = shift // '';
     my $class = ref($this) || $this;
     my $self = {};
     bless $self, $class;

+ 2 - 2
scripts/Dpkg/Shlibs/Symbol.pm

@@ -328,7 +328,7 @@ sub is_pattern {
 
 # Get pattern type if this symbol is a pattern.
 sub get_pattern_type {
-    return $_[0]->{pattern}{type} || '';
+    return $_[0]->{pattern}{type} // '';
 }
 
 # Get (sub)type of the alias pattern. Returns empty string if current
@@ -410,7 +410,7 @@ sub get_symbolspec {
     if ($template_mode) {
 	if ($self->has_tags()) {
 	    $spec .= sprintf('%s%3$s%s%3$s', $self->get_tagspec(),
-		$self->get_symboltempl(), $self->{symbol_quoted} || '');
+		$self->get_symboltempl(), $self->{symbol_quoted} // '');
 	} else {
 	    $spec .= $self->get_symboltempl();
 	}

+ 2 - 2
scripts/Dpkg/Source/Patch.pm

@@ -65,7 +65,7 @@ sub set_header {
 sub add_diff_file {
     my ($self, $old, $new, %opts) = @_;
     $opts{include_timestamp} //= 0;
-    my $handle_binary = $opts{handle_binary_func} || sub {
+    my $handle_binary = $opts{handle_binary_func} // sub {
         my ($self, $old, $new, %opts) = @_;
         my $file = $opts{filename};
         $self->_fail_with_msg($file, _g('binary file contents changed'));
@@ -148,7 +148,7 @@ sub add_diff_directory {
     # TODO: make this function more configurable
     # - offer to disable some checks
     my $basedir = $opts{basedirname} || basename($new);
-    my $inc_removal = $opts{include_removal} || 0;
+    my $inc_removal = $opts{include_removal} // 0;
     my $diff_ignore;
     if ($opts{diff_ignore_func}) {
         $diff_ignore = $opts{diff_ignore_func};

+ 1 - 1
scripts/Dpkg/Vendor/Ubuntu.pm

@@ -88,7 +88,7 @@ sub run_hook {
         my $fields = shift @params;
 
         # Add Launchpad-Bugs-Fixed field
-        my $bugs = find_launchpad_closes($fields->{'Changes'} || '');
+        my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
         if (scalar(@$bugs)) {
             $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
         }

+ 1 - 1
scripts/dpkg-checkbuilddeps.pl

@@ -89,7 +89,7 @@ my @options_spec = (
 set_build_profiles(split(/,/, $bp_value)) if ($bp_value);
 my @build_profiles = get_build_profiles();
 
-my $controlfile = shift || 'debian/control';
+my $controlfile = shift // 'debian/control';
 
 my $control = Dpkg::Control::Info->new($controlfile);
 my $fields = $control->get_source();

+ 1 - 1
scripts/dpkg-genchanges.pl

@@ -276,7 +276,7 @@ foreach (keys %{$src_fields}) {
 # Scan control info of all binary packages
 foreach my $pkg ($control->get_packages()) {
     my $p = $pkg->{'Package'};
-    my $a = $pkg->{'Architecture'} || '';
+    my $a = $pkg->{'Architecture'} // '';
     my $d = $pkg->{'Description'} || 'no description available';
     $d = $1 if $d =~ /^(.*)\n/;
     my $pkg_type = $pkg->{'Package-Type'} ||