blib/lib/TBX/Min/NoteGrp.pm

filter: Statementstmt 33.3% 11 / 33 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 26.1% 17 / 65 CC 9 SCAR 30.7
CC
9
Cov
22%
new
42.0
add_note
12.0
notes
6.0
CRAP 21.6
↑ Summary blib/lib/TBX/Min/TIG.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::NoteGrp;
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  
14 1 our $VERSION = '0.07'; # VERSION
15  
16 # ABSTRACT: Store information from one TBX-Min C<noteGrp> element
17  
18 sub new {
19 0 ▶ my ($class, $args) = @_;
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
20  
21 0 my $self;
22 0 ▶ if((ref $args) eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq 'HASH') { } 0 0 0
23 # only 'notes' allowed in input hash
24 0 ▶ if(my @invalids = grep {$_ ne 'notes'} sort keys %$args){
Branch: 1 branch
BranchTrueFalseTotal
if (my(@invalids) = grep({$_ ne "notes";} sort(keys %$args))) 0 0 0
25 0 croak 'Invalid attributes for class: ' .
26 join ' ', @invalids
27 }
28 0 ▶ if($args->{notes} && ref $args->{notes} ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"notes"} and ref $args->{"notes"} ne "ARRAY") 0 0 0
Condition0%0/3
$args->{"notes"} and ref $args->{"notes"} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"notes"} and ref $args->{"notes"} ne "ARRAY"
$args->{"notes"} ref $args->{"notes"} ne "ARRAY"
Truth table0%0/3
A and B
A= $args->{"notes"}B= ref $args->{"notes"} ne "ARRAY"
ABresult
0X0
100
111
29 0 croak q{Attribute 'notes' should be an array reference};
30 }
31 0 $self = $args;
32 }else{
33 0 $self = {};
34 }
35 0 ▶ $self->{notes} ||= [];
Condition0%0/2
$self->{"notes"} ||= []
l!l
00
MC/DC0%0/1
$self->{"notes"} ||= []
$self->{"notes"}
Truth table0%0/2
A
A= $self->{"notes"}
Aresult
11
00
36 0 return bless $self, $class;
37 }
38  
39 sub notes { ## no critic(RequireArgUnpacking)
40 0 ▶ my ($self) = @_;
Subroutine notes: not called CC=2 SCAR=17.9
Pod documented
41 0 ▶ if (@_ > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
42 0 croak 'extra argument found (notes is a getter only)';
43 }
44 0 return $self->{notes};
45 }
46  
47 sub add_note {
48 0 ▶ my ($self, $note) = @_;
Subroutine add_note: not called CC=3 SCAR=24.8
Pod documented
49 0 ▶ if( !$note || !$note->isa('TBX::Min::Note') ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($note and $note->isa("TBX::Min::Note")) 0 0 0
Condition0%0/3
$note and $note->isa("TBX::Min::Note")
!ll&&!rl&&r
000
MC/DC0%0/2
$note and $note->isa("TBX::Min::Note")
$note $note->isa("TBX::Min::Note")
Truth table0%0/3
A and B
A= $noteB= $note->isa("TBX::Min::Note")
ABresult
0X0
100
111
50 0 croak 'argument to add_note should be a TBX::Min::Note';
51 }
52 0 push @{$self->{notes}}, $note;
53 0 return;
54 }
55  
56  
57 1 1;
58  
59 __END__
60  
61 =pod
62  
63 =encoding UTF-8
64  
65 =head1 NAME
66  
67 TBX::Min::NoteGrp - Store information from one TBX-Min C<noteGrp> element
68  
69 =head1 VERSION
70  
71 version 0.07
72  
73 =head1 SYNOPSIS
74  
75 use TBX::Min::NoteGrp;
76 use TBX::Min::Note;
77 my $note_grp = TBX::Min::NoteGrp->new(
78 my $note = TBX::Min::Note->new({noteKey => 'grammaticalGender', noteValue => 'male'});
79 $note_grp->add_note($note);
80 my $notes = $note_grp->notes;
81 print $#$notes; # '1'
82  
83 =head1 DESCRIPTION
84  
85 This class represents a single note group contained in a TBX-Min file. A note
86 group contains a single noteValue and and optional noteKey.
87  
88 =head1 METHODS
89  
90 =head2 C<new>
91  
92 Creates a new C<TBX::Min::NoteGrp> instance. Optionally you may pass in a hash
93 reference which is used to initialized the object. The fields of the hash
94 correspond to the names of the accessor methods listed below.
95  
96 =head2 C<notes>
97  
98 Returns an array ref containing all of the C<TBX::Min::NoteGrp> objects
99 in this tig. The array ref is the same one used to store the objects
100 internally, so additions or removals from the array will be reflected in future
101 calls to this method.
102  
103 =head2 C<add_note>
104  
105 Adds the input C<TBX::Min::Note> object to the list of language groups
106 contained by this object.
107  
108 =head1 SEE ALSO
109  
110 L<TBX::Min>
111  
112 =head1 AUTHOR
113  
114 James Hayes <james.s.hayes@gmail.com>
115  
116 =head1 COPYRIGHT AND LICENSE
117  
118 This software is copyright (c) 2016 by Alan Melby.
119  
120 This is free software; you can redistribute it and/or modify it under
121 the same terms as the Perl 5 programming language system itself.
122  
123 =cut
↑ Summary blib/lib/TBX/Min/TIG.pm »