Debian::Control::Stanza::CommaSeparated - comma separated debian/control field abstraction


DhMakePerl documentation Contained in the DhMakePerl distribution.

Index


Code Index:

NAME

Top

Debian::Control::Stanza::CommaSeparated - comma separated debian/control field abstraction

SYNOPSYS

Top

    my $f = Debian::Control::Stanza::CommaSeparated->new(
        'Joe M <joem@there.not>');
    $f->add('"Smith, Agent" <asmith@hasyou.not>, Joe M <joem@there.not>');
    print $f->as_string;
        # 'Joe M <joem@there.not>, "Smith, Agent" <asmith@hasyou.not>'
    print "$f";     # the same
    $f->sort;

DESCRIPTION

Top

Debian::Control::Stanza::CommaSeparated abstracts handling of comma-separated list of values, often found in debian/control file fields like Uploaders. Note that the various dependency fields in debian/control also use comma-separated values, but the Debian::Dependencies class is more suitable for these as it is for example also capable of finding overlapping dependency declarations.

CONSTRUCTOR

Top

new (initial values)

The initial values list is parsed and may contain strings that are in fact comma-separated lists. These are split appropriately using Text::ParseWords' quotewords routine.

METHODS

Top

as_string

Returns text representation of the list. A simple join of the elements by , .

The same function is used for overloading the stringification operation.

add @items

Adds the ginen items to the list. Items that are already present are not added, keeping the list unique.

sort

A handy method for sorting the list.


DhMakePerl documentation Contained in the DhMakePerl distribution.
package Debian::Control::Stanza::CommaSeparated;

use strict;
use warnings;

use Array::Unique;
use Text::ParseWords qw(quotewords);

use overload '""' => \&as_string;

sub new {
    my $self = bless [], shift;

    tie @$self, 'Array::Unique';

    $self->add(@_) if @_;

    $self;
}

sub as_string
{
    return join( ', ', @{ $_[0] } );
}

sub _parse {
    my $self = shift;

    my @output;

    for (@_) {
        my @items = quotewords( qr/\s*,\s*/, 1, $_ );
        push @output, @items;
    }

    return @output;
}

sub add {
    my ( $self, @items ) = @_;

    push @$self, $self->_parse(@items);
}

sub sort {
    my $self = shift;

    @$self = sort @$self;
}


1;