blib/lib/TBX/Min/LangSet.pm

filter: Statementstmt 33.3% 13 / 39 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 42.8% 3 / 7 Podpod 100% 4 / 4 totaltotal 26.6% 20 / 75 CC 10 SCAR 29.8
CC
10
Cov
22%
new
42.0
add_term_group
12.0
code
6.0
CRAP 19.7
« blib/lib/TBX/Min/TIG.pm ↑ Summary blib/lib/TBX/Min/TermEntry.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::LangSet;
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<langSet> element
16  
17 1 my %valid = map {$_ => 1} qw(code term_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({not $valid{$_};} sort(keys %$args))) 0 0 0
24 0 croak 'Invalid attributes for class: ' .
25 join ' ', @invalids
26 }
27 0 ▶ if($args->{term_groups} && ref $args->{term_groups} ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"term_groups"} and ref $args->{"term_groups"} ne "ARRAY") 0 0 0
Condition0%0/3
$args->{"term_groups"} and ref $args->{"term_groups"} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"term_groups"} and ref $args->{"term_groups"} ne "ARRAY"
$args->{"term_groups"} ref $args->{"term_groups"} ne "ARRAY"
Truth table0%0/3
A and B
A= $args->{"term_groups"}B= ref $args->{"term_groups"} ne "ARRAY"
ABresult
0X0
100
111
28 0 croak q{Attribute 'term_groups' should be an array reference};
29 }
30 0 $self = $args;
31 }else{
32 0 $self = {};
33 }
34 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
35 0 return bless $self, $class;
36 }
37  
38 sub code {
39 0 ▶ my ($self, $code) = @_;
Subroutine code: not called CC=2 SCAR=17.9
Pod documented
40 0 ▶ if($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 0 0
41 0 return $self->{code} = $code;
42 }
43 0 return $self->{code};
44 }
45  
46 sub term_groups { ## no critic(RequireArgUnpacking)
47 0 ▶ my ($self) = @_;
Subroutine term_groups: not called CC=2 SCAR=17.9
Pod documented
48 0 ▶ if (@_ > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
49 0 croak 'extra argument found (term_groups is a getter only)';
50 }
51 0 return $self->{term_groups};
52 }
53  
54 sub add_term_group {
55 0 ▶ my ($self, $term_grp) = @_;
Subroutine add_term_group: not called CC=3 SCAR=24.8
Pod documented
56 0 ▶ if( !$term_grp || !$term_grp->isa('TBX::Min::TIG') ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($term_grp and $term_grp->isa("TBX::Min::TIG")) 0 0 0
Condition0%0/3
$term_grp and $term_grp->isa("TBX::Min::TIG")
!ll&&!rl&&r
000
MC/DC0%0/2
$term_grp and $term_grp->isa("TBX::Min::TIG")
$term_grp $term_grp->isa("TBX::Min::TIG")
Truth table0%0/3
A and B
A= $term_grpB= $term_grp->isa("TBX::Min::TIG")
ABresult
0X0
100
111
57 0 croak 'argument to add_term_group should be a TBX::Min::TIG';
58 }
59 0 push @{$self->{term_groups}}, $term_grp;
60 0 return;
61 }
62  
63  
64 1 1;
65  
66 __END__
67  
68 =pod
69  
70 =encoding UTF-8
71  
72 =head1 NAME
73  
74 TBX::Min::LangSet - Store information from one TBX-Min C<langSet> element
75  
76 =head1 VERSION
77  
78 version 0.07
79  
80 =head1 SYNOPSIS
81  
82 use TBX::Min::LangSet;
83 use TBX::Min::TIG;
84 my $lang_grp = TBX::Min::LangSet->new(
85 {code => 'en'});
86 print $lang_grp->lang(); # 'en'
87 my $term_grp = TBX::Min::TIG->new({term => 'perl'});
88 $lang_grp->add_term_group($term_grp);
89 my $term_grps = $lang_grp->term_groups;
90 print $#$term_grps; # '1'
91  
92 =head1 DESCRIPTION
93  
94 This class represents a single language group contained in a TBX-Min file.
95 A language group is contained by a concept termEntry, and contains several term
96 groups each representing a given concept for the same language.
97  
98 =head1 METHODS
99  
100 =head2 C<new>
101  
102 Creates a new C<TBX::Min::LangSet> instance. Optionally you may pass in
103 a hash reference which is used to initialize the object. The allowed hash
104 fields are C<code> and C<term_groups>, where C<code> corresponds to the
105 method of the same name, and C<term_groups> is an array reference containing
106 C<TBX::Min::LangSet> objects.
107  
108 =head2 C<code>
109  
110 Get or set the language group language code (should be ISO 639 and 3166,
111 e.g. C<en-US>, C<de>, etc.).
112  
113 =head2 C<term_groups>
114  
115 Returns an array ref containing all of the C<TBX::Min::TIG> objects
116 in this concept termEntry. 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_term_group>
121  
122 Adds the input C<TBX::Min::TIG> 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 James Hayes <james.s.hayes@gmail.com>
132  
133 =head1 COPYRIGHT AND LICENSE
134  
135 This software is copyright (c) 2016 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/TIG.pm ↑ Summary blib/lib/TBX/Min/TermEntry.pm »