File Coverage

blib/lib/Debian/Control/Stanza/Binary.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Debian::Control::Stanza::Binary - binary stanza of Debian source package control file
4              
5             =head1 SYNOPSIS
6              
7             my $bin = Debian::Control::Stanza::Binary->new(\%data);
8             print $bin; # auto-stringification
9             print $bin->Depends; # Debian::Dependencies object
10              
11             =head1 DESCRIPTION
12              
13             Debian::Control::Stanza::Binary can be used for representation and manipulation
14             of C stanza of Debian source package control files in an
15             object-oriented way. Converts itself to a textual representation in string
16             context.
17              
18             =head1 FIELDS
19              
20             The supported fields for binary stanzas are listed below. For more information
21             about each field's meaning, consult the section named C
22             files -- debian/control> of the Debian Policy Manual at
23             L
24              
25             Note that real control fields may contain dashes in their names. These are
26             replaced with underscores.
27              
28             =over
29              
30             =item Package
31              
32             =item Architecture
33              
34             =item Section
35              
36             =item Priority
37              
38             =item Essential
39              
40             =item Depends
41              
42             =item Recommends
43              
44             =item Suggests
45              
46             =item Enhances
47              
48             =item Replaces
49              
50             =item Pre_Depends
51              
52             =item Conflicts
53              
54             =item Breaks
55              
56             =item Provides
57              
58             =item Description
59              
60             =back
61              
62             C, C C, C, C, C,
63             C, and C fields are converted to objects of
64             L class upon construction.
65              
66             Two more accessor methods are provided for easier handling of package's short
67             and long description.
68              
69             =over
70              
71             =item short_description
72              
73             =item long_description
74              
75             =back
76              
77             Setting them transparently modifies I. Note that the value of
78             I is "unmangled", that is without leading spaces, and empty
79             lines are empty. I on the other hand is just as it looks in a
80             regular debian/control file - the long part is indented with a single space and
81             empty lines are replaced with dots.
82              
83             =cut
84              
85             package Debian::Control::Stanza::Binary;
86              
87 1     1   3286154 use strict;
  1         5  
  1         48  
88 1     1   7 use warnings;
  1         3  
  1         85  
89              
90             our $VERSION = '0.96';
91              
92 1     1   9 use base 'Debian::Control::Stanza';
  1         2  
  1         441  
93              
94             use constant fields => qw(
95             Package Architecture Section Priority Essential Depends Recommends Suggests
96             Enhances Replaces Pre_Depends Conflicts Breaks Provides Built_Using Description
97             _short_description _long_description
98             );
99              
100             =head1 CONSTRUCTOR
101              
102             =over
103              
104             =item new
105              
106             =item new( { field => value, ... } )
107              
108             Creates a new L object and optionally
109             initializes it with the supplied data.
110              
111             =back
112              
113             =head1 SEE ALSO
114              
115             Debian::Control::Stanza::Source inherits most of its functionality from
116             L
117              
118             =head1 COPYRIGHT & LICENSE
119              
120             Copyright (C) 2009, 2010 Damyan Ivanov L
121              
122             This program is free software; you can redistribute it and/or modify it under
123             the terms of the GNU General Public License version 2 as published by the Free
124             Software Foundation.
125              
126             This program is distributed in the hope that it will be useful, but WITHOUT ANY
127             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
128             PARTICULAR PURPOSE.
129              
130             =cut
131              
132             sub set {
133             my ( $self, $field, @value ) = @_;
134              
135             my $res = $self->SUPER::set( $field, @value );
136              
137             # re-split description in it was set
138             if ( $field eq 'Description' ) {
139             $self->_split_description;
140             }
141             elsif ( $field eq '_short_description' or $field eq '_long_description' ) {
142             $self->_format_description;
143             }
144              
145             $res;
146             }
147              
148             sub short_description {
149             shift->_short_description(@_);
150             }
151              
152             sub long_description {
153             shift->_long_description(@_);
154             }
155              
156             sub _format_description {
157             my $self = shift;
158              
159             my $short = $self->_short_description;
160             my $long = $self->_long_description;
161              
162             if( defined($long) ) {
163             $long =~ s/\n\n/\n.\n/sg; # add spacing between paragraphs
164             $long =~ s/^/ /mg; # prepend every line with a space
165             }
166              
167             # use SUPER::set to not trigger our implementation, which would cause
168             # endless loop (setting short_description updates Description, which is
169             # then split)
170             $self->SUPER::set( 'Description',
171             join( "\n", map { $_ // () } ( $short, $long ) ) );
172             }
173              
174             sub _split_description {
175             my $self = shift;
176              
177             my ( $short, $long ) = split( /\n/, $self->Description, 2 );
178              
179             $long =~ s/^ //mg;
180             $long =~ s/^ \.$//mg;
181              
182             # use SUPER::set to not trigger our implementation, which would cause
183             # endless loop (setting short_description updates Description, which is
184             # then split)
185             $self->SUPER::set( '_short_description', $short );
186             $self->SUPER::set( '_long_description', $long );
187             }
188              
189             1;