FieldsCore.pm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package Dpkg::Control::FieldsCore;
  16. use strict;
  17. use warnings;
  18. our $VERSION = '1.00';
  19. use Exporter qw(import);
  20. use Dpkg::Gettext;
  21. use Dpkg::ErrorHandling;
  22. use Dpkg::Control::Types;
  23. use Dpkg::Checksums;
  24. our @EXPORT = qw(field_capitalize field_is_official field_is_allowed_in
  25. field_transfer_single field_transfer_all
  26. field_list_src_dep field_list_pkg_dep field_get_dep_type
  27. field_get_sep_type
  28. field_ordered_list field_register
  29. field_insert_after field_insert_before
  30. FIELD_SEP_UNKNOWN FIELD_SEP_SPACE FIELD_SEP_COMMA
  31. FIELD_SEP_LINE);
  32. use constant {
  33. ALL_PKG => CTRL_INFO_PKG | CTRL_INDEX_PKG | CTRL_PKG_DEB | CTRL_FILE_STATUS,
  34. ALL_SRC => CTRL_INFO_SRC | CTRL_INDEX_SRC | CTRL_PKG_SRC,
  35. ALL_CHANGES => CTRL_FILE_CHANGES | CTRL_CHANGELOG,
  36. };
  37. use constant {
  38. FIELD_SEP_UNKNOWN => 0,
  39. FIELD_SEP_SPACE => 1,
  40. FIELD_SEP_COMMA => 2,
  41. FIELD_SEP_LINE => 4,
  42. };
  43. # The canonical list of fields
  44. # Note that fields used only in dpkg's available file are not listed
  45. # Deprecated fields of dpkg's status file are also not listed
  46. our %FIELDS = (
  47. 'Architecture' => {
  48. allowed => (ALL_PKG | ALL_SRC | CTRL_FILE_CHANGES) & (~CTRL_INFO_SRC),
  49. separator => FIELD_SEP_SPACE,
  50. },
  51. 'Binary' => {
  52. allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
  53. # XXX: This field values are separated either by space or comma
  54. # depending on the context.
  55. separator => FIELD_SEP_SPACE | FIELD_SEP_COMMA,
  56. },
  57. 'Binary-Only' => {
  58. allowed => ALL_CHANGES,
  59. },
  60. 'Breaks' => {
  61. allowed => ALL_PKG,
  62. separator => FIELD_SEP_COMMA,
  63. dependency => 'union',
  64. dep_order => 7,
  65. },
  66. 'Bugs' => {
  67. allowed => (ALL_PKG | CTRL_INFO_SRC | CTRL_FILE_VENDOR) & (~CTRL_INFO_PKG),
  68. },
  69. 'Build-Conflicts' => {
  70. allowed => ALL_SRC,
  71. separator => FIELD_SEP_COMMA,
  72. dependency => 'union',
  73. dep_order => 4,
  74. },
  75. 'Build-Conflicts-Arch' => {
  76. allowed => ALL_SRC,
  77. separator => FIELD_SEP_COMMA,
  78. dependency => 'union',
  79. dep_order => 5,
  80. },
  81. 'Build-Conflicts-Indep' => {
  82. allowed => ALL_SRC,
  83. separator => FIELD_SEP_COMMA,
  84. dependency => 'union',
  85. dep_order => 6,
  86. },
  87. 'Build-Depends' => {
  88. allowed => ALL_SRC,
  89. separator => FIELD_SEP_COMMA,
  90. dependency => 'normal',
  91. dep_order => 1,
  92. },
  93. 'Build-Depends-Arch' => {
  94. allowed => ALL_SRC,
  95. separator => FIELD_SEP_COMMA,
  96. dependency => 'normal',
  97. dep_order => 2,
  98. },
  99. 'Build-Depends-Indep' => {
  100. allowed => ALL_SRC,
  101. separator => FIELD_SEP_COMMA,
  102. dependency => 'normal',
  103. dep_order => 3,
  104. },
  105. 'Built-Using' => {
  106. allowed => ALL_PKG,
  107. separator => FIELD_SEP_COMMA,
  108. dependency => 'union',
  109. dep_order => 10,
  110. },
  111. 'Changed-By' => {
  112. allowed => CTRL_FILE_CHANGES,
  113. },
  114. 'Changes' => {
  115. allowed => ALL_CHANGES,
  116. },
  117. 'Closes' => {
  118. allowed => ALL_CHANGES,
  119. separator => FIELD_SEP_SPACE,
  120. },
  121. 'Conffiles' => {
  122. allowed => CTRL_FILE_STATUS,
  123. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  124. },
  125. 'Config-Version' => {
  126. allowed => CTRL_FILE_STATUS,
  127. },
  128. 'Conflicts' => {
  129. allowed => ALL_PKG,
  130. separator => FIELD_SEP_COMMA,
  131. dependency => 'union',
  132. dep_order => 6,
  133. },
  134. 'Date' => {
  135. allowed => ALL_CHANGES,
  136. },
  137. 'Depends' => {
  138. allowed => ALL_PKG,
  139. separator => FIELD_SEP_COMMA,
  140. dependency => 'normal',
  141. dep_order => 2,
  142. },
  143. 'Description' => {
  144. allowed => ALL_PKG | CTRL_FILE_CHANGES,
  145. },
  146. 'Directory' => {
  147. allowed => CTRL_INDEX_SRC,
  148. },
  149. 'Distribution' => {
  150. allowed => ALL_CHANGES,
  151. },
  152. 'Enhances' => {
  153. allowed => ALL_PKG,
  154. separator => FIELD_SEP_COMMA,
  155. dependency => 'union',
  156. dep_order => 5,
  157. },
  158. 'Essential' => {
  159. allowed => ALL_PKG,
  160. },
  161. 'Filename' => {
  162. allowed => CTRL_INDEX_PKG,
  163. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  164. },
  165. 'Files' => {
  166. allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
  167. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  168. },
  169. 'Format' => {
  170. allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
  171. },
  172. 'Homepage' => {
  173. allowed => ALL_SRC | ALL_PKG,
  174. },
  175. 'Installed-Size' => {
  176. allowed => ALL_PKG & ~CTRL_INFO_PKG,
  177. },
  178. 'Installer-Menu-Item' => {
  179. allowed => ALL_PKG,
  180. },
  181. 'Kernel-Version' => {
  182. allowed => ALL_PKG,
  183. },
  184. 'Origin' => {
  185. allowed => (ALL_PKG | ALL_SRC) & (~CTRL_INFO_PKG),
  186. },
  187. 'Maintainer' => {
  188. allowed => CTRL_PKG_DEB | ALL_SRC | ALL_CHANGES,
  189. },
  190. 'Multi-Arch' => {
  191. allowed => ALL_PKG,
  192. },
  193. 'Package' => {
  194. allowed => ALL_PKG,
  195. },
  196. 'Package-List' => {
  197. allowed => ALL_SRC & ~CTRL_INFO_SRC,
  198. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  199. },
  200. 'Package-Type' => {
  201. allowed => ALL_PKG,
  202. },
  203. 'Parent' => {
  204. allowed => CTRL_FILE_VENDOR,
  205. },
  206. 'Pre-Depends' => {
  207. allowed => ALL_PKG,
  208. separator => FIELD_SEP_COMMA,
  209. dependency => 'normal',
  210. dep_order => 1,
  211. },
  212. 'Priority' => {
  213. allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG,
  214. },
  215. 'Provides' => {
  216. allowed => ALL_PKG,
  217. separator => FIELD_SEP_COMMA,
  218. dependency => 'union',
  219. dep_order => 9,
  220. },
  221. 'Recommends' => {
  222. allowed => ALL_PKG,
  223. separator => FIELD_SEP_COMMA,
  224. dependency => 'normal',
  225. dep_order => 3,
  226. },
  227. 'Replaces' => {
  228. allowed => ALL_PKG,
  229. separator => FIELD_SEP_COMMA,
  230. dependency => 'union',
  231. dep_order => 8,
  232. },
  233. 'Section' => {
  234. allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG,
  235. },
  236. 'Size' => {
  237. allowed => CTRL_INDEX_PKG,
  238. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  239. },
  240. 'Source' => {
  241. allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES) &
  242. (~(CTRL_INDEX_SRC | CTRL_INFO_PKG)),
  243. },
  244. 'Standards-Version' => {
  245. allowed => ALL_SRC,
  246. },
  247. 'Status' => {
  248. allowed => CTRL_FILE_STATUS,
  249. separator => FIELD_SEP_SPACE,
  250. },
  251. 'Subarchitecture' => {
  252. allowed => ALL_PKG,
  253. },
  254. 'Suggests' => {
  255. allowed => ALL_PKG,
  256. separator => FIELD_SEP_COMMA,
  257. dependency => 'normal',
  258. dep_order => 4,
  259. },
  260. 'Tag' => {
  261. allowed => ALL_PKG,
  262. separator => FIELD_SEP_COMMA,
  263. },
  264. 'Task' => {
  265. allowed => ALL_PKG,
  266. },
  267. 'Triggers-Awaited' => {
  268. allowed => CTRL_FILE_STATUS,
  269. separator => FIELD_SEP_SPACE,
  270. },
  271. 'Triggers-Pending' => {
  272. allowed => CTRL_FILE_STATUS,
  273. separator => FIELD_SEP_SPACE,
  274. },
  275. 'Uploaders' => {
  276. allowed => ALL_SRC,
  277. separator => FIELD_SEP_COMMA,
  278. },
  279. 'Urgency' => {
  280. allowed => ALL_CHANGES,
  281. },
  282. 'Vcs-Browser' => {
  283. allowed => ALL_SRC,
  284. },
  285. 'Vcs-Arch' => {
  286. allowed => ALL_SRC,
  287. },
  288. 'Vcs-Bzr' => {
  289. allowed => ALL_SRC,
  290. },
  291. 'Vcs-Cvs' => {
  292. allowed => ALL_SRC,
  293. },
  294. 'Vcs-Darcs' => {
  295. allowed => ALL_SRC,
  296. },
  297. 'Vcs-Git' => {
  298. allowed => ALL_SRC,
  299. },
  300. 'Vcs-Hg' => {
  301. allowed => ALL_SRC,
  302. },
  303. 'Vcs-Mtn' => {
  304. allowed => ALL_SRC,
  305. },
  306. 'Vcs-Svn' => {
  307. allowed => ALL_SRC,
  308. },
  309. 'Vendor' => {
  310. allowed => CTRL_FILE_VENDOR,
  311. },
  312. 'Vendor-Url' => {
  313. allowed => CTRL_FILE_VENDOR,
  314. },
  315. 'Version' => {
  316. allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES) &
  317. (~(CTRL_INFO_SRC | CTRL_INFO_PKG)),
  318. },
  319. );
  320. my @checksum_fields = map { &field_capitalize("Checksums-$_") } checksums_get_list();
  321. my @sum_fields = map { $_ eq 'md5' ? 'MD5sum' : &field_capitalize($_) }
  322. checksums_get_list();
  323. &field_register($_, CTRL_PKG_SRC | CTRL_FILE_CHANGES) foreach @checksum_fields;
  324. &field_register($_, CTRL_INDEX_PKG,
  325. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE) foreach @sum_fields;
  326. our %FIELD_ORDER = (
  327. CTRL_PKG_DEB() => [
  328. qw(Package Package-Type Source Version Built-Using Kernel-Version
  329. Architecture Subarchitecture Installer-Menu-Item Essential Origin Bugs
  330. Maintainer Installed-Size), &field_list_pkg_dep(),
  331. qw(Section Priority Multi-Arch Homepage Description Tag Task)
  332. ],
  333. CTRL_PKG_SRC() => [
  334. qw(Format Source Binary Architecture Version Origin Maintainer
  335. Uploaders Homepage Standards-Version Vcs-Browser
  336. Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
  337. Vcs-Svn), &field_list_src_dep(), qw(Package-List),
  338. @checksum_fields, qw(Files)
  339. ],
  340. CTRL_FILE_CHANGES() => [
  341. qw(Format Date Source Binary Binary-Only Architecture Version
  342. Distribution Urgency Maintainer Changed-By Description
  343. Closes Changes),
  344. @checksum_fields, qw(Files)
  345. ],
  346. CTRL_CHANGELOG() => [
  347. qw(Source Binary-Only Version Distribution Urgency Maintainer
  348. Date Closes Changes)
  349. ],
  350. CTRL_FILE_STATUS() => [ # Same as fieldinfos in lib/dpkg/parse.c
  351. qw(Package Essential Status Priority Section Installed-Size Origin
  352. Maintainer Bugs Architecture Multi-Arch Source Version Config-Version
  353. Replaces Provides Depends Pre-Depends Recommends Suggests Breaks
  354. Conflicts Enhances Conffiles Description Triggers-Pending
  355. Triggers-Awaited)
  356. ],
  357. );
  358. # Order for CTRL_INDEX_PKG is derived from CTRL_PKG_DEB
  359. $FIELD_ORDER{CTRL_INDEX_PKG()} = [ @{$FIELD_ORDER{CTRL_PKG_DEB()}} ];
  360. &field_insert_before(CTRL_INDEX_PKG, 'Section', 'Filename', 'Size', @sum_fields);
  361. # Order for CTRL_INDEX_SRC is derived from CTRL_PKG_SRC
  362. $FIELD_ORDER{CTRL_INDEX_SRC()} = [ @{$FIELD_ORDER{CTRL_PKG_SRC()}} ];
  363. @{$FIELD_ORDER{CTRL_INDEX_SRC()}} = map { $_ eq 'Source' ? 'Package' : $_ }
  364. @{$FIELD_ORDER{CTRL_PKG_SRC()}};
  365. &field_insert_after(CTRL_INDEX_SRC, 'Version', 'Priority', 'Section');
  366. &field_insert_before(CTRL_INDEX_SRC, 'Checksums-Md5', 'Directory');
  367. =encoding utf8
  368. =head1 NAME
  369. Dpkg::Control::FieldsCore - manage (list of official) control fields
  370. =head1 DESCRIPTION
  371. The modules contains a list of fieldnames with associated meta-data explaining
  372. in which type of control information they are allowed. The types are the
  373. CTRL_* constants exported by Dpkg::Control.
  374. =head1 FUNCTIONS
  375. =over 4
  376. =item my $f = field_capitalize($field_name)
  377. Returns the field name properly capitalized. All characters are lowercase,
  378. except the first of each word (words are separated by a hyphen in field names).
  379. =cut
  380. sub field_capitalize($) {
  381. my $field = lc(shift);
  382. # Some special cases due to history
  383. return 'MD5sum' if $field eq 'md5sum';
  384. return uc($field) if checksums_is_supported($field);
  385. # Generic case
  386. return join '-', map { ucfirst } split /-/, $field;
  387. }
  388. =item field_is_official($fname)
  389. Returns true if the field is official and known.
  390. =cut
  391. sub field_is_official($) {
  392. return exists $FIELDS{field_capitalize($_[0])};
  393. }
  394. =item field_is_allowed_in($fname, @types)
  395. Returns true (1) if the field $fname is allowed in all the types listed in
  396. the list. Note that you can use type sets instead of individual types (ex:
  397. CTRL_FILE_CHANGES | CTRL_CHANGELOG).
  398. field_allowed_in(A|B, C) returns true only if the field is allowed in C
  399. and either A or B.
  400. Undef is returned for non-official fields.
  401. =cut
  402. sub field_is_allowed_in($@) {
  403. my ($field, @types) = @_;
  404. $field = field_capitalize($field);
  405. return unless field_is_official($field);
  406. return 0 if not scalar(@types);
  407. foreach my $type (@types) {
  408. next if $type == CTRL_UNKNOWN; # Always allowed
  409. return 0 unless $FIELDS{$field}{allowed} & $type;
  410. }
  411. return 1;
  412. }
  413. =item field_transfer_single($from, $to, $field)
  414. If appropriate, copy the value of the field named $field taken from the
  415. $from Dpkg::Control object to the $to Dpkg::Control object.
  416. Official fields are copied only if the field is allowed in both types of
  417. objects. Custom fields are treated in a specific manner. When the target
  418. is not among CTRL_PKG_SRC, CTRL_PKG_DEB or CTRL_FILE_CHANGES, then they
  419. are alway copied as is (the X- prefix is kept). Otherwise they are not
  420. copied except if the target object matches the target destination encoded
  421. in the field name. The initial X denoting custom fields can be followed by
  422. one or more letters among "S" (Source: corresponds to CTRL_PKG_SRC), "B"
  423. (Binary: corresponds to CTRL_PKG_DEB) or "C" (Changes: corresponds to
  424. CTRL_FILE_CHANGES).
  425. Returns undef if nothing has been copied or the name of the new field
  426. added to $to otherwise.
  427. =cut
  428. sub field_transfer_single($$;$) {
  429. my ($from, $to, $field) = @_;
  430. $field //= $_;
  431. my ($from_type, $to_type) = ($from->get_type(), $to->get_type());
  432. $field = field_capitalize($field);
  433. if (field_is_allowed_in($field, $from_type, $to_type)) {
  434. $to->{$field} = $from->{$field};
  435. return $field;
  436. } elsif ($field =~ /^X([SBC]*)-/i) {
  437. my $dest = $1;
  438. if (($dest =~ /B/i and $to_type == CTRL_PKG_DEB) or
  439. ($dest =~ /S/i and $to_type == CTRL_PKG_SRC) or
  440. ($dest =~ /C/i and $to_type == CTRL_FILE_CHANGES))
  441. {
  442. my $new = $field;
  443. $new =~ s/^X([SBC]*)-//i;
  444. $to->{$new} = $from->{$field};
  445. return $new;
  446. } elsif ($to_type != CTRL_PKG_DEB and
  447. $to_type != CTRL_PKG_SRC and
  448. $to_type != CTRL_FILE_CHANGES)
  449. {
  450. $to->{$field} = $from->{$field};
  451. return $field;
  452. }
  453. } elsif (not field_is_allowed_in($field, $from_type)) {
  454. warning(_g("unknown information field '%s' in input data in %s"),
  455. $field, $from->get_option('name') || _g('control information'));
  456. }
  457. return;
  458. }
  459. =item field_transfer_all($from, $to)
  460. Transfer all appropriate fields from $from to $to. Calls
  461. field_transfer_single() on all fields available in $from.
  462. Returns the list of fields that have been added to $to.
  463. =cut
  464. sub field_transfer_all($$) {
  465. my ($from, $to) = @_;
  466. my (@res, $res);
  467. foreach my $k (keys %$from) {
  468. $res = field_transfer_single($from, $to, $k);
  469. push @res, $res if $res and defined wantarray;
  470. }
  471. return @res;
  472. }
  473. =item field_ordered_list($type)
  474. Returns an ordered list of fields for a given type of control information.
  475. This list can be used to output the fields in a predictable order.
  476. The list might be empty for types where the order does not matter much.
  477. =cut
  478. sub field_ordered_list($) {
  479. my ($type) = @_;
  480. return @{$FIELD_ORDER{$type}} if exists $FIELD_ORDER{$type};
  481. return ();
  482. }
  483. =item field_list_src_dep()
  484. List of fields that contains dependencies-like information in a source
  485. Debian package.
  486. =cut
  487. sub field_list_src_dep() {
  488. my @list = sort {
  489. $FIELDS{$a}{dep_order} <=> $FIELDS{$b}{dep_order}
  490. } grep {
  491. field_is_allowed_in($_, CTRL_PKG_SRC) and
  492. exists $FIELDS{$_}{dependency}
  493. } keys %FIELDS;
  494. return @list;
  495. }
  496. =item field_list_pkg_dep()
  497. List of fields that contains dependencies-like information in a binary
  498. Debian package. The fields that express real dependencies are sorted from
  499. the stronger to the weaker.
  500. =cut
  501. sub field_list_pkg_dep() {
  502. my @keys = keys %FIELDS;
  503. my @list = sort {
  504. $FIELDS{$a}{dep_order} <=> $FIELDS{$b}{dep_order}
  505. } grep {
  506. field_is_allowed_in($_, CTRL_PKG_DEB) and
  507. exists $FIELDS{$_}{dependency}
  508. } @keys;
  509. return @list;
  510. }
  511. =item field_get_dep_type($field)
  512. Return the type of the dependency expressed by the given field. Can
  513. either be "normal" for a real dependency field (Pre-Depends, Depends, ...)
  514. or "union" for other relation fields sharing the same syntax (Conflicts,
  515. Breaks, ...). Returns undef for fields which are not dependencies.
  516. =cut
  517. sub field_get_dep_type($) {
  518. my $field = field_capitalize($_[0]);
  519. return unless field_is_official($field);
  520. return $FIELDS{$field}{dependency} if exists $FIELDS{$field}{dependency};
  521. return;
  522. }
  523. =item field_get_sep_type($field)
  524. Return the type of the field value separator. Can be one of FIELD_SEP_UNKNOWN,
  525. FIELD_SEP_SPACE, FIELD_SEP_COMMA or FIELD_SEP_LINE.
  526. =cut
  527. sub field_get_sep_type($) {
  528. my $field = field_capitalize($_[0]);
  529. return $FIELDS{$field}{separator} if exists $FIELDS{$field}{separator};
  530. return FIELD_SEP_UNKNOWN;
  531. }
  532. =item field_register($field, $allowed_types, %opts)
  533. Register a new field as being allowed in control information of specified
  534. types. %opts is optional
  535. =cut
  536. sub field_register($$;@) {
  537. my ($field, $types, %opts) = @_;
  538. $field = field_capitalize($field);
  539. $FIELDS{$field} = {
  540. allowed => $types,
  541. %opts
  542. };
  543. }
  544. =item field_insert_after($type, $ref, @fields)
  545. Place field after another one ($ref) in output of control information of
  546. type $type.
  547. =cut
  548. sub field_insert_after($$@) {
  549. my ($type, $field, @fields) = @_;
  550. return 0 if not exists $FIELD_ORDER{$type};
  551. ($field, @fields) = map { field_capitalize($_) } ($field, @fields);
  552. @{$FIELD_ORDER{$type}} = map {
  553. ($_ eq $field) ? ($_, @fields) : $_
  554. } @{$FIELD_ORDER{$type}};
  555. return 1;
  556. }
  557. =item field_insert_before($type, $ref, @fields)
  558. Place field before another one ($ref) in output of control information of
  559. type $type.
  560. =cut
  561. sub field_insert_before($$@) {
  562. my ($type, $field, @fields) = @_;
  563. return 0 if not exists $FIELD_ORDER{$type};
  564. ($field, @fields) = map { field_capitalize($_) } ($field, @fields);
  565. @{$FIELD_ORDER{$type}} = map {
  566. ($_ eq $field) ? (@fields, $_) : $_
  567. } @{$FIELD_ORDER{$type}};
  568. return 1;
  569. }
  570. =back
  571. =head1 AUTHOR
  572. Raphaël Hertzog <hertzog@debian.org>.
  573. =cut
  574. 1;