blib/lib/TBX/Min/Entry.pm

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