Browse Source

scripts: Use //= instead of explicit defined or exists checks

Guillem Jover 12 years ago
parent
commit
543ac69d24

+ 1 - 1
scripts/Dpkg/BuildOptions.pm

@@ -180,7 +180,7 @@ set to the variable is also returned.
 
 sub export {
     my ($self, $var) = @_;
-    $var = $self->{envvar} unless defined $var;
+    $var //= $self->{envvar};
     my $content = $self->output();
     Dpkg::BuildEnv::set($var, $content);
     return $content;

+ 1 - 3
scripts/Dpkg/Changelog/Parse.pm

@@ -95,9 +95,7 @@ sub changelog_parse {
     }
 
     # Set a default filename
-    if (not exists $options{file}) {
-	$options{file} = 'debian/changelog';
-    }
+    $options{file} //= 'debian/changelog';
     my $changelogfile = $options{file};
 
     # Extract the format from the changelog file if possible

+ 2 - 2
scripts/Dpkg/Checksums.pm

@@ -255,7 +255,7 @@ is false.
 
 sub add_from_control {
     my ($self, $control, %opts) = @_;
-    $opts{use_files_for_md5} = 0 unless exists $opts{use_files_for_md5};
+    $opts{use_files_for_md5} //= 0;
     foreach my $alg (checksums_get_list()) {
 	my $key = "Checksums-$alg";
 	$key = 'Files' if ($opts{use_files_for_md5} and $alg eq 'md5');
@@ -364,7 +364,7 @@ $control object.
 
 sub export_to_control {
     my ($self, $control, %opts) = @_;
-    $opts{use_files_for_md5} = 0 unless exists $opts{use_files_for_md5};
+    $opts{use_files_for_md5} //= 0;
     foreach my $alg (checksums_get_list()) {
 	my $key = "Checksums-$alg";
 	$key = 'Files' if ($opts{use_files_for_md5} and $alg eq 'md5');

+ 12 - 14
scripts/Dpkg/Deps.pm

@@ -237,17 +237,16 @@ This should be set whenever working with build-deps.
 sub deps_parse {
     my $dep_line = shift;
     my %options = (@_);
-    $options{use_arch} = 1 if not exists $options{use_arch};
-    $options{reduce_arch} = 0 if not exists $options{reduce_arch};
-    $options{host_arch} = get_host_arch() if not exists $options{host_arch};
-    $options{build_arch} = get_build_arch() if not exists $options{build_arch};
-    $options{use_profiles} = 1 if not exists $options{use_profiles};
-    $options{reduce_profiles} = 0 if not exists $options{reduce_profiles};
-    $options{build_profiles} = [ get_build_profiles() ]
-        if not exists $options{build_profiles};
-    $options{reduce_restrictions} = 0 if not exists $options{reduce_restrictions};
-    $options{union} = 0 if not exists $options{union};
-    $options{build_dep} = 0 if not exists $options{build_dep};
+    $options{use_arch} //= 1;
+    $options{reduce_arch} //= 0;
+    $options{host_arch} //= get_host_arch();
+    $options{build_arch} //= get_build_arch();
+    $options{use_profiles} //= 1;
+    $options{reduce_profiles} //= 0;
+    $options{build_profiles} //= [ get_build_profiles() ];
+    $options{reduce_restrictions} //= 0;
+    $options{union} //= 0;
+    $options{build_dep} //= 0;
 
     if ($options{reduce_restrictions}) {
         $options{reduce_arch} = 1;
@@ -1365,9 +1364,8 @@ field. This might be used in the future for versioned provides.
 
 sub add_provided_package {
     my ($self, $pkg, $rel, $ver, $by) = @_;
-    if (not exists $self->{virtualpkg}{$pkg}) {
-	$self->{virtualpkg}{$pkg} = [];
-    }
+
+    $self->{virtualpkg}{$pkg} //= [];
     push @{$self->{virtualpkg}{$pkg}}, [ $by, $rel, $ver ];
 }
 

+ 3 - 4
scripts/Dpkg/Index.pm

@@ -141,9 +141,8 @@ details).
 
 sub add {
     my ($self, $item, $key) = @_;
-    unless (defined $key) {
-	$key = $self->{get_key_func}($item);
-    }
+
+    $key //= $self->{get_key_func}($item);
     if (not exists $self->{items}{$key}) {
 	push @{$self->{order}}, $key;
     }
@@ -288,7 +287,7 @@ computed with the same function.
 
 sub merge {
     my ($self, $other, %opts) = @_;
-    $opts{keep_keys} = 1 unless exists $opts{keep_keys};
+    $opts{keep_keys} //= 1;
     foreach my $key ($other->get_keys()) {
 	$self->add($other->get_by_key($key), $opts{keep_keys} ? $key : undef);
     }

+ 4 - 5
scripts/Dpkg/Shlibs/Symbol.pm

@@ -194,9 +194,8 @@ sub get_symboltempl {
 
 sub set_symbolname {
     my ($self, $name, $templ, $quoted) = @_;
-    unless (defined $name) {
-	$name = $self->{symbol};
-    }
+
+    $name //= $self->{symbol};
     if (!defined $templ && $name =~ /\s/) {
 	$templ = $name;
     }
@@ -253,8 +252,8 @@ sub get_tag_value {
 # tag sets, versioning info (minver and depid))
 sub equals {
     my ($self, $other, %opts) = @_;
-    $opts{versioning} = 1 unless exists $opts{versioning};
-    $opts{tags} = 1 unless exists $opts{tags};
+    $opts{versioning} //= 1;
+    $opts{tags} //= 1;
 
     return 0 if $self->{symbol} ne $other->{symbol};
 

+ 4 - 6
scripts/Dpkg/Shlibs/SymbolFile.pm

@@ -177,9 +177,7 @@ sub add_symbol {
 
     if ($symbol->is_pattern()) {
 	if (my $alias_type = $symbol->get_alias_type()) {
-	    unless (exists $object->{patterns}{aliases}{$alias_type}) {
-		$object->{patterns}{aliases}{$alias_type} = {};
-	    }
+	    $object->{patterns}{aliases}{$alias_type} //= {};
 	    # Alias hash for matching.
 	    my $aliases = $object->{patterns}{aliases}{$alias_type};
 	    $aliases->{$symbol->get_symbolname()} = $symbol;
@@ -282,9 +280,9 @@ sub merge_object_from_symfile {
 
 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};
+    $opts{template_mode} //= 0;
+    $opts{with_deprecated} //= 1;
+    $opts{with_pattern_matches} //= 0;
     my $res = '';
     foreach my $soname (sort $self->get_sonames()) {
 	my @deps = $self->get_dependencies($soname);

+ 5 - 9
scripts/Dpkg/Source/Package.pm

@@ -261,8 +261,7 @@ sub initialize {
 sub upgrade_object_type {
     my ($self, $update_format) = @_;
     $update_format //= 1;
-    $self->{fields}{'Format'} = '1.0'
-        unless exists $self->{fields}{'Format'};
+    $self->{fields}{'Format'} //= '1.0';
     my $format = $self->{fields}{'Format'};
 
     if ($format =~ /^([\d\.]+)(?:\s+\((.*)\))?$/) {
@@ -345,10 +344,9 @@ sub get_basename {
 
 sub find_original_tarballs {
     my ($self, %opts) = @_;
-    $opts{extension} = compression_get_file_extension_regex()
-        unless exists $opts{extension};
-    $opts{include_main} = 1 unless exists $opts{include_main};
-    $opts{include_supplementary} = 1 unless exists $opts{include_supplementary};
+    $opts{extension} //= compression_get_file_extension_regex();
+    $opts{include_main} //= 1;
+    $opts{include_supplementary} //= 1;
     my $basename = $self->get_basename();
     my @tar;
     foreach my $dir ('.', $self->{basedir}, $self->{options}{origtardir}) {
@@ -614,9 +612,7 @@ sub write_dsc {
     }
 
     my $filename = $opts{filename};
-    unless (defined $filename) {
-        $filename = $self->get_basename(1) . '.dsc';
-    }
+    $filename //= $self->get_basename(1) . '.dsc';
     open(my $dsc_fh, '>', $filename)
         or syserr(_g('cannot write %s'), $filename);
     $fields->apply_substvars($opts{substvars});

+ 10 - 20
scripts/Dpkg/Source/Package/V2.pm

@@ -52,26 +52,16 @@ our $CURRENT_MINOR_VERSION = '0';
 sub init_options {
     my ($self) = @_;
     $self->SUPER::init_options();
-    $self->{options}{include_removal} = 0
-        unless exists $self->{options}{include_removal};
-    $self->{options}{include_timestamp} = 0
-        unless exists $self->{options}{include_timestamp};
-    $self->{options}{include_binaries} = 0
-        unless exists $self->{options}{include_binaries};
-    $self->{options}{preparation} = 1
-        unless exists $self->{options}{preparation};
-    $self->{options}{skip_patches} = 0
-        unless exists $self->{options}{skip_patches};
-    $self->{options}{unapply_patches} = 'auto'
-        unless exists $self->{options}{unapply_patches};
-    $self->{options}{skip_debianization} = 0
-        unless exists $self->{options}{skip_debianization};
-    $self->{options}{create_empty_orig} = 0
-        unless exists $self->{options}{create_empty_orig};
-    $self->{options}{auto_commit} = 0
-        unless exists $self->{options}{auto_commit};
-    $self->{options}{ignore_bad_version} = 0
-        unless exists $self->{options}{ignore_bad_version};
+    $self->{options}{include_removal} //= 0;
+    $self->{options}{include_timestamp} //= 0;
+    $self->{options}{include_binaries} //= 0;
+    $self->{options}{preparation} //= 1;
+    $self->{options}{skip_patches} //= 0;
+    $self->{options}{unapply_patches} //= 'auto';
+    $self->{options}{skip_debianization} //= 0;
+    $self->{options}{create_empty_orig} //= 0;
+    $self->{options}{auto_commit} //= 0;
+    $self->{options}{ignore_bad_version} //= 0;
 }
 
 sub parse_cmdline_option {

+ 2 - 4
scripts/Dpkg/Source/Package/V3/Quilt.pm

@@ -40,10 +40,8 @@ our $CURRENT_MINOR_VERSION = '0';
 
 sub init_options {
     my ($self) = @_;
-    $self->{options}{single_debian_patch} = 0
-        unless exists $self->{options}{single_debian_patch};
-    $self->{options}{allow_version_of_quilt_db} = []
-        unless exists $self->{options}{allow_version_of_quilt_db};
+    $self->{options}{single_debian_patch} //= 0;
+    $self->{options}{allow_version_of_quilt_db} //= [];
 
     $self->SUPER::init_options();
 }

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

@@ -64,7 +64,7 @@ sub set_header {
 
 sub add_diff_file {
     my ($self, $old, $new, %opts) = @_;
-    $opts{include_timestamp} = 0 unless exists $opts{include_timestamp};
+    $opts{include_timestamp} //= 0;
     my $handle_binary = $opts{handle_binary_func} || sub {
         my ($self, $old, $new, %opts) = @_;
         my $file = $opts{filename};
@@ -262,7 +262,7 @@ sub add_diff_directory {
         # being shuffled when they are regenerated.
         foreach my $diff_file (sort { $a->[0] cmp $b->[0] } @diff_files) {
             my $fn = $diff_file->[0];
-            $patchorder{$fn} = $i++ unless exists $patchorder{$fn};
+            $patchorder{$fn} //= $i++;
         }
         @diff_files = sort { $patchorder{$a->[0]} <=> $patchorder{$b->[0]} }
                       @diff_files;
@@ -548,9 +548,9 @@ sub prepare_apply {
 sub apply {
     my ($self, $destdir, %opts) = @_;
     # Set default values to options
-    $opts{force_timestamp} = 1 unless exists $opts{force_timestamp};
-    $opts{remove_backup} = 1 unless exists $opts{remove_backup};
-    $opts{create_dirs} = 1 unless exists $opts{create_dirs};
+    $opts{force_timestamp} //= 1;
+    $opts{remove_backup} //= 1;
+    $opts{create_dirs} //= 1;
     $opts{options} ||= [ '-t', '-F', '0', '-N', '-p1', '-u',
             '-V', 'never', '-g0', '-b', '-z', '.dpkg-orig'];
     $opts{add_options} ||= [];
@@ -601,7 +601,7 @@ sub apply {
 sub check_apply {
     my ($self, $destdir, %opts) = @_;
     # Set default values to options
-    $opts{create_dirs} = 1 unless exists $opts{create_dirs};
+    $opts{create_dirs} //= 1;
     $opts{options} ||= [ '--dry-run', '-s', '-t', '-F', '0', '-N', '-p1', '-u',
             '-V', 'never', '-g0', '-b', '-z', '.dpkg-orig'];
     $opts{add_options} ||= [];

+ 3 - 3
scripts/Dpkg/Substvars.pm

@@ -270,8 +270,8 @@ sub substvars {
     my $vn;
     my $rhs = '';
     my $count = 0;
-    $opts{msg_prefix} = $self->{msg_prefix} unless exists $opts{msg_prefix};
-    $opts{no_warn} = 0 unless exists $opts{no_warn};
+    $opts{msg_prefix} //= $self->{msg_prefix};
+    $opts{no_warn} //= 0;
 
     while ($v =~ m/^(.*?)\$\{([-:0-9a-z]+)\}(.*)$/si) {
         # If we have consumed more from the leftover data, then
@@ -309,7 +309,7 @@ Issues warning about any variables that were set, but not used.
 
 sub warn_about_unused {
     my ($self, %opts) = @_;
-    $opts{msg_prefix} = $self->{msg_prefix} unless exists $opts{msg_prefix};
+    $opts{msg_prefix} //= $self->{msg_prefix};
 
     foreach my $vn (keys %{$self->{vars}}) {
         next if $self->{attr}{$vn} & SUBSTVAR_ATTR_USED;

+ 4 - 8
scripts/dpkg-shlibdeps.pl

@@ -244,10 +244,8 @@ foreach my $file (keys %exec) {
             if (defined($symfile_path)) {
                 # Load symbol information
                 print "Using symbols file $symfile_path for $soname\n" if $debug;
-                unless (exists $symfile_cache{$symfile_path}) {
-                    $symfile_cache{$symfile_path} =
-                        Dpkg::Shlibs::SymbolFile->new(file => $symfile_path);
-                }
+                $symfile_cache{$symfile_path} //=
+                   Dpkg::Shlibs::SymbolFile->new(file => $symfile_path);
                 $symfile->merge_object_from_symfile($symfile_cache{$symfile_path}, $soname);
             }
 	    if (defined($symfile_path) && $symfile->has_object($soname)) {
@@ -267,9 +265,7 @@ foreach my $file (keys %exec) {
 	    } else {
 		# No symbol file found, fall back to standard shlibs
                 print "Using shlibs+objdump for $soname (file $lib)\n" if $debug;
-                unless (exists $objdump_cache{$lib}) {
-                    $objdump_cache{$lib} = Dpkg::Shlibs::Objdump::Object->new($lib);
-                }
+                $objdump_cache{$lib} //= Dpkg::Shlibs::Objdump::Object->new($lib);
                 my $libobj = $objdump_cache{$lib};
                 my $id = $dumplibs_wo_symfile->add_object($libobj);
 		if (($id ne $soname) and ($id ne $lib)) {
@@ -308,7 +304,7 @@ foreach my $file (keys %exec) {
     foreach (@sonames) {
         # Initialize statistics
         $soname_used{$_} = 0;
-        $global_soname_used{$_} = 0 unless exists $global_soname_used{$_};
+        $global_soname_used{$_} //= 0;
         if (exists $global_soname_needed{$_}) {
             push @{$global_soname_needed{$_}}, $file;
         } else {