Dpkg::Substvars - handle variable substitution in strings
| Use Case | Command | Description |
|---|---|---|
| Create new substvars object | $s = Dpkg::Substvars->new($file) | Create object with default substitutions, load from file |
| Set a substitution | $s->set($key, $value) | Add or replace a substitution variable |
| Get a substitution value | $s->get($key) | Retrieve the value of a given substitution |
| Substitute variables in string | $s->substvars($string) | Replace ${...} variables in string with their values |
| Save all substitutions to file | $s->save($file) | Write all non-automatic substvars to a file |
It provides a class which is able to substitute variables in strings.
$s = Dpkg::Substvars->new($file) — Create a new object that can do substitutions. By default it contains generic substitutions like ${Newline}, ${Space}, ${Tab}, ${dpkg:Version} and ${dpkg:Upstream-Version}. Additional substitutions will be read from the $file passed as parameter. It keeps track of which substitutions were actually used (only counting substvars(), not get()), and warns about unused substvars when asked to. The substitutions that are always present are not included in these warnings.$s->set($key, $value) — Add/replace a substitution.$s->set_as_used($key, $value) — Add/replace a substitution and mark it as used (no warnings will be produced even if unused).$s->set_as_auto($key, $value) — Add/replace a substitution and mark it as used and automatic (no warnings will be produced even if unused).$s->get($key) — Get the value of a given substitution.$s->delete($key) — Remove a given substitution.$s->mark_as_used($key) — Prevents warnings about a unused substitution, for example if it is provided by default.$s->parse($fh, $desc) — Add new substitutions read from the filehandle. $desc is used to identify the filehandle in error messages. Returns the number of substitutions that have been parsed with success.$s->load($file) — Add new substitutions read from $file.$s->set_version_substvars($sourceversion, $binaryversion) — Defines ${binary:Version}, ${source:Version} and ${source:Upstream-Version} based on the given version strings. These will never be warned about when unused.$s->set_arch_substvars() — Defines architecture variables: ${Arch}. This will never be warned about when unused.$s->set_vendor_substvars() — Defines vendor variables: ${vendor:Name} and ${vendor:Id}. These will never be warned about when unused.$s->set_desc_substvars() — Defines source description variables: ${source:Synopsis} and ${source:Extended-Description}. These will never be warned about when unused.$s->set_field_substvars($ctrl, $prefix) — Defines field variables from a Dpkg::Control object, with each variable having the form "${$prefix:$field}". They will never be warned about when unused.$newstring = $s->substvars($string) — Substitutes variables in $string and return the result in $newstring.$s->warn_about_unused() — Issues warning about any variables that were set, but not used.$s->set_msg_prefix($prefix) — Define a prefix displayed before all warnings/error messages output by the module.$s->filter(remove => $rmfunc) or $s->filter(keep => $keepfun) — Filter the substitution variables, either removing or keeping all those that return true when $rmfunc->($key) or $keepfunc->($key) is called."$s" — Return a string representation of all substitutions variables except the automatic ones.$str = $s->output([$fh]) — Return all substitutions variables except the automatic ones. If $fh is passed print them into the filehandle.$s->save($file) — Store all substitutions variables except the automatic ones in the indicated file.$s->no_warn().$s->set_vendor_substvars().$s->set_desc_substvars().$s->parse() now returns the number of parsed substvars.$s->set_field_substvars().$s->filter().$s->set_as_auto().$s->set_version_substvars(), passing a single argument is still supported.$s->mark_as_used().$s->no_warn(), use $s->mark_as_used() instead.$s->set_as_used().1.21.1 2025-09-09 Dpkg::Substvars(3perl)
Generated by phpman v4.9.29 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-22 04:20 @2600:1f28:365:80b0:8802:8bb4:3873:328e
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format