blib/lib/TBX/Min/TermEntry.pm

filter: Statementstmt 29.2% 12 / 41 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 24.6% 20 / 81 CC 11 SCAR 29.0
CC
11
Cov
19%
new
42.0
add_lang_group
12.0
id
6.0
CRAP 18.2
« blib/lib/TBX/Min/LangSet.pm ↑ Summary Build »
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::TermEntry;
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 Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 our $VERSION = '0.07'; # VERSION
14  
15 # ABSTRACT: Store information from one TBX-Min C<termEntry> element
16  
17 1 my %valid = map +($_=>1), qw(id subject_field lang_groups);
18 sub new {
19 0 ▶ my ($class, $args) = @_;
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
20 0 my $self;
21 0 ▶ if((ref $args) eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq 'HASH') { } 0 0 0
22 # validate arguments
23 0 ▶ if(my @invalids = grep !$valid{$_}, sort keys %$args){
Branch: 1 branch
BranchTrueFalseTotal
if (my(@invalids) = grep((!$valid{$_}), sort(keys %$args))) 0 0 0
24 0 croak 'Invalid attributes for class: ' .
25 join ' ', @invalids
26 }
27 0 ▶ if($args->{lang_groups} && ref $args->{lang_groups} ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"lang_groups"} and ref $args->{"lang_groups"} ne "ARRAY") 0 0 0
Condition0%0/3
$args->{"lang_groups"} and ref $args->{"lang_groups"} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"lang_groups"} and ref $args->{"lang_groups"} ne "ARRAY"
$args->{"lang_groups"} ref $args->{"lang_groups"} ne "ARRAY"
Truth table0%0/3
A and B
A= $args->{"lang_groups"}B= ref $args->{"lang_groups"} ne "ARRAY"
ABresult
0X0
100
111
28 0 croak q{Attribute 'lang_groups' should be an array reference};
29 }
30 0 $self = $args;
31 }else{
32 0 $self = {};
33 }
34 0 ▶ $self->{lang_groups} ||= [];
Condition0%0/2
$self->{"lang_groups"} ||= []
l!l
00
MC/DC0%0/1
$self->{"lang_groups"} ||= []
$self->{"lang_groups"}
Truth table0%0/2
A
A= $self->{"lang_groups"}
Aresult
11
00
35 0 return bless $self, $class;
36 }
37  
38 sub id {
39 0 ▶ my ($self, $id) = @_;
Subroutine id: not called CC=2 SCAR=17.9
Pod documented
40 0 ▶ if($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
41 0 return $self->{id} = $id;
42 }
43 0 return $self->{id};
44 }
45  
46 sub subject_field {
47 0 ▶ my ($self, $subject_field) = @_;
Subroutine subject_field: not called CC=2 SCAR=17.9
Pod documented
48 0 ▶ if($subject_field) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subject_field) 0 0 0
49 0 return $self->{subject_field} = $subject_field;
50 }
51 0 return $self->{subject_field};
52 }
53  
54 sub lang_groups { ## no critic(RequireArgUnpacking)
55 0 ▶ my ($self) = @_;
Subroutine lang_groups: not called CC=2 SCAR=17.9
Pod documented
56 0 ▶ if (@_ > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
57 0 croak 'extra argument found (lang_groups is a getter only)';
58 }
59 0 return $self->{lang_groups};
60 }
61  
62 sub add_lang_group {
63 0 ▶ my ($self, $lang_grp) = @_;
Subroutine add_lang_group: not called CC=3 SCAR=24.8
Pod documented
64 0 ▶ if( !$lang_grp || !$lang_grp->isa('TBX::Min::LangSet') ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($lang_grp and $lang_grp->isa("TBX::Min::LangSet")) 0 0 0
Condition0%0/3
$lang_grp and $lang_grp->isa("TBX::Min::LangSet")
!ll&&!rl&&r
000
MC/DC0%0/2
$lang_grp and $lang_grp->isa("TBX::Min::LangSet")
$lang_grp $lang_grp->isa("TBX::Min::LangSet")
Truth table0%0/3
A and B
A= $lang_grpB= $lang_grp->isa("TBX::Min::LangSet")
ABresult
0X0
100
111
65 0 croak 'argument to add_lang_group should be a TBx::Min::LangSet';
66 }
67 0 push @{$self->{lang_groups}}, $lang_grp;
68 0 return;
69 }
70  
71  
72 1 1;
73  
74 __END__
75  
76 =pod
77  
78 =encoding UTF-8
79  
80 =head1 NAME
81  
82 TBX::Min::TermEntry - Store information from one TBX-Min C<termEntry> element
83  
84 =head1 VERSION
85  
86 version 0.07
87  
88 =head1 SYNOPSIS
89  
90 use TBX::Min::TermEntry;
91 use TBX::Min::LangSet;
92 my $concept = TBX::Min::TermEntry->new(
93 {id => 'B001'});
94 print $concept->id(); # 'B001'
95 my $lang_grp = TBX::Min::LangSet->new({code => 'en'});
96 $concept->add_lang_group($lang_grp);
97 my $lang_grps = $concept->lang_groups;
98 print $#$lang_grps; # '1'
99  
100 =head1 DESCRIPTION
101  
102 This class represents a single concept termEntry contained in a TBX-Min file. A
103 concept termEntry contains several language groups, each containing terms that
104 represent this concept in a given languages.
105  
106 =head1 METHODS
107  
108 =head2 C<new>
109  
110 Creates a new C<TBX::Min::TermEntry> instance. Optionally you may pass in
111 a hash reference which is used to initialize the object. The allowed hash
112 fields are C<id>, C<subject_field> and C<lang_groups>, where C<id> and
113 C<subject_field> correspond to methods of the same name, and C<langSets> is
114 an array reference containing C<TBX::Min::LangSet> objects.
115  
116 =head2 C<id>
117  
118 Get or set the concept termEntry id value.
119  
120 =head2 C<subject_field>
121  
122 Get or set the concept subject field string.
123  
124 =head2 C<lang_groups>
125  
126 Returns an array ref containing all of the C<TBX::Min::LangSet> objects
127 in this concept termEntry. The array ref is the same one used to store the objects
128 internally, so additions or removals from the array will be reflected in future
129 calls to this method.
130  
131 =head2 C<add_lang_group>
132  
133 Adds the input C<TBX::Min::LangSet> object to the list of language groups
134 contained by this object.
135  
136 =head1 SEE ALSO
137  
138 L<TBX::Min>
139  
140 =head1 AUTHOR
141  
142 James Hayes <james.s.hayes@gmail.com>
143  
144 =head1 COPYRIGHT AND LICENSE
145  
146 This software is copyright (c) 2016 by Alan Melby.
147  
148 This is free software; you can redistribute it and/or modify it under
149 the same terms as the Perl 5 programming language system itself.
150  
151 =cut
« blib/lib/TBX/Min/LangSet.pm ↑ Summary Build »