FieldsCore.pm 18 KB

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