diff options
author | Guillem Jover <guillem@debian.org> | 2014-07-27 19:49:58 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-08-09 23:04:37 +0200 |
commit | 543ac69d2470e39f6b95a59b82fee116bc1b90d7 (patch) | |
tree | e4230e479d3d7eba0c3adc300f62ca3dc8bb21b6 /scripts/Dpkg | |
parent | 0efb836c42e264dfe60cc1db9d605ef608be5524 (diff) | |
download | dpkg-543ac69d2470e39f6b95a59b82fee116bc1b90d7.tar.gz |
scripts: Use //= instead of explicit defined or exists checks
Diffstat (limited to 'scripts/Dpkg')
-rw-r--r-- | scripts/Dpkg/BuildOptions.pm | 2 | ||||
-rw-r--r-- | scripts/Dpkg/Changelog/Parse.pm | 4 | ||||
-rw-r--r-- | scripts/Dpkg/Checksums.pm | 4 | ||||
-rw-r--r-- | scripts/Dpkg/Deps.pm | 26 | ||||
-rw-r--r-- | scripts/Dpkg/Index.pm | 7 | ||||
-rw-r--r-- | scripts/Dpkg/Shlibs/Symbol.pm | 9 | ||||
-rw-r--r-- | scripts/Dpkg/Shlibs/SymbolFile.pm | 10 | ||||
-rw-r--r-- | scripts/Dpkg/Source/Package.pm | 14 | ||||
-rw-r--r-- | scripts/Dpkg/Source/Package/V2.pm | 30 | ||||
-rw-r--r-- | scripts/Dpkg/Source/Package/V3/Quilt.pm | 6 | ||||
-rw-r--r-- | scripts/Dpkg/Source/Patch.pm | 12 | ||||
-rw-r--r-- | scripts/Dpkg/Substvars.pm | 6 |
12 files changed, 53 insertions, 77 deletions
diff --git a/scripts/Dpkg/BuildOptions.pm b/scripts/Dpkg/BuildOptions.pm index 90213aab0..a7282e06b 100644 --- a/scripts/Dpkg/BuildOptions.pm +++ b/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; diff --git a/scripts/Dpkg/Changelog/Parse.pm b/scripts/Dpkg/Changelog/Parse.pm index a1190d31d..e51e9cde3 100644 --- a/scripts/Dpkg/Changelog/Parse.pm +++ b/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 diff --git a/scripts/Dpkg/Checksums.pm b/scripts/Dpkg/Checksums.pm index 07a917c82..8cc01a201 100644 --- a/scripts/Dpkg/Checksums.pm +++ b/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'); diff --git a/scripts/Dpkg/Deps.pm b/scripts/Dpkg/Deps.pm index 24cac439f..30ccff523 100644 --- a/scripts/Dpkg/Deps.pm +++ b/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 ]; } diff --git a/scripts/Dpkg/Index.pm b/scripts/Dpkg/Index.pm index da1b4efdb..67f4773f1 100644 --- a/scripts/Dpkg/Index.pm +++ b/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); } diff --git a/scripts/Dpkg/Shlibs/Symbol.pm b/scripts/Dpkg/Shlibs/Symbol.pm index 44dd89b91..98e6cdebe 100644 --- a/scripts/Dpkg/Shlibs/Symbol.pm +++ b/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}; diff --git a/scripts/Dpkg/Shlibs/SymbolFile.pm b/scripts/Dpkg/Shlibs/SymbolFile.pm index a42d1de85..70fd0a4ed 100644 --- a/scripts/Dpkg/Shlibs/SymbolFile.pm +++ b/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); diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index 68d634ad1..6dfef4f20 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/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}); diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm index b7544367b..15ad9d04d 100644 --- a/scripts/Dpkg/Source/Package/V2.pm +++ b/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 { diff --git a/scripts/Dpkg/Source/Package/V3/Quilt.pm b/scripts/Dpkg/Source/Package/V3/Quilt.pm index 138ceb2b0..34bd74ddb 100644 --- a/scripts/Dpkg/Source/Package/V3/Quilt.pm +++ b/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(); } diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm index 859b6fff1..8b5683357 100644 --- a/scripts/Dpkg/Source/Patch.pm +++ b/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} ||= []; diff --git a/scripts/Dpkg/Substvars.pm b/scripts/Dpkg/Substvars.pm index bd158bb66..fe7a640be 100644 --- a/scripts/Dpkg/Substvars.pm +++ b/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; |