blib/lib/TBX/Min/LangGroup.pm

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