blib/lib/TBX/Min/TIG.pm

filter: Statementstmt 32.7% 20 / 61 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 41.6% 5 / 12 Podpod 50.0% 1 / 2 totaltotal 24.0% 26 / 108 CC 14 SCAR 29.8
CC
14
Cov
22%
BUILD
56.0
add_note_group
12.0
part_of_speech
6.0
CRAP 19.7
« blib/lib/TBX/Min/NoteGrp.pm ↑ Summary blib/lib/TBX/Min/LangSet.pm »
1 #
2 # This file is part of TBX-Min
3 #
4 # This software is copyright (c) 2016 by Alan Melby.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package TBX::Min::TIG;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use subs qw(part_of_speech status note_groups);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 use Class::Tiny qw(
14 term
15 part_of_speech
16 customer
17 status
18 note_groups
19 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = '0.07'; # VERSION
23  
24 # ABSTRACT: Store information from one TBX-Min C<tig> element
25  
26  
27  
28 sub part_of_speech {
29 0 ▶ my ($self, $pos) = @_;
Subroutine part_of_speech: not called CC=2 SCAR=17.9
30 0 ▶ if(defined $pos){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 0 0
31 0 _validate_pos($pos);
32 0 $self->{part_of_speech} = $pos;
33 }
34 0 return $self->{part_of_speech};
35 }
36  
37 sub note_groups { ## no critic(RequireArgUnpacking)
38 0 ▶ my ($self) = @_;
Subroutine note_groups: not called CC=2 SCAR=17.9
39 0 ▶ if (@_ > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
40 0 croak 'extra argument found (note_groups is a getter only)';
41 }
42 0 return $self->{note_groups};
43 }
44  
45 sub add_note_group {
46 0 ▶ my ($self, $note_grp) = @_;
Subroutine add_note_group: not called CC=3 SCAR=24.8
Pod documented
47 0 ▶ if( !$note_grp || !$note_grp->isa('TBX::Min::NoteGrp') ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($note_grp and $note_grp->isa("TBX::Min::NoteGrp")) 0 0 0
Condition0%0/3
$note_grp and $note_grp->isa("TBX::Min::NoteGrp")
!ll&&!rl&&r
000
MC/DC0%0/2
$note_grp and $note_grp->isa("TBX::Min::NoteGrp")
$note_grp $note_grp->isa("TBX::Min::NoteGrp")
Truth table0%0/3
A and B
A= $note_grpB= $note_grp->isa("TBX::Min::NoteGrp")
ABresult
0X0
100
111
48 0 croak 'argument to add_term_group should be a TBX::Min::TIG';
49 }
50 0 push @{$self->{note_groups}}, $note_grp;
51 0 return;
52 }
53  
54  
55 sub status {
56 0 ▶ my ($self, $status) = @_;
Subroutine status: not called CC=2 SCAR=17.9
57 0 ▶ if(defined $status){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $status) 0 0 0
58 0 _validate_status($status);
59 0 $self->{status} = $status;
60 }
61 0 return $self->{status};
62 }
63  
64 # above Pod::Coverage makes this not "naked" via Pod::Coverage::TrustPod
65  
66 1 my %valid = map +($_=>1), Class::Tiny->get_all_attributes_for(__PACKAGE__);
67 sub BUILD {
68 0 ▶ my ($self, $args) = @_;
Subroutine BUILD: not called CC=7 SCAR=40.3
Pod undocumented
69  
70 # validate arguments
71 0 ▶ if(my @invalids = grep !$valid{$_}, sort keys %$args){
Branch: 1 branch
BranchTrueFalseTotal
if (my(@invalids) = grep((!$valid{$_}), sort(keys %$args))) 0 0 0
72 0 croak 'Invalid attributes for class: ' .
73 join ' ', @invalids
74 }
75 0 ▶ if($args->{note_groups} && ref $args->{note_groups} ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"note_groups"} and ref $args->{"note_groups"} ne "ARRAY") 0 0 0
Condition0%0/3
$args->{"note_groups"} and ref $args->{"note_groups"} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"note_groups"} and ref $args->{"note_groups"} ne "ARRAY"
$args->{"note_groups"} ref $args->{"note_groups"} ne "ARRAY"
Truth table0%0/3
A and B
A= $args->{"note_groups"}B= ref $args->{"note_groups"} ne "ARRAY"
ABresult
0X0
100
111
76 0 croak q{Attribute 'note_groups' should be an array reference};
77 }
78  
79 0 ▶ if($args->{part_of_speech}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"part_of_speech"}) 0 0 0
80 0 _validate_pos($args->{part_of_speech});
81 }
82 0 ▶ if($args->{status}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"status"}) 0 0 0
83 0 _validate_status($args->{status});
84 }
85 0 ▶ $self->{note_groups} ||= [];
Condition0%0/2
$self->{"note_groups"} ||= []
l!l
00
MC/DC0%0/1
$self->{"note_groups"} ||= []
$self->{"note_groups"}
Truth table0%0/2
A
A= $self->{"note_groups"}
Aresult
11
00
86 0 return;
87 }
88  
89 1 my @allowed_pos = qw(noun properNoun verb adjective adverb other);
90 sub _validate_pos {
91 0 ▶ my ($pos) = @_;
Subroutine _validate_pos: not called CC=2 SCAR=17.9
92 0 ▶ if(!grep{$pos eq $_} @allowed_pos){
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$pos eq $_;} @allowed_pos) 0 0 0
93 0 croak "Illegal part of speech '$pos'";
94 }
95 0 return;
96 }
97  
98 1 my @allowed_status = qw(admitted preferred notRecommended obsolete);
99 sub _validate_status {
100 0 ▶ my ($pos) = @_;
Subroutine _validate_status: not called CC=2 SCAR=17.9
101 0 ▶ if(!grep{$pos eq $_} @allowed_status){
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$pos eq $_;} @allowed_status) 0 0 0
102 0 croak "Illegal status '$pos'";
103 }
104 0 return;
105 }
106  
107 1 1;
108  
109 __END__
110  
111 =pod
112  
113 =encoding UTF-8
114  
115 =head1 NAME
116  
117 TBX::Min::TIG - Store information from one TBX-Min C<tig> element
118  
119 =head1 VERSION
120  
121 version 0.07
122  
123 =head1 SYNOPSIS
124  
125 use TBX::Min::TIG;
126 my $term_grp = TBX::Min::TIG->new(
127 {term => 'bat signal', status => "preferred"});
128 $term_grp->part_of_speech('noun');
129 $term_grp->customer('GCPD');
130 print $term_grp->term; # 'bat signal'
131  
132 =head1 DESCRIPTION
133  
134 This class represents a single term group contained in a TBX-Min file. A term
135 group contains a single term and information pertaining to it, such as part of
136 speech, a note, or the associated customer.
137  
138 =head1 METHODS
139  
140 =head2 C<new>
141  
142 Creates a new C<TBX::Min::TIG> instance. Optionally you may pass in a hash
143 reference which is used to initialized the object. The fields of the hash
144 correspond to the names of the accessor methods listed below.
145  
146 =head2 C<term>
147  
148 Get or set the term text associated with this term group.
149  
150 =head2 C<part_of_speech>
151  
152 Get or set the part of speech associated with this term group.
153  
154 =head2 C<note_groups>
155  
156 Returns an array ref containing all of the C<TBX::Min::NoteGrp> objects
157 in this tig. The array ref is the same one used to store the objects
158 internally, so additions or removals from the array will be reflected in future
159 calls to this method.
160  
161 =head2 C<add_note_group>
162  
163 Adds the input C<TBX::Min::NoteGrp> object to the list of language groups
164 contained by this object.
165  
166 =head2 C<customer>
167  
168 Get or set a customer associated with this term group.
169  
170 =head2 C<status>
171  
172 Get or set a status associated with this term group.
173  
174 =head1 SEE ALSO
175  
176 L<TBX::Min>
177  
178 =for Pod::Coverage BUILD
179  
180 =head1 AUTHOR
181  
182 James Hayes <james.s.hayes@gmail.com>
183  
184 =head1 COPYRIGHT AND LICENSE
185  
186 This software is copyright (c) 2016 by Alan Melby.
187  
188 This is free software; you can redistribute it and/or modify it under
189 the same terms as the Perl 5 programming language system itself.
190  
191 =cut
« blib/lib/TBX/Min/NoteGrp.pm ↑ Summary blib/lib/TBX/Min/LangSet.pm »