1 # This module is part of debbugs, and
2 # is released under the terms of the GPL version 2, or any later
3 # version (at your option). See the file README and COPYING for more
5 # Copyright 2018 by Don Armstrong <don@donarmstrong.com>.
7 package Debbugs::Bug::Tag;
11 Debbugs::Bug::Tag -- OO interface to bug tags
15 use Debbugs::Bug::Tag;
26 use v5.10; # for state
29 use List::AllUtils qw(uniq);
30 use Debbugs::Config qw(:config);
33 {map {($_,1)} @{$config{tags}}};
36 {%{$config{tags_single_letter}}};
38 extends 'Debbugs::OOBase';
40 around BUILDARGS => sub {
43 if (@_ == 1 && !ref $_[0]) {
44 my @tags = split / /,$_[0];
46 @tags{@tags} = (1) x @tags;
47 return $class->$orig(tags => \%tags);
49 return $class->$orig(@_);
53 has tags => (is => 'ro',
54 isa => 'HashRef[Str]',
58 builder => '_build_tags',
59 handles => {has_tags => 'count'}
61 has usertags => (is => 'ro',
62 isa => 'HashRef[Str]',
64 reader => '_usertags',
65 builder => '_build_usertags',
77 return ($_[0]->tag_is_set($_[1]) or
78 $_[0]->usertag_is_set($_[1]));
82 return exists $_[0]->_tags->{$_[1]} ? 1 : 0;
86 return exists $_[0]->_usertags->{$_[1]} ? 1 : 0;
91 delete $self->_tags->{$_} foreach @_;
96 delete $self->_usertags->{$_} foreach @_;
102 if (not $self->valid_tag($tag)) {
103 confess("Invalid tag $tag");
105 $self->_tags->{$tag} = 1;
111 return exists $valid_tags->{$_[1]}?1:0;
116 return $self->join_all(' ');
123 return join($joiner,$self->all_tags);
127 return uniq sort $_[0]->tags,$_[0]->usertags;
131 return sort keys %{$_[0]->_tags}
137 for my $tag ($self->tags) {
138 next unless exists $short_tags->{$tag};
141 short => $short_tags->{$tag},
152 return sort keys %{$_[0]->_usertags}
161 # indent-tabs-mode: nil
162 # cperl-indent-level: 4